{"id":15287,"library":"which-typed-array","title":"Typed Array Kind Detector","description":"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.","status":"active","version":"1.1.20","language":"javascript","source_language":"en","source_url":"git://github.com/inspect-js/which-typed-array","tags":["javascript","array","TypedArray","typed array","which","typed","Int8Array","Uint8Array","Uint8ClampedArray","typescript"],"install":[{"cmd":"npm install which-typed-array","lang":"bash","label":"npm"},{"cmd":"yarn add which-typed-array","lang":"bash","label":"yarn"},{"cmd":"pnpm add which-typed-array","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"While the README uses `require`, the library supports ESM. For modern Node.js and browser environments, prefer the ESM import.","wrong":"const whichTypedArray = require('which-typed-array');","symbol":"whichTypedArray","correct":"import whichTypedArray from 'which-typed-array';"}],"quickstart":{"code":"import whichTypedArray from 'which-typed-array';\n\nconsole.log(whichTypedArray(new Int8Array())); // 'Int8Array'\nconsole.log(whichTypedArray(new Uint8ClampedArray(10))); // 'Uint8ClampedArray'\nconsole.log(whichTypedArray(new Float64Array([1.1, 2.2]))); // 'Float64Array'\nconsole.log(whichTypedArray([])); // false\nconsole.log(whichTypedArray({})); // false\nconsole.log(whichTypedArray(42)); // false\nconsole.log(whichTypedArray(null)); // false\n\n// Example with BigInt Typed Arrays\nif (typeof BigInt64Array !== 'undefined') {\n  console.log(whichTypedArray(new BigInt64Array([1n, 2n]))); // 'BigInt64Array'\n}\n","lang":"typescript","description":"This quickstart demonstrates how to import and use `whichTypedArray` to identify various Typed Array types and distinguish them from other JavaScript values."},"warnings":[{"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]'`.","message":"This 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure you are using `import whichTypedArray from 'which-typed-array';` for ESM or `const whichTypedArray = require('which-typed-array');` for CommonJS.","message":"The 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`.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Change your import statement to `import whichTypedArray from 'which-typed-array';` for ES Modules or `const whichTypedArray = require('which-typed-array');` for CommonJS.","cause":"Attempting to use `whichTypedArray` after an incorrect import, specifically `import { whichTypedArray } from 'which-typed-array';`","error":"TypeError: whichTypedArray is not a function"},{"fix":"Ensure your JavaScript environment supports BigInt Typed Arrays. If targeting older environments, wrap usage in a check: `if (typeof BigInt64Array !== 'undefined') { /* use BigInt64Array */ }`.","cause":"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).","error":"ReferenceError: BigInt64Array is not defined"}],"ecosystem":"npm"}