What is is-typed-array?
The is-typed-array npm package is a utility for checking if a given value is a typed array. Typed arrays are array-like objects that provide a mechanism for reading and writing raw binary data in memory buffers. This package helps in determining whether a variable is one of the typed array types, such as Int8Array, Uint8Array, Float32Array, etc.
What are is-typed-array's main functionalities?
Check if a value is a typed array
This feature allows you to check if a given value is a typed array. The function returns true if the value is one of the typed array types, and false otherwise.
const isTypedArray = require('is-typed-array');
const buffer = new ArrayBuffer(16);
const int16Array = new Int16Array(buffer);
const result = isTypedArray(int16Array); // true
Other packages similar to is-typed-array
isarray
The isarray package is used to check if a given value is an Array. It does not specifically check for typed arrays, but it can be used to determine if a value is an array of any kind.
is-buffer
The is-buffer package checks if an object is a Node.js Buffer, which is a global object used to deal with binary data directly. While it does not check for typed arrays, it serves a similar purpose in identifying binary data containers.
is-typed-array
[![dependency status][5]][6]
[![dev dependency status][7]][8]
Is this value a JS Typed Array? This module works cross-realm/iframe, does not depend on instanceof
or mutable properties, and despite ES6 Symbol.toStringTag.
Example
var isTypedArray = require('is-typed-array');
var assert = require('assert');
assert.equal(false, isTypedArray(undefined));
assert.equal(false, isTypedArray(null));
assert.equal(false, isTypedArray(false));
assert.equal(false, isTypedArray(true));
assert.equal(false, isTypedArray([]));
assert.equal(false, isTypedArray({}));
assert.equal(false, isTypedArray(/a/g));
assert.equal(false, isTypedArray(new RegExp('a', 'g')));
assert.equal(false, isTypedArray(new Date()));
assert.equal(false, isTypedArray(42));
assert.equal(false, isTypedArray(NaN));
assert.equal(false, isTypedArray(Infinity));
assert.equal(false, isTypedArray(new Number(42)));
assert.equal(false, isTypedArray('foo'));
assert.equal(false, isTypedArray(Object('foo')));
assert.equal(false, isTypedArray(function () {}));
assert.equal(false, isTypedArray(function* () {}));
assert.equal(false, isTypedArray(x => x * x));
assert.equal(false, isTypedArray([]));
assert.ok(isTypedArray(new Int8Array()));
assert.ok(isTypedArray(new Uint8Array()));
assert.ok(isTypedArray(new Uint8ClampedArray()));
assert.ok(isTypedArray(new Int16Array()));
assert.ok(isTypedArray(new Uint16Array()));
assert.ok(isTypedArray(new Int32Array()));
assert.ok(isTypedArray(new Uint32Array()));
assert.ok(isTypedArray(new Float32Array()));
assert.ok(isTypedArray(new Float64Array()));
assert.ok(isTypedArray(new BigInt64Array()));
assert.ok(isTypedArray(new BigUint64Array()));
Tests
Simply clone the repo, npm install
, and run npm test