Registry / serialization / which-typed-array

which-typed-array

JSON →
library1.1.20jsnpmunverified

The `which-typed-array` package provides a robust and cross-realm method for determining the specific kind of JavaScript Typed Array a given value is. Unlike `instanceof`, it works reliably across different JavaScript realms (e.g., iframes, web workers) and bypasses issues with `Symbol.toStringTag` being overridden. It returns the string name of the Typed Array (e.g., 'Int8Array', 'Uint32Array', 'Float64Array') or `false` if the value is not a Typed Array. The current stable version is 1.1.20, indicating a mature and well-tested utility. Given its focused scope and the stability of the underlying JavaScript `TypedArray` specification, new releases are generally infrequent, focusing on compatibility and minor improvements. It's a foundational utility often used by libraries that need to handle various JavaScript value types precisely.

npm install which-typed-array
INSTALL
IMPORT
SIG · WHICH-TYPED-ARRAY
W
which-typed-array
serializationjavascriptv1.1.20
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

whichTypedArray
import whichTypedArray from 'which-typed-array';
const whichTypedArray = require('which-typed-array');
While the README uses `require`, the library supports ESM. For modern Node.js and browser environments, prefer the ESM import.

This quickstart demonstrates how to import and use `whichTypedArray` to identify various Typed Array types and distinguish them from other JavaScript values.

import whichTypedArray from 'which-typed-array'; console.log(whichTypedArray(new Int8Array())); // 'Int8Array' console.log(whichTypedArray(new Uint8ClampedArray(10))); // 'Uint8ClampedArray' console.log(whichTypedArray(new Float64Array([1.1, 2.2]))); // 'Float64Array' console.log(whichTypedArray([])); // false console.log(whichTypedArray({})); // false console.log(whichTypedArray(42)); // false console.log(whichTypedArray(null)); // false // Example with BigInt Typed Arrays if (typeof BigInt64Array !== 'undefined') { console.log(whichTypedArray(new BigInt64Array([1n, 2n]))); // 'BigInt64Array' }
Debug
Known issues
gotchaThis package is designed specifically for standard JavaScript Typed Arrays (e.g., Int8Array, Float64Array). It will return `false` for ArrayBuffer, DataView, or any custom objects that might mimic Typed Array behavior but are not true `TypedArray` instances.
fix
If you need to check for `ArrayBuffer` or `DataView`, use dedicated checks like `value instanceof ArrayBuffer` or `Object.prototype.toString.call(value) === '[object ArrayBuffer]'`.
affects: >=1.0.0
gotchaThe primary function is a default export, meaning it should be imported directly as `import whichTypedArray from 'which-typed-array'` in ESM. Using a named import or destructuring will result in `undefined`.
fix
Ensure you are using `import whichTypedArray from 'which-typed-array';` for ESM or `const whichTypedArray = require('which-typed-array');` for CommonJS.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: whichTypedArray is not a function
Attempting to use `whichTypedArray` after an incorrect import, specifically `import { whichTypedArray } from 'which-typed-array';`
fix
Change your import statement to `import whichTypedArray from 'which-typed-array';` for ES Modules or `const whichTypedArray = require('which-typed-array');` for CommonJS.
ReferenceError: BigInt64Array is not defined
Attempting to create or check `BigInt64Array` or `BigUint64Array` in an environment that does not support BigInt Typed Arrays (e.g., older Node.js versions or browsers).
fix
Ensure your JavaScript environment supports BigInt Typed Arrays. If targeting older environments, wrap usage in a check: `if (typeof BigInt64Array !== 'undefined') { /* use BigInt64Array */ }`.
Upgrade
Version history
1.1.20latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
26 hits · last 30 days
node
22
OpenAI (training)
1
Resources
which-typed-array — npm install which-typed-array · libregistry