| 587 | } |
| 588 | |
| 589 | addKeyword( |
| 590 | kwdOrDef: string | KeywordDefinition, |
| 591 | def?: KeywordDefinition // deprecated |
| 592 | ): Ajv { |
| 593 | let keyword: string | string[] |
| 594 | if (typeof kwdOrDef == "string") { |
| 595 | keyword = kwdOrDef |
| 596 | if (typeof def == "object") { |
| 597 | this.logger.warn("these parameters are deprecated, see docs for addKeyword") |
| 598 | def.keyword = keyword |
| 599 | } |
| 600 | } else if (typeof kwdOrDef == "object" && def === undefined) { |
| 601 | def = kwdOrDef |
| 602 | keyword = def.keyword |
| 603 | if (Array.isArray(keyword) && !keyword.length) { |
| 604 | throw new Error("addKeywords: keyword must be string or non-empty array") |
| 605 | } |
| 606 | } else { |
| 607 | throw new Error("invalid addKeywords parameters") |
| 608 | } |
| 609 | |
| 610 | checkKeyword.call(this, keyword, def) |
| 611 | if (!def) { |
| 612 | eachItem(keyword, (kwd) => addRule.call(this, kwd)) |
| 613 | return this |
| 614 | } |
| 615 | keywordMetaschema.call(this, def) |
| 616 | const definition: AddedKeywordDefinition = { |
| 617 | ...def, |
| 618 | type: getJSONTypes(def.type), |
| 619 | schemaType: getJSONTypes(def.schemaType), |
| 620 | } |
| 621 | eachItem( |
| 622 | keyword, |
| 623 | definition.type.length === 0 |
| 624 | ? (k) => addRule.call(this, k, definition) |
| 625 | : (k) => definition.type.forEach((t) => addRule.call(this, k, definition, t)) |
| 626 | ) |
| 627 | return this |
| 628 | } |
| 629 | |
| 630 | getKeyword(keyword: string): AddedKeywordDefinition | boolean { |
| 631 | const rule = this.RULES.all[keyword] |