Skip to content

kazzkiq/pale

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status


Pale: A dead-simple schema validator.

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.