typed-array-length
Advanced tools
Comparing version 1.0.5 to 1.0.6
@@ -8,2 +8,11 @@ # Changelog | ||
## [v1.0.6](https://github.com/inspect-js/typed-array-length/compare/v1.0.5...v1.0.6) - 2024-03-21 | ||
### Commits | ||
- [types] vastly improve types [`9f68d36`](https://github.com/inspect-js/typed-array-length/commit/9f68d36cdc1abeb412f47e91de289b5fb903a696) | ||
- [types] use shared config [`b6b3cbc`](https://github.com/inspect-js/typed-array-length/commit/b6b3cbcaf8f4a46f5bcb77226d4cea2b3f62ffe2) | ||
- [actions] remove redundant finisher [`c69896e`](https://github.com/inspect-js/typed-array-length/commit/c69896e0d71e9f6da562b9ae0eaba415e4cbff26) | ||
- [Tests] actually check types in tests, and add attw [`e2c3f94`](https://github.com/inspect-js/typed-array-length/commit/e2c3f948bd0b898c38e1d9f63cd9702e728a7109) | ||
## [v1.0.5](https://github.com/inspect-js/typed-array-length/compare/v1.0.4...v1.0.5) - 2024-02-20 | ||
@@ -10,0 +19,0 @@ |
@@ -1,16 +0,23 @@ | ||
type TypedArray = | ||
| Int8Array | ||
| Uint8Array | ||
| Int16Array | ||
| Uint16Array | ||
| Int32Array | ||
| Uint32Array | ||
| Float32Array | ||
| Float64Array | ||
| BigInt64Array | ||
| BigUint64Array; | ||
import type names from 'possible-typed-array-names'; | ||
declare function typedArrayLength(value: TypedArray): number; | ||
declare function typedArrayLength(value: typedArrayLength.TypedArray): number; | ||
declare function typedArrayLength(value: unknown): false; | ||
declare namespace typedArrayLength { | ||
type TypedArray = | ||
| Int8Array | ||
| Uint8Array | ||
| Uint8ClampedArray | ||
| Int16Array | ||
| Uint16Array | ||
| Int32Array | ||
| Uint32Array | ||
| Float32Array | ||
| Float64Array | ||
| BigInt64Array | ||
| BigUint64Array; | ||
type TypedArrayName = typeof names[number]; | ||
} | ||
export = typedArrayLength; |
19
index.js
@@ -12,8 +12,8 @@ 'use strict'; | ||
/** @typedef {Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array} TypedArray */ | ||
/** @typedef {typeof typedArrays[number]} TypedArrayName */ | ||
/** @typedef {(value: TypedArray) => number} TypedArrayLengthGetter */ | ||
/** @typedef {(value: import('.').TypedArray) => number} TypedArrayLengthGetter */ | ||
/** @typedef {{ [k in `$${import('.').TypedArrayName}` | '__proto__']: k extends '__proto__' ? null : TypedArrayLengthGetter }} Cache */ | ||
/** @type {Object.<TypedArrayName, TypedArrayLengthGetter>} */ | ||
var getters = {}; | ||
/** @type {Cache} */ | ||
// @ts-expect-error TS doesn't seem to have a "will eventually satisfy" type | ||
var getters = { __proto__: null }; | ||
var oDP = Object.defineProperty; | ||
@@ -24,3 +24,3 @@ if (gOPD) { | ||
}; | ||
forEach(typedArrays, /** @type {(typedArray: TypedArrayName) => void} */ function (typedArray) { | ||
forEach(typedArrays, /** @type {(typedArray: import('.').TypedArrayName) => void} */ function (typedArray) { | ||
var TA = global[typedArray]; | ||
@@ -39,3 +39,4 @@ // In Safari 7, Typed Array constructors are typeof object | ||
if (descriptor && descriptor.get) { | ||
getters[typedArray] = callBind(descriptor.get); | ||
// eslint-disable-next-line no-extra-parens | ||
getters[/** @type {`$${import('.').TypedArrayName}`} */ ('$' + typedArray)] = callBind(descriptor.get); | ||
} else if (oDP) { | ||
@@ -50,3 +51,4 @@ // this is likely an engine where instances have a magic length data property | ||
if (arr.length === 2) { | ||
getters[typedArray] = getLength; | ||
// eslint-disable-next-line no-extra-parens | ||
getters[/** @type {`$${import('.').TypedArrayName}`} */ ('$' + typedArray)] = getLength; | ||
} | ||
@@ -61,2 +63,3 @@ } | ||
/** @type {number} */ var foundLength; | ||
// @ts-expect-error not sure why this won't work | ||
forEach(getters, /** @type {(getter: TypedArrayLengthGetter) => void} */ function (getter) { | ||
@@ -63,0 +66,0 @@ if (typeof foundLength !== 'number') { |
{ | ||
"name": "typed-array-length", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "Robustly get the length of a Typed Array", | ||
@@ -19,2 +19,3 @@ "main": "index.js", | ||
"lint": "eslint --ext=js,mjs .", | ||
"postlint": "tsc -p . && attw -P", | ||
"tests-only": "nyc tape 'test/**/*.js'", | ||
@@ -57,3 +58,5 @@ "test:harmony": "nyc node --harmony --es-staging test", | ||
"devDependencies": { | ||
"@arethetypeswrong/cli": "^0.15.2", | ||
"@ljharb/eslint-config": "^21.1.0", | ||
"@ljharb/tsconfig": "^0.2.0", | ||
"@types/call-bind": "^1.0.5", | ||
@@ -60,0 +63,0 @@ "@types/for-each": "^0.3.3", |
{ | ||
"extends": "@ljharb/tsconfig", | ||
"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. */ | ||
"target": "ES2021", | ||
}, | ||
"exclude": [ | ||
"coverage" | ||
] | ||
"coverage", | ||
], | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23302
25
167