Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

which-typed-array

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

which-typed-array - npm Package Compare versions

Comparing version 1.1.13 to 1.1.14

index.d.ts

9

CHANGELOG.md

@@ -8,2 +8,11 @@ # Changelog

## [v1.1.14](https://github.com/inspect-js/which-typed-array/compare/v1.1.13...v1.1.14) - 2024-02-01
### Commits
- [patch] add types [`49c4d4c`](https://github.com/inspect-js/which-typed-array/commit/49c4d4c5db9bebb8d6f8c18a01047e44eea15e17)
- [Dev Deps] update `aud`, `npmignore`, `tape` [`e5fab7b`](https://github.com/inspect-js/which-typed-array/commit/e5fab7b3dc9df2bceb88f15c3d0a2c0176cf2567)
- [Deps] update `available-typed-arrays`, `call-bind` [`97e2b44`](https://github.com/inspect-js/which-typed-array/commit/97e2b44bad85c9183f1219e28211b3abd167677c)
- [Deps] update `has-tostringtag` [`1efa8bf`](https://github.com/inspect-js/which-typed-array/commit/1efa8bf910c080c14f011aa7c645ac88bc7a7078)
## [v1.1.13](https://github.com/inspect-js/which-typed-array/compare/v1.1.12...v1.1.13) - 2023-10-19

@@ -10,0 +19,0 @@

57

index.js

@@ -18,3 +18,3 @@ 'use strict';

var $indexOf = callBound('Array.prototype.indexOf', true) || function indexOf(array, value) {
var $indexOf = callBound('Array.prototype.indexOf', true) || /** @type {(array: readonly unknown[], value: unknown) => keyof array} */ function indexOf(array, value) {
for (var i = 0; i < array.length; i += 1) {

@@ -27,2 +27,6 @@ if (array[i] === value) {

};
/** @typedef {Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array} TypedArray */
/** @typedef {'Int8Array' | 'Uint8Array' | 'Uint8ClampedArray' | 'Int16Array' | 'Uint16Array' | 'Int32Array' | 'Uint32Array' | 'Float32Array' | 'Float64Array' | 'BigInt64Array' | 'BigUint64Array'} TypedArrayName */
/** @type {{ [k in `\$${TypedArrayName}`]?: (receiver: TypedArray) => string | typeof Uint8Array.prototype.slice.call | typeof Uint8Array.prototype.set.call } & { __proto__: null }} */
var cache = { __proto__: null };

@@ -34,7 +38,10 @@ if (hasToStringTag && gOPD && getPrototypeOf) {

var proto = getPrototypeOf(arr);
// @ts-expect-error TS won't narrow inside a closure
var descriptor = gOPD(proto, Symbol.toStringTag);
if (!descriptor) {
var superProto = getPrototypeOf(proto);
// @ts-expect-error TS won't narrow inside a closure
descriptor = gOPD(superProto, Symbol.toStringTag);
}
// @ts-expect-error TODO: fix
cache['$' + typedArray] = callBind(descriptor.get);

@@ -48,2 +55,3 @@ }

if (fn) {
// @ts-expect-error TODO: fix
cache['$' + typedArray] = callBind(fn);

@@ -54,29 +62,42 @@ }

/** @type {import('.')} */
var tryTypedArrays = function tryAllTypedArrays(value) {
var found = false;
forEach(cache, function (getter, typedArray) {
if (!found) {
try {
if ('$' + getter(value) === typedArray) {
found = $slice(typedArray, 1);
}
} catch (e) { /**/ }
/** @type {ReturnType<tryAllTypedArrays>} */ var found = false;
forEach(
// eslint-disable-next-line no-extra-parens
/** @type {Record<`\$${TypedArrayName}`, typeof cache>} */ /** @type {any} */ (cache),
/** @type {(getter: typeof cache, name: `\$${TypedArrayName}`) => void} */ function (getter, typedArray) {
if (!found) {
try {
// @ts-expect-error TODO: fix
if ('$' + getter(value) === typedArray) {
found = $slice(typedArray, 1);
}
} catch (e) { /**/ }
}
}
});
);
return found;
};
/** @type {import('.')} */
var trySlices = function tryAllSlices(value) {
var found = false;
forEach(cache, function (getter, name) {
if (!found) {
try {
getter(value);
found = $slice(name, 1);
} catch (e) { /**/ }
/** @type {ReturnType<tryAllSlices>} */ var found = false;
forEach(
// eslint-disable-next-line no-extra-parens
/** @type {any} */ (cache),
/** @type {(getter: typeof cache, name: `\$${TypedArrayName}`) => void} */ function (getter, name) {
if (!found) {
try {
// @ts-expect-error TODO: fix
getter(value);
found = $slice(name, 1);
} catch (e) { /**/ }
}
}
});
);
return found;
};
/** @type {import('.')} */
module.exports = function whichTypedArray(value) {

@@ -83,0 +104,0 @@ if (!value || typeof value !== 'object') { return false; }

{
"name": "which-typed-array",
"version": "1.1.13",
"version": "1.1.14",
"author": {

@@ -22,2 +22,3 @@ "name": "Jordan Harband",

"main": "index.js",
"types": "./index.d.ts",
"sideEffects": false,

@@ -34,2 +35,3 @@ "scripts": {

"lint": "eslint --ext=js,mjs .",
"postlint": "tsc -p .",
"version": "auto-changelog && git add CHANGELOG.md",

@@ -63,11 +65,19 @@ "postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\""

"dependencies": {
"available-typed-arrays": "^1.0.5",
"call-bind": "^1.0.4",
"available-typed-arrays": "^1.0.6",
"call-bind": "^1.0.5",
"for-each": "^0.3.3",
"gopd": "^1.0.1",
"has-tostringtag": "^1.0.0"
"has-tostringtag": "^1.0.1"
},
"devDependencies": {
"@ljharb/eslint-config": "^21.1.0",
"aud": "^2.0.3",
"@types/call-bind": "^1.0.5",
"@types/for-each": "^0.3.3",
"@types/gopd": "^1.0.3",
"@types/is-callable": "^1.1.2",
"@types/make-arrow-function": "^1.2.2",
"@types/make-generator-function": "^2.0.3",
"@types/node": "^20.11.14",
"@types/tape": "^5.6.4",
"aud": "^2.0.4",
"auto-changelog": "^2.4.0",

@@ -79,6 +89,7 @@ "eslint": "=8.8.0",

"make-generator-function": "^2.0.0",
"npmignore": "^0.3.0",
"npmignore": "^0.3.1",
"nyc": "^10.3.2",
"safe-publish-latest": "^2.0.0",
"tape": "^5.7.1"
"tape": "^5.7.4",
"typescript": "^5.4.0-dev.20240131"
},

@@ -85,0 +96,0 @@ "testling": {

@@ -27,2 +27,3 @@ 'use strict';

t.test('non-number/string primitives', function (st) {
// @ts-expect-error
st.equal(false, whichTypedArray(), 'undefined is not typed array');

@@ -78,5 +79,9 @@ st.equal(false, whichTypedArray(null), 'null is not typed array');

forEach(typedArrayNames, function (typedArray) {
// @ts-expect-error TODO: fix
if (typeof global[typedArray] === 'function') {
// @ts-expect-error TODO: fix
var fakeTypedArray = [];
// @ts-expect-error TODO: fix
fakeTypedArray[Symbol.toStringTag] = typedArray;
// @ts-expect-error TODO: fix
t.equal(false, whichTypedArray(fakeTypedArray), 'faked ' + typedArray + ' is not typed array');

@@ -90,5 +95,8 @@ } else {

/** @typedef {Int8ArrayConstructor | Uint8ArrayConstructor | Uint8ClampedArrayConstructor | Int16ArrayConstructor | Uint16ArrayConstructor | Int32ArrayConstructor | Uint32ArrayConstructor | Float32ArrayConstructor | Float64ArrayConstructor | BigInt64ArrayConstructor | BigUint64ArrayConstructor} TypedArrayConstructor */
test('Typed Arrays', function (t) {
forEach(typedArrayNames, function (typedArray) {
var TypedArray = global[typedArray];
// @ts-expect-error TODO: fix
/** @type {TypedArrayConstructor} */ var TypedArray = global[typedArray];
if (isCallable(TypedArray)) {

@@ -95,0 +103,0 @@ var arr = new TypedArray(10);

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc