UNPKG

799 BPlain TextView Raw
1import type Ajv from "ajv"
2import type {Plugin} from "ajv"
3import plugins from "./keywords"
4
5export {AjvKeywordsError} from "./definitions"
6
7const 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
20ajvKeywords.get = get
21
22function get(keyword: string): Plugin<any> {
23 const defFunc = plugins[keyword]
24 if (!defFunc) throw new Error("Unknown keyword " + keyword)
25 return defFunc
26}
27
28export default ajvKeywords
29module.exports = ajvKeywords
30
31// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
32module.exports.default = ajvKeywords