Validator for Alien Creations node apps
$ yarn add @aliencreations/node-validator
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 for a complete list of validation errors.
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
}
- Initial commit
- Tree-shake
- Update jcvd library
- Update prettycats library
- Update README
- Update prettycats library
- Update README