0.1.3 • Published 10 years ago
isval v0.1.3
isval
isval is a helper module that validates any given value. It overcomes common JavaScript issues with type checking, like NaN and null values.
Example
var isval = require('isval');
var string = 'I am a string';
assert.ok(isval(string, 'string'));Installation
Node
To install isval in a Node application use npm.
$ npm install isvalBrowser
No tests available for the browser but you may try using it via webpack.
$ webpack index.js isval.jsTest
To run tests use npm.
$ npm install
$ npm testDocumentation
Basic Usage
The following types are available:
'string''number''boolean''function''object''array''regex''regexp''date''null''undefined''NaN''arguments''integer''generator',(function *(){})()'generator*',function *() {}
Types can also be literal values:
StringNumberBooleanObjectnullundefinedNaN
Instance Of
Passing a constructor function will check if the value is an instanceof of that "Class".
var buffer = new ArrayBuffer();
isval(buffer, ArrayBuffer);Truthy Values
Passing no type will check for truthy values.
isval(1);
isval('true');API
isval(<value>, type)
License
Copyright (c) 2014 Christopher Turner