pale
v1.0.2
Published
A dead-simple, fat-free, schema validator. Edit
Downloads
9
Maintainers
Readme
Instalation
You can install Pale via npm:
npm install --save pale
Or use it directly in browser via cdn service:
https://unpkg.com/pale/build/pale.min.js
Usage
import Pale from 'pale';
const check = new Pale({
name: ['string minLength(2)', 'John Doe'],
age: ['number minLength(1) maxLength(3)', '35']
});
check.run()
.then(console.log) // Object with input data
.catch(console.log); // Object showing which validator failed
Adding a new validator
import Pale from 'pale';
const check = new Pale({
acceptedTerms: ['boolean', true]
});
function boolean(value) {
if (['true', 'false', true, false].includes(value)) {
return true;
} else {
return false;
}
}
check.addValidator(boolean);
check.run();
// ...
Get all available validators
import Pale from 'pale';
const check = new Pale({
acceptedTerms: ['boolean', true]
});
Object.keys(check.validators);
// Outputs by default:
// ['string', 'number', 'min', 'max', 'minLength', 'maxLength']
Credits & Thanks
By @Kazzkiq
Pale was made possible by awesome open-source projects such as Rollup.