type-of-is
Advanced tools
Comparing version 3.1.3 to 3.2.0
@@ -83,2 +83,10 @@ var Type = require('./'); | ||
var t = new Type.of(s)("t"); | ||
console.log(t); // "t" | ||
console.log(t.toUpperCase()); // "T" | ||
// Type.any(obj, [Array, Of, Types]) and Type(obj, [Array, Of, Types]) should test whether | ||
// the object is any of the passed in types | ||
var str = 'hihihi'; | ||
console.log(Type.any(str, [String, Number, Array])); // true | ||
console.log(Type(str, [Array, RegExp])); // false | ||
28
index.js
@@ -1,2 +0,2 @@ | ||
(function (factory) { | ||
(function (factory) { | ||
if (typeof exports == 'object') { | ||
@@ -60,3 +60,3 @@ module.exports = factory(); | ||
} | ||
}; | ||
} | ||
@@ -66,4 +66,4 @@ function is (obj, test) { | ||
return (typer(obj) === test); | ||
}; | ||
} | ||
function instance (obj, test) { | ||
@@ -73,2 +73,15 @@ return (obj instanceof test); | ||
function any (obj, tests) { | ||
if (!is(tests, Array)) { | ||
throw ("Second argument to .any() should be array") | ||
} | ||
for (var i = 0; i < tests.length; i++) { | ||
var test = tests[i]; | ||
if (is(obj, test)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
var exports = function (obj, type) { | ||
@@ -78,3 +91,7 @@ if (arguments.length == 1) { | ||
} else { | ||
return is(obj, type); | ||
if (is(type, Array)) { | ||
return any(obj, type); | ||
} else { | ||
return is(obj, type); | ||
} | ||
} | ||
@@ -87,2 +104,3 @@ } | ||
exports.is = is; | ||
exports.any = any; | ||
@@ -89,0 +107,0 @@ return exports; |
{ | ||
"name": "type-of-is", | ||
"version": "3.1.3", | ||
"version": "3.2.0", | ||
"description": "Determine and test types using constructor or {}.toString", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -43,3 +43,3 @@ # Description | ||
3.1.3 | ||
3.2.0 | ||
@@ -59,3 +59,3 @@ | ||
"dependencies": { | ||
"type-of-is": "3.1.x" | ||
"type-of-is": "3.2.x" | ||
} | ||
@@ -168,4 +168,9 @@ } | ||
var t = new Type.of(s)("t"); | ||
console.log(t); // "t" | ||
console.log(t.toUpperCase()); // "T" | ||
// Type.any(obj, [Array, Of, Types]) and Type(obj, [Array, Of, Types]) should test whether | ||
// the object is any of the passed in types | ||
var str = 'hihihi'; | ||
console.log(Type.any(str, [String, Number, Array])); // true | ||
console.log(Type(str, [Array, RegExp])); // false | ||
@@ -172,0 +177,0 @@ // multi-frame dom |
@@ -131,3 +131,15 @@ var Path = require('path'); | ||
Assert(!Type.instance(ralph, String)); | ||
}, | ||
"Type.any and Type(obj, <Array>) should check whether an array is one of many types": function () { | ||
var str = 'abcdefg'; | ||
Assert(Type.any(str, [String])); | ||
Assert(Type.any(str, [Array, String])); | ||
Assert(!Type.any(str, [Array, Number])); | ||
Assert(Type(str, [String])); | ||
Assert(!Type(str, [Array, Number])); | ||
Assert.throws(function () { | ||
Type.any(str, String); | ||
}, /should be array/); | ||
} | ||
}); |
Sorry, the diff of this file is not supported yet
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
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
21581
305
220