odin-default-js-exercises/node_modules/ajv-keywords/keywords/if.js

22 lines
600 B
JavaScript
Raw Normal View History

2017-12-15 18:56:14 +00:00
'use strict';
module.exports = function defFunc(ajv) {
if (!ajv.RULES.keywords.switch) require('./switch')(ajv);
defFunc.definition = {
macro: function (schema, parentSchema) {
if (parentSchema.then === undefined)
throw new Error('keyword "then" is absent');
var cases = [ { 'if': schema, 'then': parentSchema.then } ];
if (parentSchema.else !== undefined)
cases[1] = { 'then': parentSchema.else };
return { switch: cases };
}
};
ajv.addKeyword('if', defFunc.definition);
ajv.addKeyword('then');
ajv.addKeyword('else');
return ajv;
};