Functional, modular and async validation 👌
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
build
config
public
scripts
src
.editorconfig
.gitignore
.travis.yml
LICENSE
README.md
codecov.yml
esdoc.json
package.json
yarn.lock

README.md

legitimate

npm docs build codecov dependencies version

Functional, modular and async validation 👌

Works fine on browser and node.js, framework agnostic.

Docs

Demo

Installation

npm install --save legitimate

or

yarn add legitimate

Usage

Simply:

import { Legitimate, validators } from 'legitimate';

const legitimate = new Legitimate();

legitimate
  .setRules('propToValidate', validators.notEmpty)
  .update('propToValidate', 'value')
  .validate('propToValidate') //validates single prop
  .then(response => response.map(console.log))
  .catch(response => response.map(console.warn));

Some customization:

import { Legitimate, validators, locales } from 'legitimate';

const legitimate = new Legitimate({
  ...locales,
  TOO_SHORT : (value, min) => `Custom message : ${min}`;
}, {
  password : null
});

const passwordRules = [
  password : [
    validators.isText,
    validators.notEmpty,
    (...params) => validators.min(...params, 8),
    (...params) => validators.max(...params, 16),
    (...params) => validators.minLowerCaseChars(...params, 1),
    (...params) => validators.minUpperCaseChars(...params, 1)
  ]
];

legitimate
  .setRules('username', validations.notEmpty, validations.alphanumeric)
  .setRules('password', ...passwordRules)
  .update('username', 'jacopkane')
  .update('password', 'secretPass')
  .isLegit() //validates all the state at once
  .then(response => response.map(console.log)) //will return results for all the rules
  .catch(response => response.map(console.warn));

ES5 & CommonJS

If you are old-school, it's fine with ES5 as well.

var Legitimate = require('legitimate').Legitimate;
var legitimate = new Legitimate();

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

TODO

  • Implement / experiment observable approach
  • Simplify demo
  • Add more built-in validators maybe by using other proven libraries