component-type
Advanced tools
Comparing version 1.0.0 to 1.1.0
{ | ||
"name": "type", | ||
"description": "Cross-browser type assertions (less broken typeof)", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"keywords": ["typeof", "type", "utility"], | ||
@@ -6,0 +6,0 @@ "dependencies": {}, |
10
index.js
@@ -1,2 +0,1 @@ | ||
/** | ||
@@ -18,3 +17,2 @@ * toString ref. | ||
switch (toString.call(val)) { | ||
case '[object Function]': return 'function'; | ||
case '[object Date]': return 'date'; | ||
@@ -24,3 +22,3 @@ case '[object RegExp]': return 'regexp'; | ||
case '[object Array]': return 'array'; | ||
case '[object String]': return 'string'; | ||
case '[object Error]': return 'error'; | ||
} | ||
@@ -30,6 +28,10 @@ | ||
if (val === undefined) return 'undefined'; | ||
if (val !== val) return 'nan'; | ||
if (val && val.nodeType === 1) return 'element'; | ||
if (val === Object(val)) return 'object'; | ||
val = val.valueOf | ||
? val.valueOf() | ||
: Object.prototype.valueOf.apply(val) | ||
return typeof val; | ||
}; |
{ | ||
"name": "component-type", | ||
"description": "Cross-browser type assertions (less broken typeof)", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"keywords": [ | ||
@@ -6,0 +6,0 @@ "typeof", |
@@ -0,1 +1,2 @@ | ||
# type | ||
@@ -30,2 +31,4 @@ | ||
type(document.createElement('div')) == 'element' | ||
type(NaN) == 'nan' | ||
type(new Error('Ups! Something wrong...')) == 'error' | ||
``` | ||
@@ -32,0 +35,0 @@ |
@@ -9,5 +9,2 @@ var type = require('type') | ||
assert('object' === type(new Foo)); | ||
assert('object' === type(new Boolean(true))); | ||
assert('object' === type(new Number(123))); | ||
// assert('object' === type(new String('whoop'))); | ||
}); | ||
@@ -17,6 +14,15 @@ | ||
assert('number' === type(12)); | ||
assert('number' === type(1.0)); | ||
assert('number' === type(-5)); | ||
assert('number' === type(new Number(123))); | ||
assert('number' === type(Infinity)); | ||
}); | ||
it('should match NaN', function () { | ||
assert('nan' === type(NaN)); | ||
}); | ||
it('should match strings', function(){ | ||
assert('string' === type("test")); | ||
assert('string' === type(new String('whoop'))); | ||
}); | ||
@@ -31,2 +37,3 @@ | ||
assert('boolean' === type(false)); | ||
assert('boolean' === type(new Boolean(true))); | ||
}); | ||
@@ -39,2 +46,3 @@ | ||
it('should match undefined', function(){ | ||
assert('undefined' === type()); | ||
assert('undefined' === type(undefined)); | ||
@@ -45,2 +53,3 @@ }); | ||
assert('array' === type([])); | ||
assert('array' === type(new Array())); | ||
}); | ||
@@ -58,3 +67,3 @@ | ||
it('should match arguments', function(){ | ||
assert('arguments' === type((function(){ return arguments })())); | ||
assert('arguments' === type(arguments)); | ||
}); | ||
@@ -65,2 +74,6 @@ | ||
}); | ||
}); | ||
it('should match errors', function(){ | ||
assert('error' === type(new Error('Ups!'))); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
119028
4651
38
1