typed-array-length (1.0.7)
Published 2026-02-24 14:07:45 +00:00 by atheaadmin
Installation
registry=npm install typed-array-length@1.0.7"typed-array-length": "1.0.7"About this package
typed-array-length 
Robustly get the length of a Typed Array, or false if it is not a Typed Array. Works cross-realm, in every engine, even if the length property is overridden.
Example
var typedArrayLength = require('typed-array-length');
var assert = require('assert');
assert.equal(false, typedArrayLength(undefined));
assert.equal(false, typedArrayLength(null));
assert.equal(false, typedArrayLength(false));
assert.equal(false, typedArrayLength(true));
assert.equal(false, typedArrayLength([]));
assert.equal(false, typedArrayLength({}));
assert.equal(false, typedArrayLength(/a/g));
assert.equal(false, typedArrayLength(new RegExp('a', 'g')));
assert.equal(false, typedArrayLength(new Date()));
assert.equal(false, typedArrayLength(42));
assert.equal(false, typedArrayLength(NaN));
assert.equal(false, typedArrayLength(Infinity));
assert.equal(false, typedArrayLength(new Number(42)));
assert.equal(false, typedArrayLength('foo'));
assert.equal(false, typedArrayLength(Object('foo')));
assert.equal(false, typedArrayLength(function () {}));
assert.equal(false, typedArrayLength(function* () {}));
assert.equal(false, typedArrayLength(x => x * x));
assert.equal(false, typedArrayLength([]));
assert.equal(1, typedArrayLength(new Int8Array(1)));
assert.equal(2, typedArrayLength(new Uint8Array(2)));
assert.equal(3, typedArrayLength(new Uint8ClampedArray(3)));
assert.equal(4, typedArrayLength(new Int16Array(4)));
assert.equal(5, typedArrayLength(new Uint16Array(5)));
assert.equal(6, typedArrayLength(new Int32Array(6)));
assert.equal(7, typedArrayLength(new Uint32Array(7)));
assert.equal(8, typedArrayLength(new Float32Array(8)));
assert.equal(9, typedArrayLength(new Float64Array(9)));
assert.equal(10, typedArrayLength(new BigInt64Array(10)));
assert.equal(11, typedArrayLength(new BigUint64Array(11)));
Tests
Simply clone the repo, npm install, and run npm test
Dependencies
Dependencies
| ID | Version |
|---|---|
| call-bind | ^1.0.7 |
| for-each | ^0.3.3 |
| gopd | ^1.0.1 |
| is-typed-array | ^1.1.13 |
| possible-typed-array-names | ^1.0.0 |
| reflect.getprototypeof | ^1.0.6 |
Development Dependencies
| ID | Version |
|---|---|
| @arethetypeswrong/cli | ^0.17.0 |
| @ljharb/eslint-config | ^21.1.1 |
| @ljharb/tsconfig | ^0.2.0 |
| @types/call-bind | ^1.0.5 |
| @types/for-each | ^0.3.3 |
| @types/gopd | ^1.0.3 |
| @types/is-callable | ^1.1.2 |
| @types/make-arrow-function | ^1.2.2 |
| @types/make-generator-function | ^2.0.3 |
| @types/object-inspect | ^1.13.0 |
| @types/tape | ^5.6.4 |
| auto-changelog | ^2.5.0 |
| eslint | =8.8.0 |
| evalmd | ^0.0.19 |
| in-publish | ^2.0.1 |
| is-callable | ^1.2.7 |
| make-arrow-function | ^1.2.0 |
| make-generator-function | ^2.0.0 |
| npmignore | ^0.3.1 |
| nyc | ^10.3.2 |
| object-inspect | ^1.13.3 |
| safe-publish-latest | ^2.0.0 |
| tape | ^5.9.0 |
| typescript | next |
Keywords
typed
array
length
robust
es
Int8Array
Uint8Array
Uint8ClampedArray
Int16Array
Uint16Array
Int32Array
Uint32Array
Float32Array
Float64Array
