https://github.com/nswbmw/validator-it
Just validate it, based on [validator](https://github.com/chriso/validator.js).
https://github.com/nswbmw/validator-it
Last synced: 3 days ago
JSON representation
Just validate it, based on [validator](https://github.com/chriso/validator.js).
- Host: GitHub
- URL: https://github.com/nswbmw/validator-it
- Owner: nswbmw
- Created: 2015-11-12T04:36:18.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2017-10-11T10:52:21.000Z (about 8 years ago)
- Last Synced: 2025-10-14T20:25:07.091Z (18 days ago)
- Language: JavaScript
- Size: 2.93 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## validator-it
Just validate it, based on [validator](https://github.com/chriso/validator.js).
### Install
```
npm i validator-it
```
### Examples
```
var validatorIt = require('validator-it');
var validatePosts = validatorIt({
author: {
_id: validatorIt.isMongoId(),
name: function checkName(name) {
if (['nswbmw', 'jack'].indexOf(name) === -1) {
throw new Error('You are not admin.');
}
},
email: validatorIt.isEmail()
},
content: validatorIt.isByteLength(10)
});
validatePosts({
author: {
_id: '5643263df301e3550988b3c8',
name: 'nswbmw',
email: 'foo@bar.com'
},
content: 'abcdefghijk'
});
// return true
validatePosts({
author: {
_id: 'abc',
name: 'nswbmw',
email: 'foo@bar.com'
}
});
// return false
validatePosts({
author: {
_id: 'abc',
name: 'nswbmw',
email: 'foo@bar.com'
}
}, true);
// throw
// [author._id: abc] ✖ isMongoId
validatePosts({
author: {
_id: '5643263df301e3550988b3c8',
name: 'guest',
email: 'foo@bar.com'
}
});
// throw
// You are not admin.
validatorIt.isEmail()('foo@bar.com') // { key: 'isEmail', value: true }
validatorIt.contains('foo')('foo@bar.com') // { key: 'contains(foo)', value: true }
validatorIt.validator.isEmail('foo@bar.com') // true
validatorIt.validator.contains('foo@bar.com', 'foo') // true
```
More examples see [test](./test.js).
### License
MIT