Cheque.js
![Coverage Status](https://img.shields.io/coveralls/yuanqing/cheque.svg?style=flat)
Type checking, for when you only use JavaScript’s Good Parts.
API
'use strict';
var isInt = function(x) {
return typeof x == 'number' && x % 1 === 0;
};
module.exports = {
isUndefined: function(x) {
return typeof x == 'undefined';
},
isNull: function(x) {
return x === null;
},
isBoolean: function(x) {
return x === true || x === false;
},
isFloat: function(x) {
return typeof x == 'number' && isFinite(x);
},
isInt: isInt,
isInteger: isInt,
isString: function(x) {
return typeof x == 'string';
},
isNaN: function(x) {
return x != x;
},
isObject: function(x) {
return typeof x == 'object' && !!x && x.constructor === Object;
},
isArray: Array.isArray || function(x) {
return Object.prototype.toString.call(x) == '[object Array]';
},
isFunction: function(x) {
return typeof x == 'function';
}
};
You must not do terrible things like:
var boo = new Boolean(true);
var bad = new Number(42);
var noo = new String('foo');
Instead, do:
var yay = true;
var god = 42;
var yes = 'foo';
There are lots of tests.
Installation
Install via npm:
$ npm i --save cheque
Changelog
- 0.2.0
- Add polyfill for
Array.isArray
- 0.1.0
License
MIT license