Socket
Socket
Sign inDemoInstall

typed-array-length

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typed-array-length - npm Package Compare versions

Comparing version 1.0.4 to 1.0.5

index.d.ts

15

CHANGELOG.md

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

## [v1.0.5](https://github.com/inspect-js/typed-array-length/compare/v1.0.4...v1.0.5) - 2024-02-20
### Commits
- add types [`df51e65`](https://github.com/inspect-js/typed-array-length/commit/df51e65a85fa6d1a98571ab30398b36ac2c981bb)
- [Refactor] use `possible-typed-array-names` for a single source of truth [`84503a3`](https://github.com/inspect-js/typed-array-length/commit/84503a3d406e8ae1cc84cf6e893cacc556be664a)
- [actions] update rebase action to use reusable workflow [`f163023`](https://github.com/inspect-js/typed-array-length/commit/f16302365bbb353b0504a41d997fa18196757c80)
- [Dev Deps] update `@ljharb/eslint-config`, `aud`, `npmignore`, `object-inspect`, `tape` [`57ca930`](https://github.com/inspect-js/typed-array-length/commit/57ca93013d607c0ac46b749d8258bb341b903567)
- [Dev Deps] update `aud`, `is-callable`, `object-inspect`, `tape` [`99343f4`](https://github.com/inspect-js/typed-array-length/commit/99343f477d68f2d53597bc0cadf93e532a498138)
- [Refactor] use `gopd` and `has-proto` [`b134a5c`](https://github.com/inspect-js/typed-array-length/commit/b134a5cc4bea1666f4195d6b6c6e97617305420f)
- [Deps] update `call-bind`, `is-typed-array` [`3b62f55`](https://github.com/inspect-js/typed-array-length/commit/3b62f55cc52da8b4c9548fb8839f0e4db222ac1b)
- [meta] add missing `engines.node` [`ff3e9f7`](https://github.com/inspect-js/typed-array-length/commit/ff3e9f7b8d72c0c2d1e9c2122a701ac454e6552c)
- [Deps] update `is-typed-array` [`877f507`](https://github.com/inspect-js/typed-array-length/commit/877f507048ece8b1db6402b56d512c7eb3337ce9)
- [meta] add `sideEffects` flag [`6e91309`](https://github.com/inspect-js/typed-array-length/commit/6e913098eaca5132a3595b0653d211ffec93f2c6)
## [v1.0.4](https://github.com/inspect-js/typed-array-length/compare/v1.0.3...v1.0.4) - 2022-05-23

@@ -10,0 +25,0 @@

48

index.js
'use strict';
// / <reference types="node" />
var callBind = require('call-bind');
var forEach = require('for-each');
var callBind = require('call-bind');
var gOPD = require('gopd');
var hasProto = require('has-proto')();
var isTypedArray = require('is-typed-array');
var typedArrays = require('possible-typed-array-names');
var typedArrays = [
'Float32Array',
'Float64Array',
'Int8Array',
'Int16Array',
'Int32Array',
'Uint8Array',
'Uint8ClampedArray',
'Uint16Array',
'Uint32Array',
'BigInt64Array',
'BigUint64Array'
];
/** @typedef {Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array} TypedArray */
/** @typedef {typeof typedArrays[number]} TypedArrayName */
/** @typedef {(value: TypedArray) => number} TypedArrayLengthGetter */
/** @type {Object.<TypedArrayName, TypedArrayLengthGetter>} */
var getters = {};
var hasProto = [].__proto__ === Array.prototype; // eslint-disable-line no-proto
var gOPD = Object.getOwnPropertyDescriptor;
var oDP = Object.defineProperty;
if (gOPD) {
var getLength = function (x) {
var getLength = /** @type {TypedArrayLengthGetter} */ function (x) {
return x.length;
};
forEach(typedArrays, function (typedArray) {
forEach(typedArrays, /** @type {(typedArray: TypedArrayName) => void} */ function (typedArray) {
var TA = global[typedArray];
// In Safari 7, Typed Array constructors are typeof object
if (typeof global[typedArray] === 'function' || typeof global[typedArray] === 'object') {
var Proto = global[typedArray].prototype;
if (typeof TA === 'function' || typeof TA === 'object') {
var Proto = TA.prototype;
// @ts-expect-error TS doesn't narrow types inside callbacks, which is weird
var descriptor = gOPD(Proto, 'length');
if (!descriptor && hasProto) {
var superProto = Proto.__proto__; // eslint-disable-line no-proto
// @ts-expect-error TS doesn't narrow types inside callbacks, which is weird
descriptor = gOPD(superProto, 'length');

@@ -43,2 +41,3 @@ }

var arr = new global[typedArray](2);
// @ts-expect-error TS doesn't narrow types inside callbacks, which is weird
descriptor = gOPD(arr, 'length');

@@ -56,5 +55,6 @@ if (descriptor && descriptor.configurable) {

/** @type {TypedArrayLengthGetter} */
var tryTypedArrays = function tryAllTypedArrays(value) {
var foundLength;
forEach(getters, function (getter) {
/** @type {number} */ var foundLength;
forEach(getters, /** @type {(getter: TypedArrayLengthGetter) => void} */ function (getter) {
if (typeof foundLength !== 'number') {

@@ -69,7 +69,7 @@ try {

});
// @ts-expect-error TS can't guarantee the above callback is invoked sync
return foundLength;
};
var isTypedArray = require('is-typed-array');
/** @type {import('.')} */
module.exports = function typedArrayLength(value) {

@@ -76,0 +76,0 @@ if (!isTypedArray(value)) {

{
"name": "typed-array-length",
"version": "1.0.4",
"version": "1.0.5",
"description": "Robustly get the length of a Typed Array",

@@ -10,2 +10,4 @@ "main": "index.js",

},
"types": "./index.d.ts",
"sideEffects": false,
"scripts": {

@@ -55,15 +57,25 @@ "prepack": "npmignore --auto --commentLines=autogenerated",

"devDependencies": {
"@ljharb/eslint-config": "^21.0.0",
"aud": "^2.0.0",
"@ljharb/eslint-config": "^21.1.0",
"@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/object-inspect": "^1.8.4",
"@types/tape": "^5.6.4",
"aud": "^2.0.4",
"auto-changelog": "^2.4.0",
"eslint": "=8.8.0",
"evalmd": "^0.0.19",
"is-callable": "^1.2.4",
"in-publish": "^2.0.1",
"is-callable": "^1.2.7",
"make-arrow-function": "^1.2.0",
"make-generator-function": "^2.0.0",
"npmignore": "^0.3.0",
"npmignore": "^0.3.1",
"nyc": "^10.3.2",
"object-inspect": "^1.12.1",
"object-inspect": "^1.13.1",
"safe-publish-latest": "^2.0.0",
"tape": "^5.5.3"
"tape": "^5.7.5",
"typescript": "next"
},

@@ -79,5 +91,8 @@ "auto-changelog": {

"dependencies": {
"call-bind": "^1.0.2",
"call-bind": "^1.0.7",
"for-each": "^0.3.3",
"is-typed-array": "^1.1.9"
"gopd": "^1.0.1",
"has-proto": "^1.0.3",
"is-typed-array": "^1.1.13",
"possible-typed-array-names": "^1.0.0"
},

@@ -91,3 +106,6 @@ "testling": {

]
},
"engines": {
"node": ">= 0.4"
}
}

@@ -10,19 +10,7 @@ 'use strict';

var inspect = require('object-inspect');
var typedArrayNames = require('possible-typed-array-names');
var typedArrayNames = [
'Int8Array',
'Uint8Array',
'Uint8ClampedArray',
'Int16Array',
'Uint16Array',
'Int32Array',
'Uint32Array',
'Float32Array',
'Float64Array',
'BigInt64Array',
'BigUint64Array'
];
test('not arrays', function (t) {
t.test('non-number/string primitives', function (st) {
// @ts-expect-error
st.equal(false, typedArrayLength(), 'undefined is not typed array');

@@ -76,2 +64,3 @@ st.equal(false, typedArrayLength(null), 'null is not typed array');

forEach(typedArrayNames, function (typedArray) {
/** @type {Int8ArrayConstructor | Uint8ArrayConstructor | Uint8ClampedArrayConstructor | Int16ArrayConstructor | Uint16ArrayConstructor | Int32ArrayConstructor | Uint32ArrayConstructor | Float32ArrayConstructor | Float64ArrayConstructor | BigInt64ArrayConstructor | BigUint64ArrayConstructor} */
var TypedArray = global[typedArray];

@@ -78,0 +67,0 @@ if (isCallable(TypedArray)) {

Sorry, the diff of this file is not supported yet

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