0.1.2 • Published 8 years ago
ensure-validation v0.1.2
ensure-validation
Dead-simple validation library for node.js and the browser
Setup
$ npm install --save ensure-validation
Usage
import { Validator, ValidationError } from 'ensure-validation';
const nick = new Validator('nick', [
{ name: 'required', fn: nick => !!nick && nick.length > 0 },
{ name: 'length', fn: nick => nick.length <= 20 },
{ name: 'spaces', negate: true, match: '\\pZ' },
{ name: 'two-symbols', negate: true, match: '[_.\\-]{2}' },
{ name: 'begin-letter', negate: true, match: '^[^\\pL]' },
{ name: 'end-character', negate: true, match: '[^\\pL\\pN]$' },
{ name: 'invalid-character', negate: true, match: '[^\\pL\\pN.\\-_]' }
]);
await nick.exec(''); // throws ValidationError
await nick.exec('sanlyx'); // returns true