legitimate
Modular async validation 👌
Docs
Demo
Installation
npm install --save legitimate
or
yarn add legitimate
Usage
import { Legitimate, validators } from 'legitimate';
const legitimate = new Legitimate();
legitimate
.addRule('propToValidate', validators.notEmpty)
.update('propToValidate', 'value')
.validate('propToValidate') //validates single prop
.then(response => response.map(console.log))
.catch(response => response.map(console.warn));
more customization:
import { Legitimate, validators, locales } from 'legitimate';
const
legitimate = new Legitimate({
...locales
TOO_SHORT : (value, min) => `Custom message : ${min}`;
}, {
}),
secondPropRules = [
validators.isText,
(...params) => validators.minLowerCaseChars(...params, 2)
];
legitimate
.addRule('propToValidate', validations.notEmpty)
.addRule('anotherProp', ...secondPropRules)
.update('anotherProp', 'aaBBBB')
.isLegit() //validates all state
.then(response => response.map(console.log))
.catch(response => response.map(console.warn));
Development
start demo
npm start
or
yarn start
build
npm run build
or
yarn build
test
npm test
or
npm test -- --coverage
or
yarn test
version & publish
For versioning you can use npm version command with semver
It will also
- test
- build
- generate docs
- stage
- commit
- push the tags to tracked remote repository
- push the demo
- if CI will pass also get deployed to NPM
npm version patch -f -m "Backwards-compatible bug fixes";
or
npm version minor -f -m "Backwards-compatible new functionality";
or
yarn version major -f -m "Made incompatible API changes";