mirror of https://github.com/lukechilds/node.git
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
694 B
33 lines
694 B
'use strict';
|
|
|
|
var KEYWORDS = require('./keywords');
|
|
|
|
module.exports = defineKeywords;
|
|
|
|
|
|
/**
|
|
* Defines one or several keywords in ajv instance
|
|
* @param {Ajv} ajv validator instance
|
|
* @param {String|Array<String>|undefined} keyword keyword(s) to define
|
|
*/
|
|
function defineKeywords(ajv, keyword) {
|
|
if (Array.isArray(keyword)) {
|
|
for (var i=0; i<keyword.length; i++)
|
|
get(keyword[i])(ajv);
|
|
return;
|
|
}
|
|
if (keyword) {
|
|
get(keyword)(ajv);
|
|
return;
|
|
}
|
|
for (keyword in KEYWORDS) get(keyword)(ajv);
|
|
}
|
|
|
|
|
|
defineKeywords.get = get;
|
|
|
|
function get(keyword) {
|
|
var defFunc = KEYWORDS[keyword];
|
|
if (!defFunc) throw new Error('Unknown keyword ' + keyword);
|
|
return defFunc;
|
|
}
|
|
|