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-arrayVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to import and use `whichTypedArray` to identify various Typed Array types and distinguish them from other JavaScript values.
If you need to check for `ArrayBuffer` or `DataView`, use dedicated checks like `value instanceof ArrayBuffer` or `Object.prototype.toString.call(value) === '[object ArrayBuffer]'`.
Ensure you are using `import whichTypedArray from 'which-typed-array';` for ESM or `const whichTypedArray = require('which-typed-array');` for CommonJS.Change your import statement to `import whichTypedArray from 'which-typed-array';` for ES Modules or `const whichTypedArray = require('which-typed-array');` for CommonJS.Ensure your JavaScript environment supports BigInt Typed Arrays. If targeting older environments, wrap usage in a check: `if (typeof BigInt64Array !== 'undefined') { /* use BigInt64Array */ }`.No dependency data recorded yet.