isval

0.1.3 • Public • Published

isval

isval is a helper module that validates any given value. It overcomes common JavaScript issues with type checking, like NaN and null values.

Build Status

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 isval

Browser

No tests available for the browser but you may try using it via webpack.

$ webpack index.js isval.js

Test

To run tests use npm.

$ npm install
$ npm test

Documentation

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:

  • String
  • Number
  • Boolean
  • Object
  • null
  • undefined
  • NaN

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

MIT

Copyright (c) 2014 Christopher Turner

Package Sidebar

Install

npm i isval

Weekly Downloads

288

Version

0.1.3

License

MIT

Last publish

Collaborators

  • tur-nr