Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aliencreations/node-validator
Validator for Alien Creations node apps.
https://github.com/aliencreations/node-validator
Last synced: 28 days ago
JSON representation
Validator for Alien Creations node apps.
- Host: GitHub
- URL: https://github.com/aliencreations/node-validator
- Owner: AlienCreations
- Created: 2020-11-06T14:32:48.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2024-03-30T16:24:19.000Z (10 months ago)
- Last Synced: 2024-11-06T10:13:44.151Z (3 months ago)
- Language: JavaScript
- Size: 141 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# node-validator
Validator for Alien Creations node apps## Install
```
$ yarn add @aliencreations/node-validator
```## Bundled Dependencies
- [prettycats](https://github.com/seancannon/prettycats)
- [jcvd](https://github.com/seancannon/jcvd)## Usage
`validate` accepts two payloads - one is the schema and one is the payload. If the payload
does not satisfy the schema, the function will throw an error.Please see [node-error](https://github.com/aliencreations/node-error) for
a complete list of validation errors.```js
const {
isArrayOf,
isObjectOf,
isOptional,
isRequired,
label,
prr
} = require('@aliencreations/node-validator');const accountType = label('accountType', isObjectOf({
accountName : isRequired(prr.isStringOfLengthAtMost(30)),
accountNumber : isRequired(prr.isPositiveNumber)
}));const validateUser = label('validateUser', isObjectOf({
firstName : isRequired(prr.isStringOfLengthAtMost(30)),
lastName : isRequired(prr.isStringOfLengthAtMost(30)),
accounts : isOptional(isArrayOf(accountType))
}));// Example
try {
validateUser({
firstName : 'Joe',
lastName : 'Swanson',
accounts : [
{
name : 'My Main Account',
number : 12345
}
]
});
} catch (e) {
// threw because accounts -> [0] -> name is unsupported, should have been accountName
}```
---
## Changelog##### 1.0.0
- Initial commit##### 1.0.1
- Tree-shake
##### 1.0.2
- Update [jcvd](https://github.com/seancannon/jcvd) library##### 1.0.3
- Update [prettycats](https://github.com/seancannon/prettycats) library##### 1.0.4
- Update README##### 1.0.5
- Update [prettycats](https://github.com/seancannon/prettycats) library##### 1.0.6
- Update README