Comparing version 2.1.4 to 2.2.0
@@ -43,2 +43,3 @@ (function(root, factory) { | ||
, object: function(arg){ return Object.prototype.toString.call(arg) === '[object Object]' && !types.promise(arg);} | ||
, someObject: function(arg){ return /\[object [^\]]+\]/i.test(Object.prototype.toString.call(arg));} | ||
, function: function(arg){ return typeof arg === 'function'; } | ||
@@ -112,3 +113,4 @@ , symbol: function(arg){ return typeof arg === 'symbol'; } | ||
types.uInt8ClampedArray(item) ? 'uInt8ClampedArray' : | ||
types.arrayBuffer(item) ? 'arrayBuffer' : 'unknown'; | ||
types.arrayBuffer(item) ? 'arrayBuffer' : | ||
types.someObject(item) ? 'object' : 'unknown'; | ||
}; | ||
@@ -115,0 +117,0 @@ |
@@ -1,2 +0,2 @@ | ||
!function(t,r){"use strict";if("function"==typeof define&&define.amd)define(["bower/ee-class/dist/ee-class.min"],r);else if("object"==typeof module&&"object"==typeof module.exports)module.exports=r(require("ee-class"));else{if("object"!=typeof t.ee&&(t.ee={}),!t.ee.Class)throw new Error("Missing the ee-class module! See https://github.com/eventEmitter/ee-class");t.ee.types=r(t.ee.Class)}}(this,function(t){"use strict";var r,e,n,o;return r=new t({string:function(t){return"string"==typeof t||"[object String]"===Object.prototype.toString.call(t)},number:function(t){return"number"==typeof t||"[object Number]"===Object.prototype.toString.call(t)},"boolean":function(t){return"boolean"==typeof t||"[object Boolean]"===Object.prototype.toString.call(t)},array:function(t){return Array.isArray(t)},intArray:function(t){return e.int8Array(t)||e.int16Array(t)||e.int32Array(t)||e.uInt8Array(t)||e.uInt16Array(t)||e.uInt32Array(t)||e.uInt8ClampedArray(t)},floatArray:function(t){return Array.isArray(t)||e.float32Array(t)},object:function(t){return"[object Object]"===Object.prototype.toString.call(t)&&!e.promise(t)},"function":function(t){return"function"==typeof t},symbol:function(t){return"symbol"==typeof t},date:function(t){return t instanceof Date&&!isNaN(t.valueOf())},regexp:function(t){return t instanceof RegExp},error:function(t){return t instanceof Error},undefined:function(t){return"undefined"==typeof t},buffer:function(t){return"object"==typeof global&&"function"==typeof global.Buffer&&global.Buffer.isBuffer(t)},"null":function(t){return null===t||"[object Null]"===Object.prototype.toString.call(t)},arrayBuffer:function(t){return"[object ArrayBuffer]"===Object.prototype.toString.call(t)},map:function(t){return"[object Map]"===Object.prototype.toString.call(t)},weakMap:function(t){return"[object WeakMap]"===Object.prototype.toString.call(t)},set:function(t){return"[object Set]"===Object.prototype.toString.call(t)},weakSet:function(t){return"[object WeakSet]"===Object.prototype.toString.call(t)},dataView:function(t){return"[object DataView]"===Object.prototype.toString.call(t)},float32Array:function(t){return"[object Float32Array]"===Object.prototype.toString.call(t)},float64Array:function(t){return"[object Float64Array]"===Object.prototype.toString.call(t)},int8Array:function(t){return"[object Int8Array]"===Object.prototype.toString.call(t)},int16Array:function(t){return"[object Int16Array]"===Object.prototype.toString.call(t)},int32Array:function(t){return"[object Int32Array]"===Object.prototype.toString.call(t)},uInt8Array:function(t){return"[object Uint8Array]"===Object.prototype.toString.call(t)},uInt16Array:function(t){return"[object Uint16Array]"===Object.prototype.toString.call(t)},uInt32Array:function(t){return"[object Uint32Array]"===Object.prototype.toString.call(t)},uInt8ClampedArray:function(t){return"[object Uint8ClampedArray]"===Object.prototype.toString.call(t)},generator:function(t){return"[object Generator]"===Object.prototype.toString.call(t)},promise:function(t){return"[object Promise]"===Object.prototype.toString.call(t)||"[object Object]"===Object.prototype.toString.call(t)&&e["function"](t.then)&&e["function"](t["catch"])}}),e=new r,o=function(t){return e.string(t)?"string":e.number(t)?"number":e["boolean"](t)?"boolean":e.object(t)?"object":e.array(t)?"array":e["null"](t)?"null":e.undefined(t)?"undefined":e["function"](t)?"function":e.date(t)?"date":e.regexp(t)?"regexp":e.error(t)?"error":e.buffer(t)?"buffer":e.symbol(t)?"symbol":e.map(t)?"map":e.weakMap(t)?"weakMap":e.set(t)?"set":e.weakSet(t)?"weakSet":e.promise(t)?"promise":e.dataView(t)?"dataView":e.float32Array(t)?"float32Array":e.float64Array(t)?"float64Array":e.int8Array(t)?"int8Array":e.int16Array(t)?"int16Array":e.int32Array(t)?"int32Array":e.generator(t)?"generator":e.uInt8Array(t)?"uInt8Array":e.uInt16Array(t)?"uInt16Array":e.uInt32Array(t)?"uInt32Array":e.intArray(t)?"intArray":e.floatArray(t)?"floatArray":e.uInt8ClampedArray(t)?"uInt8ClampedArray":e.arrayBuffer(t)?"arrayBuffer":"unknown"},n=Object.getPrototypeOf(e),Object.keys(n).forEach(function(t){if(o[t])throw new Error("Failed to map property «"+t+"» of types to type :(");o[t]=e[t].bind(e)}),Object.keys(e).forEach(function(t){if(o[t])throw new Error("Failed to map property «"+t+"» of types to type :(");o[t]=e[t]}),o}); | ||
!function(t,r){"use strict";if("function"==typeof define&&define.amd)define(["bower/ee-class/dist/ee-class.min"],r);else if("object"==typeof module&&"object"==typeof module.exports)module.exports=r(require("ee-class"));else{if("object"!=typeof t.ee&&(t.ee={}),!t.ee.Class)throw new Error("Missing the ee-class module! See https://github.com/eventEmitter/ee-class");t.ee.types=r(t.ee.Class)}}(this,function(t){"use strict";var r,e,n,o;return r=new t({string:function(t){return"string"==typeof t||"[object String]"===Object.prototype.toString.call(t)},number:function(t){return"number"==typeof t||"[object Number]"===Object.prototype.toString.call(t)},"boolean":function(t){return"boolean"==typeof t||"[object Boolean]"===Object.prototype.toString.call(t)},array:function(t){return Array.isArray(t)},intArray:function(t){return e.int8Array(t)||e.int16Array(t)||e.int32Array(t)||e.uInt8Array(t)||e.uInt16Array(t)||e.uInt32Array(t)||e.uInt8ClampedArray(t)},floatArray:function(t){return Array.isArray(t)||e.float32Array(t)},object:function(t){return"[object Object]"===Object.prototype.toString.call(t)&&!e.promise(t)},someObject:function(t){return/\[object [^\]]+\]/i.test(Object.prototype.toString.call(t))},"function":function(t){return"function"==typeof t},symbol:function(t){return"symbol"==typeof t},date:function(t){return t instanceof Date&&!isNaN(t.valueOf())},regexp:function(t){return t instanceof RegExp},error:function(t){return t instanceof Error},undefined:function(t){return"undefined"==typeof t},buffer:function(t){return"object"==typeof global&&"function"==typeof global.Buffer&&global.Buffer.isBuffer(t)},"null":function(t){return null===t||"[object Null]"===Object.prototype.toString.call(t)},arrayBuffer:function(t){return"[object ArrayBuffer]"===Object.prototype.toString.call(t)},map:function(t){return"[object Map]"===Object.prototype.toString.call(t)},weakMap:function(t){return"[object WeakMap]"===Object.prototype.toString.call(t)},set:function(t){return"[object Set]"===Object.prototype.toString.call(t)},weakSet:function(t){return"[object WeakSet]"===Object.prototype.toString.call(t)},dataView:function(t){return"[object DataView]"===Object.prototype.toString.call(t)},float32Array:function(t){return"[object Float32Array]"===Object.prototype.toString.call(t)},float64Array:function(t){return"[object Float64Array]"===Object.prototype.toString.call(t)},int8Array:function(t){return"[object Int8Array]"===Object.prototype.toString.call(t)},int16Array:function(t){return"[object Int16Array]"===Object.prototype.toString.call(t)},int32Array:function(t){return"[object Int32Array]"===Object.prototype.toString.call(t)},uInt8Array:function(t){return"[object Uint8Array]"===Object.prototype.toString.call(t)},uInt16Array:function(t){return"[object Uint16Array]"===Object.prototype.toString.call(t)},uInt32Array:function(t){return"[object Uint32Array]"===Object.prototype.toString.call(t)},uInt8ClampedArray:function(t){return"[object Uint8ClampedArray]"===Object.prototype.toString.call(t)},generator:function(t){return"[object Generator]"===Object.prototype.toString.call(t)},promise:function(t){return"[object Promise]"===Object.prototype.toString.call(t)||"[object Object]"===Object.prototype.toString.call(t)&&e["function"](t.then)&&e["function"](t["catch"])}}),e=new r,o=function(t){return e.string(t)?"string":e.number(t)?"number":e["boolean"](t)?"boolean":e.object(t)?"object":e.array(t)?"array":e["null"](t)?"null":e.undefined(t)?"undefined":e["function"](t)?"function":e.date(t)?"date":e.regexp(t)?"regexp":e.error(t)?"error":e.buffer(t)?"buffer":e.symbol(t)?"symbol":e.map(t)?"map":e.weakMap(t)?"weakMap":e.set(t)?"set":e.weakSet(t)?"weakSet":e.promise(t)?"promise":e.dataView(t)?"dataView":e.float32Array(t)?"float32Array":e.float64Array(t)?"float64Array":e.int8Array(t)?"int8Array":e.int16Array(t)?"int16Array":e.int32Array(t)?"int32Array":e.generator(t)?"generator":e.uInt8Array(t)?"uInt8Array":e.uInt16Array(t)?"uInt16Array":e.uInt32Array(t)?"uInt32Array":e.intArray(t)?"intArray":e.floatArray(t)?"floatArray":e.uInt8ClampedArray(t)?"uInt8ClampedArray":e.arrayBuffer(t)?"arrayBuffer":e.someObject(t)?"object":"unknown"},n=Object.getPrototypeOf(e),Object.keys(n).forEach(function(t){if(o[t])throw new Error("Failed to map property «"+t+"» of types to type :(");o[t]=e[t].bind(e)}),Object.keys(e).forEach(function(t){if(o[t])throw new Error("Failed to map property «"+t+"» of types to type :(");o[t]=e[t]}),o}); | ||
//# sourceMappingURL=maps/ee-types.min.js.map |
{ | ||
"name": "ee-types", | ||
"description": "Reliable type detection", | ||
"version": "2.1.4", | ||
"version": "2.2.0", | ||
"homepage": "https://github.com/eventEmitter/ee-types", | ||
@@ -22,3 +22,3 @@ "author": "Michael van der Weg <michael@joinbox.com> (http://joinbox.com/)", | ||
"devDependencies": { | ||
"mocha": "3.x", | ||
"mocha": "5.x", | ||
"gulp": "3.x", | ||
@@ -25,0 +25,0 @@ "gulp-concat": "2.x", |
@@ -128,23 +128,69 @@ # ee-types | ||
- promise | ||
- someObject | ||
#### Object Types | ||
Since many of the types defined by javascript are just special | ||
objects that also can be treated as normal objects ee-types has | ||
are a bunch of methods that allow you to handle that correctly. | ||
For example `Map` is an object too. Or custom class where you | ||
define a getter that returns a specific name for your object: | ||
```javascript | ||
const X = class { | ||
get [Symbol.toStringTag]() { | ||
return 'AQL query';; | ||
} | ||
}; | ||
console.log(Object.prototype.toString.call(new X())); | ||
// prints: [object AQL Query] | ||
``` | ||
##### Check for a classic object | ||
```javascript | ||
types.object({}); // true | ||
types.object(new Map()); // false | ||
// be aware that if you are not explicitly testing | ||
// for an object any obecjt will be treated as one | ||
types({}) // 'object' | ||
types(new Map()) // 'object' | ||
``` | ||
##### Check any type of object | ||
```javascript | ||
types.someObject({}); // true | ||
types.someObject(new Map()); // false | ||
types(new Map()) // 'object' | ||
``` | ||
## Examples | ||
var types = require('ee-types'); | ||
```javascript | ||
var types = require('ee-types'); | ||
types.string('nope'); // true | ||
types.strign(new String('yeah')); // true | ||
types.string('nope'); // true | ||
types.strign(new String('yeah')); // true | ||
types(2) // number | ||
types(2) // number | ||
types([]]) // array | ||
types(new Array()]) // array | ||
types(new Int8Array()]) // int8Array | ||
types([]]) // array | ||
types(new Array()]) // array | ||
types(new Int8Array()]) // int8Array | ||
types.promise(Promise.all()) // true | ||
types.promise(Promise.all()) // true | ||
``` |
@@ -43,2 +43,3 @@ (function(root, factory) { | ||
, object: function(arg){ return Object.prototype.toString.call(arg) === '[object Object]' && !types.promise(arg);} | ||
, someObject: function(arg){ return /\[object [^\]]+\]/i.test(Object.prototype.toString.call(arg));} | ||
, function: function(arg){ return typeof arg === 'function'; } | ||
@@ -112,3 +113,4 @@ , symbol: function(arg){ return typeof arg === 'symbol'; } | ||
types.uInt8ClampedArray(item) ? 'uInt8ClampedArray' : | ||
types.arrayBuffer(item) ? 'arrayBuffer' : 'unknown'; | ||
types.arrayBuffer(item) ? 'arrayBuffer' : | ||
types.someObject(item) ? 'object' : 'unknown'; | ||
}; | ||
@@ -115,0 +117,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
60911
5938
314
196
12