main
Last change
on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 6 days ago |
F4 Finalna Verzija
|
-
Property mode
set to
100644
|
File size:
799 bytes
|
Rev | Line | |
---|
[79a0317] | 1 | import type Ajv from "ajv"
|
---|
| 2 | import type {Plugin} from "ajv"
|
---|
| 3 | import plugins from "./keywords"
|
---|
| 4 |
|
---|
| 5 | export {AjvKeywordsError} from "./definitions"
|
---|
| 6 |
|
---|
| 7 | const ajvKeywords: Plugin<string | string[]> = (ajv: Ajv, keyword?: string | string[]): Ajv => {
|
---|
| 8 | if (Array.isArray(keyword)) {
|
---|
| 9 | for (const k of keyword) get(k)(ajv)
|
---|
| 10 | return ajv
|
---|
| 11 | }
|
---|
| 12 | if (keyword) {
|
---|
| 13 | get(keyword)(ajv)
|
---|
| 14 | return ajv
|
---|
| 15 | }
|
---|
| 16 | for (keyword in plugins) get(keyword)(ajv)
|
---|
| 17 | return ajv
|
---|
| 18 | }
|
---|
| 19 |
|
---|
| 20 | ajvKeywords.get = get
|
---|
| 21 |
|
---|
| 22 | function get(keyword: string): Plugin<any> {
|
---|
| 23 | const defFunc = plugins[keyword]
|
---|
| 24 | if (!defFunc) throw new Error("Unknown keyword " + keyword)
|
---|
| 25 | return defFunc
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | export default ajvKeywords
|
---|
| 29 | module.exports = ajvKeywords
|
---|
| 30 |
|
---|
| 31 | // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
---|
| 32 | module.exports.default = ajvKeywords
|
---|
Note:
See
TracBrowser
for help on using the repository browser.