jsonschema-is-js
v0.3.0
Published
The jsonschema validator property included is.js functions
Downloads
228
Readme
jsonschema-is-js
The jsonschema validator property included is.js functions for JavaScript.
Install
npm i --save jsonschema-is-js
Usage
var Validator = require('jsonschema').Validator;
var isPlugin = require('jsonschema-is-js');
var v = new Validator();
v.attributes.is = isPlugin();
var schema = {
type: 'object',
properties: {
emails: { type: 'array', is: 'all.email' }, // <- use attribute
text: { type: 'string', is: 'include:some' } // <- method:value, result: is.include(text, 'some')
}
};
var result1 = v.validate({
emails: [ '[email protected]', '[email protected]', 123, 'test' ]
}, schema);
var result2 = v.validate({
emails: [ '[email protected]', '[email protected]', '[email protected]' ],
text: 'some text...'
}, schema);
console.log(result1.errors); // error
console.log(result2.errors); // not error
Or use is.js of override regex:
var is = require('is_js')
is.setRegexp(/quack/, 'url');
v.attributes.is = isPlugin(is);