Is.js
MooTools convenient type-check methods and deep equality comparator.
Version: 0.0.3
Influences:
Dependencies:
Is
Is is an object that contains methods for checking type and equality. The API contains all of the methods found in Type
from MooTools-Core, with a few additions. Type
is decorated so that a convenient type-check method is also added to Is
whenever a new type is created.
Along with the positive checks, we have the opposing negative checks that can be accessed in Is.not
.
All type-check methods take only one argument: the object which will be type-checked. Is.Equal
is the only method that takes two arguments.
Examples:
var Human = function(){};
Is.Human;
Is.not.Human
new Type('Human', Human);
Is.Human;
Is.not.Human;
var Garrick;
Is.Human(Garrick);
Garrick = new Human;
Is.Human(Garrick);
Equal
Performs an optimized deep comparison between the two objects, to determine if they should be considered equal.
Syntax:
Is.Equal(object, other);
Arguments:
object
- (Mixed)
Can be anything. Used to compare with other
object. Deep comparisons are done on Object
types where each item is compared with the each item in other
.other
- (Mixed)
Just like object
, can be anything.
Returns: Boolean (true/false)
Notes:
If either object
or other
contains an isEqual
method, that method is passed the opposing object that is being tested. The result will be returned by Equal
method and the comparisons stops there.
Examples:
var a = {something: 'to', compare: 'to'},
b = {something: 'to', compare: 'to'};
a == b;
Is.Equal(a, b);
b = {something: 'else', to: {compare: 'to'}};
a == b;
Is.Equal(a, b);
a.isEqual = function(other){
return true;
}
Is.Equal(a, b);
NaN
Type-check for NaN
.
Examples:
Is.NaN('1');
Is.NaN('NaN');
Is.NaN(NaN);
Null
Type-check for null
.
Examples:
Is.Null('');
Is.Null(undefined);
Is.Null(null);
Undefined
Type-check for undefined
.
Examples:
Is.Undefined('');
Is.Undefined(null);
Is.Undefined();
Is.Undefined(undefined);
Is.Undefined(void 0);
MooTools-Core Type Methods
The following methods have been implemented from MooTools-Core Type
. They take the same arguments as their Type
counterparts. They also exist in Is.not
.
Arguments
Array
Boolean
Class
DOMEvent
Date
Document
Element
Elements
Enumerable
Function
IFrame
Number
Object
RegExp
String
TextNode
Type
WhiteSpace
Window