Skip to content

SachaCR/chknum

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

chknum

Check numeric params in Javascript.

See documentation here

Make it easy to read :

  • chknum(x)isInt().greaterThan(5).lesserThan(10);
  • chknum(x).gt(5).lt(10);

more compact and readable than :

if (x > 5 && x < 10) {

} else {
  throw new RangeError();
}

Example :

var chknum require ('chknum');

function (x, y, z) {

  // This will check if the number is an integer.
  chknum(x).isInt();

  // This will check if the number is a float.
  chknum(x).isFloat();

  // This will throw a RangeError if x does'nt match.
  chknum(x).greaterThan(5).lesserThan(10);

  // Also work like this :
  chknum(x).gt(5).lt(10);

  chknum(y).negative(); // Or chknum(y).neg();

  chknum(y).positive(); // Or chknum(y).pos();

  chknum(z).isIn([1,5,6,8,321]);

  chknum(z).between(0,322); // Or chknum(z).btw(0,322);

  chknum(z).equal(200); // Or chknum(z).eq(200);
}