paright

0.1.1 • Public • Published

Install:

npm install --save paright

Example:

var paright = require('paright');

/**
Example function
@param {number} first
@param {object} [second]
*/
function foo(first, second) {
  paright(arguments)
    .hasPattern('number')
    .hasPattern('number', 'object|array')
    .test();
  return true;
}

foo(1);
foo(1, {});
foo(1, []);
// -> true

foo({});
// Throws Error;

Usage:

Call paright function with an array-like parameter which you want to validate.

var params = paright(arrayLike);

This returns an object, call hasPattern method on this object to add pattern and call test method to start validation. It will throw a Runtime Error if arrayLike doesn't match with any patterns.

params
  .hasPattern('string')
  .hasPattern('string', 'number')
  .hasPattern('boolean|number')
  .test();

You can also extract arguments use extract method.

Types:

string
number
boolean
object
function
array
null
nan

Readme

Keywords

none

Package Sidebar

Install

npm i paright

Weekly Downloads

3

Version

0.1.1

License

MIT

Last publish

Collaborators

  • caojs