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 |
|
32 | module.exports.default = ajvKeywords
|