diff options
author | isaacs <i@izs.me> | 2020-07-24 22:50:02 +0300 |
---|---|---|
committer | isaacs <i@izs.me> | 2020-07-29 21:55:03 +0300 |
commit | bbe4279120c94791b70d97f235c73d972fd67354 (patch) | |
tree | a098e008fc4b906180a4b5ca03a6203ba7a946d5 /node_modules/ajv/lib/keyword.js | |
parent | 764103ceff2ec2e80f396b5a071660fd7425be15 (diff) |
reset and update all deps
Diffstat (limited to 'node_modules/ajv/lib/keyword.js')
-rw-r--r-- | node_modules/ajv/lib/keyword.js | 135 |
1 files changed, 0 insertions, 135 deletions
diff --git a/node_modules/ajv/lib/keyword.js b/node_modules/ajv/lib/keyword.js deleted file mode 100644 index 5fcfb75fc..000000000 --- a/node_modules/ajv/lib/keyword.js +++ /dev/null @@ -1,135 +0,0 @@ -'use strict'; - -var IDENTIFIER = /^[a-z_$][a-z0-9_$-]*$/i; -var customRuleCode = require('./dotjs/custom'); - -module.exports = { - add: addKeyword, - get: getKeyword, - remove: removeKeyword -}; - -/** - * Define custom keyword - * @this Ajv - * @param {String} keyword custom keyword, should be unique (including different from all standard, custom and macro keywords). - * @param {Object} definition keyword definition object with properties `type` (type(s) which the keyword applies to), `validate` or `compile`. - * @return {Ajv} this for method chaining - */ -function addKeyword(keyword, definition) { - /* jshint validthis: true */ - /* eslint no-shadow: 0 */ - var RULES = this.RULES; - - if (RULES.keywords[keyword]) - throw new Error('Keyword ' + keyword + ' is already defined'); - - if (!IDENTIFIER.test(keyword)) - throw new Error('Keyword ' + keyword + ' is not a valid identifier'); - - if (definition) { - if (definition.macro && definition.valid !== undefined) - throw new Error('"valid" option cannot be used with macro keywords'); - - var dataType = definition.type; - if (Array.isArray(dataType)) { - var i, len = dataType.length; - for (i=0; i<len; i++) checkDataType(dataType[i]); - for (i=0; i<len; i++) _addRule(keyword, dataType[i], definition); - } else { - if (dataType) checkDataType(dataType); - _addRule(keyword, dataType, definition); - } - - var $data = definition.$data === true && this._opts.$data; - if ($data && !definition.validate) - throw new Error('$data support: "validate" function is not defined'); - - var metaSchema = definition.metaSchema; - if (metaSchema) { - if ($data) { - metaSchema = { - anyOf: [ - metaSchema, - { '$ref': 'https://raw.githubusercontent.com/epoberezkin/ajv/master/lib/refs/$data.json#' } - ] - }; - } - definition.validateSchema = this.compile(metaSchema, true); - } - } - - RULES.keywords[keyword] = RULES.all[keyword] = true; - - - function _addRule(keyword, dataType, definition) { - var ruleGroup; - for (var i=0; i<RULES.length; i++) { - var rg = RULES[i]; - if (rg.type == dataType) { - ruleGroup = rg; - break; - } - } - - if (!ruleGroup) { - ruleGroup = { type: dataType, rules: [] }; - RULES.push(ruleGroup); - } - - var rule = { - keyword: keyword, - definition: definition, - custom: true, - code: customRuleCode, - implements: definition.implements - }; - ruleGroup.rules.push(rule); - RULES.custom[keyword] = rule; - } - - - function checkDataType(dataType) { - if (!RULES.types[dataType]) throw new Error('Unknown type ' + dataType); - } - - return this; -} - - -/** - * Get keyword - * @this Ajv - * @param {String} keyword pre-defined or custom keyword. - * @return {Object|Boolean} custom keyword definition, `true` if it is a predefined keyword, `false` otherwise. - */ -function getKeyword(keyword) { - /* jshint validthis: true */ - var rule = this.RULES.custom[keyword]; - return rule ? rule.definition : this.RULES.keywords[keyword] || false; -} - - -/** - * Remove keyword - * @this Ajv - * @param {String} keyword pre-defined or custom keyword. - * @return {Ajv} this for method chaining - */ -function removeKeyword(keyword) { - /* jshint validthis: true */ - var RULES = this.RULES; - delete RULES.keywords[keyword]; - delete RULES.all[keyword]; - delete RULES.custom[keyword]; - for (var i=0; i<RULES.length; i++) { - var rules = RULES[i].rules; - for (var j=0; j<rules.length; j++) { - if (rules[j].keyword == keyword) { - rules.splice(j, 1); - break; - } - } - } - return this; -} |