You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
818 B
33 lines
818 B
|
3 years ago
|
'use strict';
|
||
|
|
|
||
|
|
var KNOWN_TYPES = ['undefined', 'string', 'number', 'object', 'function', 'boolean', 'symbol'];
|
||
|
|
|
||
|
|
module.exports = function defFunc(ajv) {
|
||
|
|
defFunc.definition = {
|
||
|
|
inline: function (it, keyword, schema) {
|
||
|
|
var data = 'data' + (it.dataLevel || '');
|
||
|
|
if (typeof schema == 'string') return 'typeof ' + data + ' == "' + schema + '"';
|
||
|
|
schema = 'validate.schema' + it.schemaPath + '.' + keyword;
|
||
|
|
return schema + '.indexOf(typeof ' + data + ') >= 0';
|
||
|
|
},
|
||
|
|
metaSchema: {
|
||
|
|
anyOf: [
|
||
|
|
{
|
||
|
|
type: 'string',
|
||
|
|
enum: KNOWN_TYPES
|
||
|
|
},
|
||
|
|
{
|
||
|
|
type: 'array',
|
||
|
|
items: {
|
||
|
|
type: 'string',
|
||
|
|
enum: KNOWN_TYPES
|
||
|
|
}
|
||
|
|
}
|
||
|
|
]
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
ajv.addKeyword('typeof', defFunc.definition);
|
||
|
|
return ajv;
|
||
|
|
};
|