JSPM

jsonschema-is-js

0.3.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 251
  • Score
    100M100P100Q85879F
  • License MIT

The jsonschema validator property included is.js functions

Package Exports

  • jsonschema-is-js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (jsonschema-is-js) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

jsonschema-is-js Build Status NPM version

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: [ 'a@test.cc', 'b@test.cc', 123, 'test' ]
}, schema);
var result2 = v.validate({
  emails: [ 'a@test.cc', 'b@test.cc', 'test@ggg.gg' ],
  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);

License

MIT