mirror of
https://github.com/S2-/minifyfromhtml.git
synced 2025-08-03 12:20:04 +02:00
update node modules
This commit is contained in:
81
node_modules/ajv/lib/keyword.js
generated
vendored
81
node_modules/ajv/lib/keyword.js
generated
vendored
@@ -2,11 +2,46 @@
|
||||
|
||||
var IDENTIFIER = /^[a-z_$][a-z0-9_$-]*$/i;
|
||||
var customRuleCode = require('./dotjs/custom');
|
||||
var metaSchema = require('./refs/json-schema-draft-07.json');
|
||||
|
||||
module.exports = {
|
||||
add: addKeyword,
|
||||
get: getKeyword,
|
||||
remove: removeKeyword
|
||||
remove: removeKeyword,
|
||||
validate: validateKeyword
|
||||
};
|
||||
|
||||
var definitionSchema = {
|
||||
definitions: {
|
||||
simpleTypes: metaSchema.definitions.simpleTypes
|
||||
},
|
||||
type: 'object',
|
||||
dependencies: {
|
||||
schema: ['validate'],
|
||||
$data: ['validate'],
|
||||
statements: ['inline'],
|
||||
valid: {not: {required: ['macro']}}
|
||||
},
|
||||
properties: {
|
||||
type: metaSchema.properties.type,
|
||||
schema: {type: 'boolean'},
|
||||
statements: {type: 'boolean'},
|
||||
dependencies: {
|
||||
type: 'array',
|
||||
items: {type: 'string'}
|
||||
},
|
||||
metaSchema: {type: 'object'},
|
||||
modifying: {type: 'boolean'},
|
||||
valid: {type: 'boolean'},
|
||||
$data: {type: 'boolean'},
|
||||
async: {type: 'boolean'},
|
||||
errors: {
|
||||
anyOf: [
|
||||
{type: 'boolean'},
|
||||
{const: 'full'}
|
||||
]
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -20,7 +55,6 @@ 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');
|
||||
|
||||
@@ -28,30 +62,23 @@ function addKeyword(keyword, definition) {
|
||||
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');
|
||||
this.validateKeyword(definition, true);
|
||||
|
||||
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);
|
||||
for (var i=0; i<dataType.length; 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) {
|
||||
if (definition.$data && this._opts.$data) {
|
||||
metaSchema = {
|
||||
anyOf: [
|
||||
metaSchema,
|
||||
{ '$ref': 'https://raw.githubusercontent.com/epoberezkin/ajv/master/lib/refs/$data.json#' }
|
||||
{ '$ref': 'https://raw.githubusercontent.com/epoberezkin/ajv/master/lib/refs/data.json#' }
|
||||
]
|
||||
};
|
||||
}
|
||||
@@ -88,11 +115,6 @@ function addKeyword(keyword, definition) {
|
||||
RULES.custom[keyword] = rule;
|
||||
}
|
||||
|
||||
|
||||
function checkDataType(dataType) {
|
||||
if (!RULES.types[dataType]) throw new Error('Unknown type ' + dataType);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -133,3 +155,24 @@ function removeKeyword(keyword) {
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Validate keyword definition
|
||||
* @this Ajv
|
||||
* @param {Object} definition keyword definition object.
|
||||
* @param {Boolean} throwError true to throw exception if definition is invalid
|
||||
* @return {boolean} validation result
|
||||
*/
|
||||
function validateKeyword(definition, throwError) {
|
||||
validateKeyword.errors = null;
|
||||
var v = this._validateKeyword = this._validateKeyword
|
||||
|| this.compile(definitionSchema, true);
|
||||
|
||||
if (v(definition)) return true;
|
||||
validateKeyword.errors = v.errors;
|
||||
if (throwError)
|
||||
throw new Error('custom keyword definition is invalid: ' + this.errorsText(v.errors));
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
Reference in New Issue
Block a user