Home Reference Source Test Repository

legitimate

npm docs build codecov dependencies version

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

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";