Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jacopkane/legitimate
Functional, modular and async validation 👌
https://github.com/jacopkane/legitimate
async ecmascript es2017 javascript validate validation
Last synced: 21 days ago
JSON representation
Functional, modular and async validation 👌
- Host: GitHub
- URL: https://github.com/jacopkane/legitimate
- Owner: JacopKane
- License: apache-2.0
- Created: 2016-12-03T02:52:52.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-09-20T04:00:42.000Z (over 6 years ago)
- Last Synced: 2024-12-16T21:56:11.777Z (23 days ago)
- Topics: async, ecmascript, es2017, javascript, validate, validation
- Language: HTML
- Homepage: https://jacopkane.github.io/legitimate/
- Size: 1.99 MB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# legitimate
[![npm][npm-image]][npm-url]
[![docs][docs-image]][docs-url]
[![build][travis-image]][travis-url]
[![codecov][codecov-image]][codecov-url]
[![dependencies][david-image]][david-url]
[![version][tag-image]][tag-url]Functional, modular and async validation 👌
Works fine on browser and node.js, framework agnostic.
## [Docs](https://jacopkane.github.io/legitimate/docs "Docs")
## [Demo](https://jacopkane.github.io/legitimate/ "Demo")
## Installation
```bash
npm install --save legitimate
```
or
```bash
yarn add legitimate
```## Usage
#### Simply:
```javascript
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:
```javascript
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.
```javascript
var Legitimate = require('legitimate').Legitimate;
var legitimate = new Legitimate();
```## Development
### start demo
```bash
npm start
```
or
```bash
yarn start
```### build
```bash
npm run build
```
or
```bash
yarn build
```### test
```bash
npm test
```
or
```bash
npm test -- --coverage
```
or
```bash
yarn test
```### version & publish
For versioning you can use [npm version command](https://docs.npmjs.com/cli/version) with [semver](http://semver.org/)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```bash
npm version patch -f -m "Backwards-compatible bug fixes";
```
or
```bash
npm version minor -f -m "Backwards-compatible new functionality";
```
or
```bash
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[docs-image]: https://doc.esdoc.org/github.com/JacopKane/legitimate/badge.svg
[docs-url]: https://jacopkane.github.io/legitimate/docs/
[npm-image]: https://img.shields.io/npm/v/legitimate.svg
[npm-url]:https://www.npmjs.org/package/legitimate
[codecov-image]: https://codecov.io/gh/jacopkane/legitimate/branch/master/graph/badge.svg
[codecov-url]: https://codecov.io/gh/jacopkane/legitimate
[travis-url]: https://travis-ci.org/JacopKane/legitimate
[travis-image]: https://travis-ci.org/JacopKane/legitimate.svg?branch=master
[david-url]: https://david-dm.org/jacopkane/legitimate?type=dev
[david-image]: https://david-dm.org/jacopkane/legitimate/dev-status.svg
[tag-image]: https://img.shields.io/github/tag/jacopkane/legitimate.svg
[tag-url]: https://github.com/jacopkane/legitimate/tags