Pale: A dead-simple schema validator.
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
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
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();
// ...
import Pale from 'pale';
const check = new Pale({
acceptedTerms: ['boolean', true]
});
Object.keys(check.validators);
// Outputs by default:
// ['string', 'number', 'min', 'max', 'minLength', 'maxLength']
By @Kazzkiq
Pale was made possible by awesome open-source projects such as Rollup.