is-typed-array
Advanced tools
Comparing version 1.1.2 to 1.1.3
@@ -0,1 +1,5 @@ | ||
1.1.3 / 2020-01-24 | ||
================= | ||
* [Refactor] use `es-abstract`’s `callBound`, `available-typed-arrays`, `has-symbols` | ||
1.1.2 / 2020-01-20 | ||
@@ -2,0 +6,0 @@ ================= |
61
index.js
'use strict'; | ||
var forEach = require('foreach'); | ||
var availableTypedArrays = require('available-typed-arrays'); | ||
var callBound = require('es-abstract/helpers/callBound'); | ||
var toStr = Object.prototype.toString; | ||
var hasToStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol'; | ||
var $toString = callBound('Object.prototype.toString'); | ||
var hasSymbols = require('has-symbols')(); | ||
var hasToStringTag = hasSymbols && typeof Symbol.toStringTag === 'symbol'; | ||
var typedArrays = [ | ||
'Float32Array', | ||
'Float64Array', | ||
'Int8Array', | ||
'Int16Array', | ||
'Int32Array', | ||
'Uint8Array', | ||
'Uint8ClampedArray', | ||
'Uint16Array', | ||
'Uint32Array', | ||
'BigInt64Array', | ||
'BigUint64Array' | ||
]; | ||
var typedArrays = availableTypedArrays(); | ||
var $indexOf = Array.prototype.indexOf || function indexOf(value) { | ||
/* eslint no-invalid-this: 0 */ | ||
for (var i = 0; i < this.length; i += 1) { | ||
if (this[i] === value) { | ||
var $indexOf = callBound('Array.prototype.indexOf', true) || function indexOf(array, value) { | ||
for (var i = 0; i < array.length; i += 1) { | ||
if (array[i] === value) { | ||
return i; | ||
@@ -31,20 +21,19 @@ } | ||
}; | ||
var $slice = String.prototype.slice; | ||
var $slice = callBound('String.prototype.slice'); | ||
var toStrTags = {}; | ||
var gOPD = Object.getOwnPropertyDescriptor; | ||
if (hasToStringTag && gOPD && Object.getPrototypeOf) { | ||
var gOPD = require('es-abstract/helpers/getOwnPropertyDescriptor'); | ||
var getPrototypeOf = Object.getPrototypeOf; // require('getprototypeof'); | ||
if (hasToStringTag && gOPD && getPrototypeOf) { | ||
forEach(typedArrays, function (typedArray) { | ||
if (typeof global[typedArray] === 'function') { | ||
var arr = new global[typedArray](); | ||
if (!(Symbol.toStringTag in arr)) { | ||
throw new EvalError('this engine has support for Symbol.toStringTag, but ' + typedArray + ' does not have the property! Please report this.'); | ||
} | ||
var proto = Object.getPrototypeOf(arr); | ||
var descriptor = gOPD(proto, Symbol.toStringTag); | ||
if (!descriptor) { | ||
var superProto = Object.getPrototypeOf(proto); | ||
descriptor = gOPD(superProto, Symbol.toStringTag); | ||
} | ||
toStrTags[typedArray] = descriptor.get; | ||
var arr = new global[typedArray](); | ||
if (!(Symbol.toStringTag in arr)) { | ||
throw new EvalError('this engine has support for Symbol.toStringTag, but ' + typedArray + ' does not have the property! Please report this.'); | ||
} | ||
var proto = getPrototypeOf(arr); | ||
var descriptor = gOPD(proto, Symbol.toStringTag); | ||
if (!descriptor) { | ||
var superProto = getPrototypeOf(proto); | ||
descriptor = gOPD(superProto, Symbol.toStringTag); | ||
} | ||
toStrTags[typedArray] = descriptor.get; | ||
}); | ||
@@ -68,4 +57,4 @@ } | ||
if (!hasToStringTag) { | ||
var tag = $slice.call(toStr.call(value), 8, -1); | ||
return $indexOf.call(typedArrays, tag) > -1; | ||
var tag = $slice($toString(value), 8, -1); | ||
return $indexOf(typedArrays, tag) > -1; | ||
} | ||
@@ -72,0 +61,0 @@ if (!gOPD) { return false; } |
{ | ||
"name": "is-typed-array", | ||
"version": "1.1.2", | ||
"version": "1.1.3", | ||
"author": { | ||
@@ -57,3 +57,6 @@ "name": "Jordan Harband", | ||
"dependencies": { | ||
"foreach": "^2.0.5" | ||
"available-typed-arrays": "^1.0.0", | ||
"es-abstract": "^1.17.4", | ||
"foreach": "^2.0.5", | ||
"has-symbols": "^1.0.1" | ||
}, | ||
@@ -60,0 +63,0 @@ "devDependencies": { |
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
14230
4
10
143
+ Addedes-abstract@^1.17.4
+ Addedhas-symbols@^1.0.1
+ Addedarray-buffer-byte-length@1.0.1(transitive)
+ Addedarraybuffer.prototype.slice@1.0.3(transitive)
+ Addedavailable-typed-arrays@1.0.7(transitive)
+ Addedcall-bind@1.0.7(transitive)
+ Addeddata-view-buffer@1.0.1(transitive)
+ Addeddata-view-byte-length@1.0.1(transitive)
+ Addeddata-view-byte-offset@1.0.0(transitive)
+ Addeddefine-data-property@1.1.4(transitive)
+ Addeddefine-properties@1.2.1(transitive)
+ Addedes-abstract@1.23.5(transitive)
+ Addedes-define-property@1.0.0(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedes-object-atoms@1.0.0(transitive)
+ Addedes-set-tostringtag@2.0.3(transitive)
+ Addedes-to-primitive@1.2.1(transitive)
+ Addedfor-each@0.3.3(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedfunction.prototype.name@1.1.6(transitive)
+ Addedfunctions-have-names@1.2.3(transitive)
+ Addedget-intrinsic@1.2.4(transitive)
+ Addedget-symbol-description@1.0.2(transitive)
+ Addedglobalthis@1.0.4(transitive)
+ Addedgopd@1.0.1(transitive)
+ Addedhas-bigints@1.0.2(transitive)
+ Addedhas-property-descriptors@1.0.2(transitive)
+ Addedhas-proto@1.0.3(transitive)
+ Addedhas-symbols@1.0.3(transitive)
+ Addedhas-tostringtag@1.0.2(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedinternal-slot@1.0.7(transitive)
+ Addedis-array-buffer@3.0.4(transitive)
+ Addedis-bigint@1.0.4(transitive)
+ Addedis-boolean-object@1.1.2(transitive)
+ Addedis-callable@1.2.7(transitive)
+ Addedis-data-view@1.0.1(transitive)
+ Addedis-date-object@1.0.5(transitive)
+ Addedis-negative-zero@2.0.3(transitive)
+ Addedis-number-object@1.0.7(transitive)
+ Addedis-regex@1.1.4(transitive)
+ Addedis-shared-array-buffer@1.0.3(transitive)
+ Addedis-string@1.0.7(transitive)
+ Addedis-symbol@1.0.4(transitive)
+ Addedis-typed-array@1.1.13(transitive)
+ Addedis-weakref@1.0.2(transitive)
+ Addedisarray@2.0.5(transitive)
+ Addedobject-inspect@1.13.3(transitive)
+ Addedobject-keys@1.1.1(transitive)
+ Addedobject.assign@4.1.5(transitive)
+ Addedpossible-typed-array-names@1.0.0(transitive)
+ Addedregexp.prototype.flags@1.5.3(transitive)
+ Addedsafe-array-concat@1.1.2(transitive)
+ Addedsafe-regex-test@1.0.3(transitive)
+ Addedset-function-length@1.2.2(transitive)
+ Addedset-function-name@2.0.2(transitive)
+ Addedside-channel@1.0.6(transitive)
+ Addedstring.prototype.trim@1.2.9(transitive)
+ Addedstring.prototype.trimend@1.0.8(transitive)
+ Addedstring.prototype.trimstart@1.0.8(transitive)
+ Addedtyped-array-buffer@1.0.2(transitive)
+ Addedtyped-array-byte-length@1.0.1(transitive)
+ Addedtyped-array-byte-offset@1.0.2(transitive)
+ Addedtyped-array-length@1.0.6(transitive)
+ Addedunbox-primitive@1.0.2(transitive)
+ Addedwhich-boxed-primitive@1.0.2(transitive)
+ Addedwhich-typed-array@1.1.15(transitive)