which-typed-array
Advanced tools
Comparing version
@@ -8,2 +8,12 @@ # Changelog | ||
## [v1.1.19](https://github.com/inspect-js/which-typed-array/compare/v1.1.18...v1.1.19) - 2025-03-08 | ||
### Commits | ||
- [Refactor] use `get-proto`, improve types [`e05d535`](https://github.com/inspect-js/which-typed-array/commit/e05d535fe4e4c4e674937718fe1cae90abff3606) | ||
- [Dev Deps] update `@arethetypeswrong/cli`, `@ljharb/tsconfig`, `@types/tape` [`0dade9c`](https://github.com/inspect-js/which-typed-array/commit/0dade9c4c334f37ed14083a35724eea56a496991) | ||
- [Deps] update `call-bound`, `for-each` [`490791a`](https://github.com/inspect-js/which-typed-array/commit/490791af49605390f9805660492976f86c64feb1) | ||
- [Tests] skip `npm ls` in older nodes [`f83aaca`](https://github.com/inspect-js/which-typed-array/commit/f83aaca6b6634ce795f8caf9a1e14ab15d35161c) | ||
- [Dev Deps] update `@ljharb/tsconfig` [`63c4795`](https://github.com/inspect-js/which-typed-array/commit/63c479564e5f3cb022c784ffe505673597341aab) | ||
## [v1.1.18](https://github.com/inspect-js/which-typed-array/compare/v1.1.17...v1.1.18) - 2024-12-18 | ||
@@ -10,0 +20,0 @@ |
41
index.js
@@ -8,4 +8,4 @@ 'use strict'; | ||
var gOPD = require('gopd'); | ||
var getProto = require('get-proto'); | ||
/** @type {(O: object) => string} */ | ||
var $toString = callBound('Object.prototype.toString'); | ||
@@ -18,3 +18,2 @@ var hasToStringTag = require('has-tostringtag/shams')(); | ||
var $slice = callBound('String.prototype.slice'); | ||
var getPrototypeOf = Object.getPrototypeOf; // require('getprototypeof'); | ||
@@ -31,14 +30,14 @@ /** @type {<T = unknown>(array: readonly T[], value: unknown) => number} */ | ||
/** @typedef {(receiver: import('.').TypedArray) => string | typeof Uint8Array.prototype.slice.call | typeof Uint8Array.prototype.set.call} Getter */ | ||
/** @type {{ [k in `\$${import('.').TypedArrayName}`]?: Getter } & { __proto__: null }} */ | ||
/** @typedef {import('./types').Getter} Getter */ | ||
/** @type {import('./types').Cache} */ | ||
var cache = { __proto__: null }; | ||
if (hasToStringTag && gOPD && getPrototypeOf) { | ||
if (hasToStringTag && gOPD && getProto) { | ||
forEach(typedArrays, function (typedArray) { | ||
var arr = new g[typedArray](); | ||
if (Symbol.toStringTag in arr) { | ||
var proto = getPrototypeOf(arr); | ||
if (Symbol.toStringTag in arr && getProto) { | ||
var proto = getProto(arr); | ||
// @ts-expect-error TS won't narrow inside a closure | ||
var descriptor = gOPD(proto, Symbol.toStringTag); | ||
if (!descriptor) { | ||
var superProto = getPrototypeOf(proto); | ||
if (!descriptor && proto) { | ||
var superProto = getProto(proto); | ||
// @ts-expect-error TS won't narrow inside a closure | ||
@@ -56,4 +55,8 @@ descriptor = gOPD(superProto, Symbol.toStringTag); | ||
if (fn) { | ||
// @ts-expect-error TODO: fix | ||
cache['$' + typedArray] = callBind(fn); | ||
cache[ | ||
/** @type {`$${import('.').TypedArrayName}`} */ ('$' + typedArray) | ||
] = /** @type {import('./types').BoundSlice | import('./types').BoundSet} */ ( | ||
// @ts-expect-error TODO FIXME | ||
callBind(fn) | ||
); | ||
} | ||
@@ -67,4 +70,3 @@ }); | ||
forEach( | ||
// eslint-disable-next-line no-extra-parens | ||
/** @type {Record<`\$${TypedArrayName}`, Getter>} */ /** @type {any} */ (cache), | ||
/** @type {Record<`\$${import('.').TypedArrayName}`, Getter>} */ (cache), | ||
/** @type {(getter: Getter, name: `\$${import('.').TypedArrayName}`) => void} */ | ||
@@ -74,5 +76,5 @@ function (getter, typedArray) { | ||
try { | ||
// @ts-expect-error TODO: fix | ||
// @ts-expect-error a throw is fine here | ||
if ('$' + getter(value) === typedArray) { | ||
found = $slice(typedArray, 1); | ||
found = /** @type {import('.').TypedArrayName} */ ($slice(typedArray, 1)); | ||
} | ||
@@ -90,10 +92,9 @@ } catch (e) { /**/ } | ||
forEach( | ||
// eslint-disable-next-line no-extra-parens | ||
/** @type {Record<`\$${TypedArrayName}`, Getter>} */ /** @type {any} */ (cache), | ||
/** @type {(getter: typeof cache, name: `\$${import('.').TypedArrayName}`) => void} */ function (getter, name) { | ||
/** @type {Record<`\$${import('.').TypedArrayName}`, Getter>} */(cache), | ||
/** @type {(getter: Getter, name: `\$${import('.').TypedArrayName}`) => void} */ function (getter, name) { | ||
if (!found) { | ||
try { | ||
// @ts-expect-error TODO: fix | ||
// @ts-expect-error a throw is fine here | ||
getter(value); | ||
found = $slice(name, 1); | ||
found = /** @type {import('.').TypedArrayName} */ ($slice(name, 1)); | ||
} catch (e) { /**/ } | ||
@@ -100,0 +101,0 @@ } |
{ | ||
"name": "which-typed-array", | ||
"version": "1.1.18", | ||
"version": "1.1.19", | ||
"author": { | ||
@@ -65,4 +65,5 @@ "name": "Jordan Harband", | ||
"call-bind": "^1.0.8", | ||
"call-bound": "^1.0.3", | ||
"for-each": "^0.3.3", | ||
"call-bound": "^1.0.4", | ||
"for-each": "^0.3.5", | ||
"get-proto": "^1.0.1", | ||
"gopd": "^1.2.0", | ||
@@ -72,5 +73,5 @@ "has-tostringtag": "^1.0.2" | ||
"devDependencies": { | ||
"@arethetypeswrong/cli": "^0.17.1", | ||
"@arethetypeswrong/cli": "^0.17.4", | ||
"@ljharb/eslint-config": "^21.1.1", | ||
"@ljharb/tsconfig": "^0.2.2", | ||
"@ljharb/tsconfig": "^0.3.2", | ||
"@types/call-bind": "^1.0.5", | ||
@@ -82,3 +83,3 @@ "@types/for-each": "^0.3.3", | ||
"@types/make-generator-function": "^2.0.3", | ||
"@types/tape": "^5.8.0", | ||
"@types/tape": "^5.8.1", | ||
"auto-changelog": "^2.5.0", | ||
@@ -128,5 +129,6 @@ "encoding": "^0.1.13", | ||
"ignore": [ | ||
".github/workflows" | ||
".github/workflows", | ||
"types.d.ts" | ||
] | ||
} | ||
} |
{ | ||
"extends": "@ljharb/tsconfig", | ||
"compilerOptions": { | ||
"target": "ES2021", | ||
"target": "ESNext", | ||
}, | ||
@@ -6,0 +6,0 @@ "exclude": [ |
Sorry, the diff of this file is not supported yet
43913
2.07%268
0.37%7
16.67%+ Added
Updated
Updated