https://github.com/jhen0409/jsonschema-is-js
The jsonschema validator property included is.js functions
https://github.com/jhen0409/jsonschema-is-js
Last synced: 10 days ago
JSON representation
The jsonschema validator property included is.js functions
- Host: GitHub
- URL: https://github.com/jhen0409/jsonschema-is-js
- Owner: jhen0409
- License: mit
- Created: 2015-09-02T09:59:36.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2016-03-30T02:00:42.000Z (over 9 years ago)
- Last Synced: 2025-09-27T17:59:09.060Z (19 days ago)
- Language: JavaScript
- Homepage:
- Size: 12.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# jsonschema-is-js [](https://travis-ci.org/jhen0409/jsonschema-is-js) [](https://www.npmjs.com/package/jsonschema-is-js)
The [jsonschema](https://github.com/tdegrunt/jsonschema) validator property included [is.js](https://github.com/arasatasaygin/is.js) functions for JavaScript.
## Install
```
$ npm i --save jsonschema jsonschema-is-js
```## Usage
```js
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:
```js
var is = require('is_js')
is.setRegexp(/quack/, 'url');
v.attributes.is = isPlugin(is);
```## License
[MIT](LICENSE)