Comparing version 0.0.7 to 0.1.0
585
is.js
@@ -1,162 +0,509 @@ | ||
// is.js | ||
// JavaScript type testing library | ||
// | ||
// Copyright 2011 Enrico Marino | ||
// MIT license | ||
!function (name, definition) { | ||
if (typeof module != 'undefined') module.exports = definition() | ||
else if (typeof define == 'function' && define.amd) define(name, definition) | ||
else this[name] = definition() | ||
}('is', function (context, undefined) { | ||
/*! | ||
* is | ||
* the definitive JavaScript type testing library | ||
* Copyright(c) 2011 Enrico Marino <enrico.marino@email.com> | ||
* MIT license | ||
*/ | ||
var owns = {}.hasOwnProperty, | ||
to_string = {}.toString, | ||
is_finite = isFinite; | ||
!(function (exports) { | ||
function arguments (self) { | ||
return to_string.call(self) === '[object Arguments]'; | ||
} | ||
var undefined | ||
, owns = {}.hasOwnProperty | ||
, toString = {}.toString | ||
, isFinite = isFinite | ||
, NON_HOST_TYPES = { | ||
'boolean': 1 | ||
, 'number': 1 | ||
, 'string': 1 | ||
, 'undefined': 1 | ||
} | ||
; | ||
function array (self) { | ||
return to_string.call(self) === '[object Array]'; | ||
} | ||
var is = exports.is = {}; | ||
function arraylike (self) { | ||
return (self && self.length && is_finite(self.length)); | ||
} | ||
/** | ||
* Test if 'value' is an arguments object | ||
* | ||
* @param value value to test | ||
* @return {Boolean} true if 'value' is an arguments object, false otherwise | ||
* @api public | ||
*/ | ||
function boolean (b) { | ||
return to_string.call(self) === '[object Boolean]'; | ||
} | ||
is.arguments = function (value) { | ||
return '[object Arguments]' === toString.call(value); | ||
}; | ||
function date (self) { | ||
/** | ||
* Test if 'value' is an array | ||
* | ||
* @param value value to test | ||
* @return {Boolean} true if 'value' is an array, false otherwise | ||
* @api public | ||
*/ | ||
return to_string.call(self) === '[object Date]'; | ||
is.array = function (value) { | ||
return '[object Array]' === toString.call(value); | ||
}; | ||
/** | ||
* Test if 'value' is an empty array(like) object | ||
* | ||
* @param {Array|Arguments} value value to test | ||
* @return {Boolean} true if 'value' is an empty array(like), false otherwise | ||
* @api public | ||
*/ | ||
is.array.empty = function (value) { | ||
return value.length === 0; | ||
}; | ||
/** | ||
* Test if 'value' is an arraylike object | ||
* | ||
* @param value value to test | ||
* @return {Boolean} true if 'value' is an arguments object, false otherwise | ||
* @api public | ||
*/ | ||
is.arraylike = function (value) { | ||
return value !== undefined | ||
&& owns.call(value, 'length') | ||
&& isFinite(value.length); | ||
}; | ||
/** | ||
* Test if 'value' is a boolean | ||
* | ||
* @param value value to test | ||
* @return {Boolean} true if 'value' is a boolean, false otherwise | ||
* @api public | ||
*/ | ||
is.boolean = function (value) { | ||
return '[object Boolean]' === toString.call(value); | ||
}; | ||
/** | ||
* Test if 'value' is a date | ||
* | ||
* @param value value to test | ||
* @return {Boolean} true if 'value' is a date, false otherwise | ||
* @api public | ||
*/ | ||
is.date = function (value) { | ||
return '[object Date]' === toString.call(value); | ||
}; | ||
/** | ||
* Test if 'value' is a decimal number | ||
* | ||
* @param value value to test | ||
* @return {Boolean} true if 'value' is a decimal number, false otherwise | ||
* @api public | ||
*/ | ||
is.decimal = function (value) { | ||
return '[object Number]' === toString.call(value) | ||
&& value % 1 !== 0; | ||
}; | ||
/** | ||
* Test if 'value' is defined | ||
* | ||
* @param value value to test | ||
* @return {Boolean} true if 'value' is defined, false otherwise | ||
* @api public | ||
*/ | ||
is.defined = function (value) { | ||
return value !== undefined; | ||
}; | ||
/** | ||
* Test if 'value' is divisible by 'n' | ||
* | ||
* @param {Number} value value to test | ||
* @param {Number} n dividend | ||
* @return {Boolean} true if 'value' is divisible by 'n', false otherwise | ||
* @api public | ||
*/ | ||
is.divisibleBy = function (value, n) { | ||
return '[object Number]' === toString.call(value) | ||
&& n !== 0 | ||
&& value % n === 0; | ||
}; | ||
/** | ||
* Test if 'value' is an html element | ||
* | ||
* @param value value to test | ||
* @return {Boolean} true if 'value' is an html element, false otherwise | ||
* @api public | ||
*/ | ||
is.element = function (value) { | ||
return value !== undefined | ||
&& owns.call(value, nodeType) | ||
&& value.nodeType === 1; | ||
}; | ||
/** | ||
* Test if 'value' is empty | ||
* | ||
* @param value value to test | ||
* @return {Boolean} true if 'value' is empty, false otherwise | ||
* @api public | ||
*/ | ||
is.empty = function (value) { | ||
var type = toString.call(value) | ||
, key | ||
; | ||
if ('[object Array]' === type || '[object Arguments]' === type) { | ||
return value.length === 0; | ||
} | ||
function decimal (self) { | ||
return to_string.call(self) === '[object Number]' && self % 1 !== 0; | ||
if ('[object Object]' === type) { | ||
for (var key in value) if (owns.call(value, key)) return false; | ||
return true; | ||
} | ||
if ('[object String]' === type) { | ||
return value === ''; | ||
} | ||
function def (self) { | ||
return false; | ||
}; | ||
return to_string.call(self) !== '[object Undefined]'; | ||
/** | ||
* Test if 'value' is an error object | ||
* | ||
* @param value value to test | ||
* @return {Boolean} true if 'value' is an error object, false otherwise | ||
* @api public | ||
*/ | ||
is.error = function (value) { | ||
return '[object Error]' === toString.call(value); | ||
}; | ||
/** | ||
* Test if 'value' is equal to 'other' | ||
* | ||
* @param value value | ||
* @param other value to compare with | ||
* @return {Boolean} true if 'value' is equal to 'other', false otherwise | ||
*/ | ||
is.equal = function (value, other) { | ||
var undefined | ||
, type = toString.call(value) | ||
, key | ||
; | ||
if (type !== toString.call(other)) { | ||
return false; | ||
} | ||
function element (self) { | ||
return !!(self && self.nodeType && self.nodeType === 1); | ||
if ('[object Object]' === type) { | ||
for (key in value) { | ||
if (!equiv(value[key], other[key])) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
function error (self) { | ||
return to_string.call(self) === '[object Error]'; | ||
if ('[object Array]' === type) { | ||
key = value.length; | ||
if (key !== other.length) { | ||
return false; | ||
} | ||
while (--key) { | ||
if (!equiv(value[key], other[key])) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
function func (self) { | ||
return to_string.call(self) === '[object Function]'; | ||
if ('[object Function]' === type) { | ||
return value.prototype === other.prototype; | ||
} | ||
function integer (self) { | ||
return to_string.call(self) === '[object Number]' && self % 1 === 0; | ||
if ('[object Date]' === type) { | ||
return value.getTime() === other.getTime(); | ||
} | ||
function nan (self) { | ||
return value === other; | ||
}; | ||
return self !== self; | ||
} | ||
/** | ||
* Test if 'value' is an even number | ||
* | ||
* @param {Number} value to test | ||
* @return {Boolean} true if 'value' is an even number, false otherwise | ||
* @api public | ||
*/ | ||
function nil (self) { | ||
is.even = function (value) { | ||
return '[object Number]' === toString.call(value) && value % 2 === 0; | ||
}; | ||
return to_string.call(self) === '[object Null]'; | ||
} | ||
/** | ||
* Test if 'value' is false | ||
* | ||
* @param value value to test | ||
* @return {Boolean} true if 'value' is false, false otherwise | ||
* @api public | ||
*/ | ||
function number (self) { | ||
return to_string.call(self) === '[object Number]'; | ||
} | ||
is.false = function (value) { | ||
return value === false; | ||
}; | ||
function object (self) { | ||
/** | ||
* Test if 'value' is a function | ||
* | ||
* @param value value to test | ||
* @return {Boolean} true if 'value' is a function, false otherwise | ||
* @api public | ||
*/ | ||
return to_string.call(self) === '[object Object]'; | ||
} | ||
is.function = function(value) { | ||
return '[object Function]' === toString.call(value); | ||
}; | ||
function regex (self) { | ||
/** | ||
* Test if 'value' is hosted by 'host' | ||
* | ||
* @param {String} value to test | ||
* @param host host | ||
* @return {Boolean} true if 'value' is hosted by 'host', false otherwise | ||
* @api public | ||
*/ | ||
return to_string.call(self) === '[object RegExp]'; | ||
} | ||
is.hosted = function (value, host) { | ||
var type = typeof host[value]; | ||
return type === 'object' ? !!host[value] : !NON_HOST_TYPES[type]; | ||
}; | ||
function string (self) { | ||
return to_string.call(self) === '[object String]'; | ||
} | ||
/** | ||
* Test if 'value' is greater than or equal to 'other' | ||
* | ||
* @param {Number} value value to test | ||
* @param {Number} other value to compare with | ||
* @return {Boolean} | ||
* @api public | ||
*/ | ||
function undef (self) { | ||
is.ge = function (value, other) { | ||
return value >= other; | ||
}; | ||
return to_string.call(self) === '[object Undefined]'; | ||
} | ||
/** | ||
* Test if 'value' is greater than 'other' | ||
* | ||
* @param {Number} value value to test | ||
* @param {Number} other value to compare with | ||
* @return {Boolean} | ||
* @api public | ||
*/ | ||
function empty (self) { | ||
var key; | ||
is.gt = function (value, other) { | ||
return value > other; | ||
}; | ||
if (array.call(self) || arraylike.call(self) || arguments.call(self)) { | ||
return self.length === 0; | ||
} | ||
/** | ||
* Test if 'value' is an integer | ||
* | ||
* @param value to test | ||
* @return {Boolean} true if 'value' is an integer, false otherwise | ||
* @api public | ||
*/ | ||
if (object.call(self)) { | ||
for (key in self) { | ||
if (owns.call(self, key)) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
is.int = function (value) { | ||
return '[object Number]' === toString.call(value) && value % 1 === 0; | ||
}; | ||
if (string.call(self)) { | ||
return self === ''; | ||
} | ||
/** | ||
* Test if 'value' is not a number | ||
* | ||
* @param value to test | ||
* @return {Boolean} true if 'value' is not a number, false otherwise | ||
* @api public | ||
*/ | ||
is.nan = function (value) { | ||
return value === null || value !== value; | ||
}; | ||
/** | ||
* Test if 'value' is less than or equal to 'other' | ||
* | ||
* @param {Number} value value to test | ||
* @param {Number} other value to compare with | ||
* @return {Boolean} if 'value' is less than or equal to 'other' | ||
* @api public | ||
*/ | ||
is.le = function (value, other) { | ||
return value < other; | ||
}; | ||
/** | ||
* Test if 'value' is less than 'other' | ||
* | ||
* @param {Number} value value to test | ||
* @param {Number} other value to compare with | ||
* @return {Boolean} if 'value' is less than 'other' | ||
* @api public | ||
*/ | ||
is.lt = function (value, other) { | ||
return value < other; | ||
}; | ||
/** | ||
* Test if 'value' is greater than 'others' values | ||
* | ||
* @param {Number} value value to test | ||
* @param {Array} others values to compare with | ||
* @return {Boolean} true if 'value' is greater than 'others' values | ||
* @api public | ||
*/ | ||
is.maximum = function (value, others) { | ||
var len = others.length; | ||
while (--len) { | ||
if (value < others[len]) { | ||
return false; | ||
} | ||
} | ||
return { | ||
args: arguments, | ||
arguments: arguments, | ||
array: array, | ||
arraylike: arraylike, | ||
bool: bool, | ||
boolean: bool, | ||
date: date, | ||
decimal: decimal, | ||
def: def, | ||
defined: defined, | ||
el: element, | ||
element: element, | ||
err: error, | ||
error: error, | ||
func: func, | ||
int: integer, | ||
integer: integer, | ||
nan: nan, | ||
nil: nil, | ||
num: number, | ||
number: number, | ||
obj: object, | ||
object: object, | ||
regex: regex, | ||
str: string, | ||
string: string, | ||
undef: undef, | ||
empty: empty | ||
}; | ||
return true; | ||
}; | ||
}(this)); | ||
/** | ||
* Test if 'value' is less than 'others' values | ||
* | ||
* @param {Number} value value to test | ||
* @param {Array} others values to compare with | ||
* @return {Boolean} true if 'value' is less than 'others' values | ||
* @api public | ||
*/ | ||
is.minimum = function (value, others) { | ||
var len = values.length; | ||
while (--len) { | ||
if (value > others[len]) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
}; | ||
/** | ||
* Test if 'value' is null | ||
* | ||
* @param value to test | ||
* @return {Boolean} true if 'value' is null, false otherwise | ||
* @api public | ||
*/ | ||
is.null = function (value) { | ||
return value === null; | ||
}; | ||
/** | ||
* Test if 'value' is a number | ||
* | ||
* @param value to test | ||
* @return {Boolean} true if 'value' is a number, false otherwise | ||
* @api public | ||
*/ | ||
is.number = function (value) { | ||
return '[object Number]' === toString.call(value); | ||
}; | ||
/** | ||
* Test if 'value' is an odd number | ||
* | ||
* @param {Number} value to test | ||
* @return {Boolean} true if 'value' is an odd number, false otherwise | ||
* @api public | ||
*/ | ||
is.odd = function (value) { | ||
return '[object Number]' === toString.call(value) && value % 2 !== 0; | ||
}; | ||
/** | ||
* Test if 'value' is an object | ||
* | ||
* @param value to test | ||
* @return {Boolean} true if 'value' is an object, false otherwise | ||
* @api public | ||
*/ | ||
is.object = function (value) { | ||
return '[object Object]' === toString.call(value); | ||
} | ||
/** | ||
* Test if 'value' is a regular expression | ||
* | ||
* @param value to test | ||
* @return {Boolean} true if 'value' is a regexp, false otherwise | ||
* @api public | ||
*/ | ||
is.regexp = function (value) { | ||
return '[object RegExp]' === toString.call(value); | ||
}; | ||
/** | ||
* Test if 'value' is a string | ||
* | ||
* @param value to test | ||
* @return {Boolean} true if 'value' is a string, false otherwise | ||
* @api public | ||
*/ | ||
is.string = function (value) { | ||
return '[object String]' === toString.call(value); | ||
} | ||
/** | ||
* Test if 'value' is true | ||
* | ||
* @param {Boolean} value to test | ||
* @return {Boolean} true if 'value' is true, false otherwise | ||
* @api public | ||
*/ | ||
is.true = function (value) { | ||
return value === true; | ||
}; | ||
/** | ||
* Test if 'value' is undefined | ||
* | ||
* @param value value to test | ||
* @return {Boolean} true if 'value' is undefined, false otherwise | ||
* @api public | ||
*/ | ||
is.undefined = function (value) { | ||
return value === undefined; | ||
}; | ||
}(this)); |
{ | ||
"name": "is", | ||
"description": "JavaScript type testing library", | ||
"description": "the definitive JavaScript type testing library", | ||
"homepage": "https://github.com/onirame/is", | ||
"keywords": [ | ||
"util", | ||
"test", | ||
"type", | ||
@@ -21,3 +22,3 @@ "sniff", | ||
"main": "is.js", | ||
"version": "0.0.7", | ||
"version": "0.1.0", | ||
"devDependencies": {}, | ||
@@ -24,0 +25,0 @@ "engines": { |
@@ -1,28 +0,42 @@ | ||
# is.js | ||
# is | ||
JavaScript type testing library | ||
the definitive JavaScript type testing library | ||
## API | ||
is x ... ? | ||
is value ... ? | ||
- arguments(x), args(x) | ||
- array(x) | ||
- arraylike(x) | ||
- boolean(x), bool(x) | ||
- date(x) | ||
- decimal(x) | ||
- defined(x), def(x) | ||
- element(x), el(x) | ||
- empty(x) | ||
- error(x), err(x) | ||
- func(x) | ||
- integer(x), int(x) | ||
- nan(x) | ||
- nil(x) | ||
- number(x), num(x) | ||
- object(x) | ||
- regex(x) | ||
- string(x) | ||
- undef(x) | ||
- arguments (value) | ||
- array (value) | ||
- array.empty (value) | ||
- arraylike (value) | ||
- boolean (value) | ||
- date (value) | ||
- decimal (value) | ||
- defined (value) | ||
- divisibleBy (value) | ||
- element (value) | ||
- empty (value) | ||
- error (value) | ||
- equal (value) | ||
- even (value) | ||
- false (value) | ||
- function (value) | ||
- hosted (value, host) | ||
- ge (value) | ||
- gt (value) | ||
- int (value) | ||
- nan (value) | ||
- le (value) | ||
- lt (value) | ||
- maximum (value) | ||
- minimum (value) | ||
- null (value) | ||
- number (value) | ||
- odd (value) | ||
- object (value) | ||
- regexp (value) | ||
- string (value) | ||
- true (value) | ||
- undefined (value) | ||
@@ -29,0 +43,0 @@ ## License |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No License Found
License(Experimental) License information could not be found.
Found 1 instance in 1 package
14466
4
0
424
66
1