Launch Week Day 2: Introducing Reports: An Extensible Reporting Framework for Socket Data.Learn More
Socket
Book a DemoSign in
Socket

pale

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pale

A dead-simple, fat-free, schema validator. Edit

latest
Source
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

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.

Keywords

validation

FAQs

Package last updated on 18 Jul 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts