typed-array-byte-length
Advanced tools
+17
| type TypedArray = | ||
| | Int8Array | ||
| | Uint8Array | ||
| | Uint8ClampedArray | ||
| | Int16Array | ||
| | Uint16Array | ||
| | Int32Array | ||
| | Uint32Array | ||
| | Float32Array | ||
| | Float64Array | ||
| | BigInt64Array | ||
| | BigUint64Array; | ||
| declare function typedArrayByteLength(value: TypedArray): number; | ||
| declare function typedArrayByteLength(value: unknown): false; | ||
| export = typedArrayByteLength; |
| { | ||
| "compilerOptions": { | ||
| /* Visit https://aka.ms/tsconfig to read more about this file */ | ||
| /* Projects */ | ||
| /* Language and Environment */ | ||
| "target": "ESNext", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ | ||
| // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ | ||
| // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ | ||
| "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ | ||
| // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ | ||
| /* Modules */ | ||
| "module": "commonjs", /* Specify what module code is generated. */ | ||
| // "rootDir": "./", /* Specify the root folder within your source files. */ | ||
| // "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */ | ||
| // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ | ||
| // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ | ||
| // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ | ||
| "typeRoots": ["types"], /* Specify multiple folders that act like './node_modules/@types'. */ | ||
| "resolveJsonModule": true, /* Enable importing .json files. */ | ||
| // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */ | ||
| /* JavaScript Support */ | ||
| "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */ | ||
| "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ | ||
| "maxNodeModuleJsDepth": 0, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */ | ||
| /* Emit */ | ||
| "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ | ||
| "declarationMap": true, /* Create sourcemaps for d.ts files. */ | ||
| "noEmit": true, /* Disable emitting files from a compilation. */ | ||
| /* Interop Constraints */ | ||
| "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ | ||
| "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ | ||
| "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ | ||
| /* Type Checking */ | ||
| "strict": true, /* Enable all strict type-checking options. */ | ||
| /* Completeness */ | ||
| //"skipLibCheck": true /* Skip type checking all .d.ts files. */ | ||
| }, | ||
| "exclude": [ | ||
| "coverage" | ||
| ] | ||
| } |
+11
-0
@@ -8,2 +8,13 @@ # Changelog | ||
| ## [v1.0.1](https://github.com/inspect-js/typed-array-byte-length/compare/v1.0.0...v1.0.1) - 2024-02-20 | ||
| ### Commits | ||
| - add types [`3144671`](https://github.com/inspect-js/typed-array-byte-length/commit/3144671ca4035136c558a107ce61af255ae3e858) | ||
| - [actions] skip ls check on node < 10; remove redundant finisher [`0f83947`](https://github.com/inspect-js/typed-array-byte-length/commit/0f83947bfe641fd87253330a6a83e8b7571e5c6a) | ||
| - [Refactor] use `gopd` [`507b948`](https://github.com/inspect-js/typed-array-byte-length/commit/507b948f9e754ad5b0888a15558448ec879c04c4) | ||
| - [Dev Deps] update `aud`, `available-typed-arrays`, `npmignore`, `object-inspect`, `tape` [`aba282d`](https://github.com/inspect-js/typed-array-byte-length/commit/aba282da3a3e16f648ceb4bc4f174cf4942a94e9) | ||
| - [Deps] update `call-bind`, `has-proto`, `is-typed-array` [`acfe4a9`](https://github.com/inspect-js/typed-array-byte-length/commit/acfe4a9081f35cea3b450b07a4736e1ab037a708) | ||
| - [meta] add `sideEffects` flag [`063a8a7`](https://github.com/inspect-js/typed-array-byte-length/commit/063a8a7ec8c134a012903531beccfc4418f701d0) | ||
| ## v1.0.0 - 2023-07-14 | ||
@@ -10,0 +21,0 @@ |
+19
-7
| 'use strict'; | ||
| 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('available-typed-arrays')(); | ||
| /** @typedef {Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array} TypedArray */ | ||
| /** @typedef {import('possible-typed-array-names')[number]} TypedArrayNames */ | ||
| /** @typedef {(value: TypedArray) => number} Getter */ | ||
| /** @type {Object.<TypedArrayNames, Getter>} */ | ||
| var getters = {}; | ||
| var hasProto = require('has-proto')(); | ||
| var gOPD = Object.getOwnPropertyDescriptor; | ||
| var oDP = Object.defineProperty; | ||
| if (gOPD) { | ||
| /** @type {Getter} */ | ||
| var getByteLength = function (x) { | ||
@@ -21,5 +28,8 @@ return x.byteLength; | ||
| var Proto = global[typedArray].prototype; | ||
| // @ts-expect-error TS doesn't narrow properly inside callbacks | ||
| var descriptor = gOPD(Proto, 'byteLength'); | ||
| if (!descriptor && hasProto) { | ||
| // @ts-expect-error hush, TS, every object has a dunder proto | ||
| var superProto = Proto.__proto__; // eslint-disable-line no-proto | ||
| // @ts-expect-error TS doesn't narrow properly inside callbacks | ||
| descriptor = gOPD(superProto, 'byteLength'); | ||
@@ -33,2 +43,3 @@ } | ||
| var arr = new global[typedArray](2); | ||
| // @ts-expect-error TS doesn't narrow properly inside callbacks | ||
| descriptor = gOPD(arr, 'byteLength'); | ||
@@ -46,5 +57,6 @@ if (descriptor && descriptor.configurable) { | ||
| /** @type {Getter} */ | ||
| var tryTypedArrays = function tryAllTypedArrays(value) { | ||
| var foundByteLength; | ||
| forEach(getters, function (getter) { | ||
| /** @type {number} */ var foundByteLength; | ||
| forEach(getters, /** @type {(getter: Getter) => void} */ function (getter) { | ||
| if (typeof foundByteLength !== 'number') { | ||
@@ -59,7 +71,7 @@ try { | ||
| }); | ||
| // @ts-expect-error TS can't guarantee the callback is invoked sync | ||
| return foundByteLength; | ||
| }; | ||
| var isTypedArray = require('is-typed-array'); | ||
| /** @type {import('.')} */ | ||
| module.exports = function typedArrayByteLength(value) { | ||
@@ -66,0 +78,0 @@ if (!isTypedArray(value)) { |
+22
-9
| { | ||
| "name": "typed-array-byte-length", | ||
| "version": "1.0.0", | ||
| "version": "1.0.1", | ||
| "description": "Robustly get the byte length of a Typed Array", | ||
@@ -10,2 +10,4 @@ "main": "index.js", | ||
| }, | ||
| "types": "./index.d.ts", | ||
| "sideEffects": false, | ||
| "scripts": { | ||
@@ -18,2 +20,3 @@ "prepack": "npmignore --auto --commentLines=autogenerated", | ||
| "lint": "eslint --ext=js,mjs .", | ||
| "postlint": "tsc -p .", | ||
| "tests-only": "nyc tape 'test/**/*.js'", | ||
@@ -59,12 +62,21 @@ "test": "npm run tests-only", | ||
| "dependencies": { | ||
| "call-bind": "^1.0.2", | ||
| "call-bind": "^1.0.7", | ||
| "for-each": "^0.3.3", | ||
| "has-proto": "^1.0.1", | ||
| "is-typed-array": "^1.1.10" | ||
| "gopd": "^1.0.1", | ||
| "has-proto": "^1.0.3", | ||
| "is-typed-array": "^1.1.13" | ||
| }, | ||
| "devDependencies": { | ||
| "@ljharb/eslint-config": "^21.1.0", | ||
| "aud": "^2.0.2", | ||
| "@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", | ||
| "available-typed-arrays": "^1.0.5", | ||
| "available-typed-arrays": "^1.0.7", | ||
| "eslint": "=8.8.0", | ||
@@ -76,7 +88,8 @@ "evalmd": "^0.0.19", | ||
| "make-generator-function": "^2.0.0", | ||
| "npmignore": "^0.3.0", | ||
| "npmignore": "^0.3.1", | ||
| "nyc": "^10.3.2", | ||
| "object-inspect": "^1.12.3", | ||
| "object-inspect": "^1.13.1", | ||
| "safe-publish-latest": "^2.0.0", | ||
| "tape": "^5.6.3" | ||
| "tape": "^5.7.5", | ||
| "typescript": "next" | ||
| }, | ||
@@ -83,0 +96,0 @@ "engines": { |
+1
-0
@@ -14,2 +14,3 @@ 'use strict'; | ||
| t.test('non-number/string primitives', function (st) { | ||
| // @ts-expect-error | ||
| st.equal(false, typedArrayByteLength(), 'undefined is not typed array'); | ||
@@ -16,0 +17,0 @@ st.equal(false, typedArrayByteLength(null), 'null is not typed array'); |
20047
46.21%11
22.22%194
53.97%5
25%24
60%+ Added
Updated
Updated
Updated