@sadbox/walledator
v0.3.1
Published
Asynchronous data validation
Downloads
3
Readme
Walledator
An environment agnostic nano-robot to perform schema validations.
Install
yarn add @sadbox/walledator
or
npm install -S @sadbox/walledator
Usage
import Q from '@sadbox/walledator';
const isFree = email => request('/email-is-free', email);
const schema = Q.shape({
email: Q.email.custom({ key: 'taken', isFree }).required,
password: Q.string.match(regex).size({ min: 8 }).required,
});
// server
schema.validate(request.body);
// client
schema.defineMessages({
'shape.email.email': 'is not an email',
'shape.email.taken': 'is already taken',
'shape.password.match': 'contains invalid symbols',
'shape.password.size': 'does not match the size limitations',
'shape.required': 'is required',
});
schema.validate(form.values, { humanize: true });