typed-array-byte-offset 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/index.d.ts +17 -0
- package/index.js +15 -3
- package/package.json +22 -9
- package/test/index.js +2 -13
- package/tsconfig.json +49 -0
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,24 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [v1.0.2](https://github.com/inspect-js/typed-array-byte-offset/compare/v1.0.1...v1.0.2) - 2024-02-20
|
|
9
|
+
|
|
10
|
+
### Commits
|
|
11
|
+
|
|
12
|
+
- add types [`9eecdd2`](https://github.com/inspect-js/typed-array-byte-offset/commit/9eecdd245b089610d6ad49ef63c9df2b58c3e8a6)
|
|
13
|
+
- [actions] skip ls check on node < 10; remove redundant finisher [`4fb4c91`](https://github.com/inspect-js/typed-array-byte-offset/commit/4fb4c912f5eb8034f4e3705b30f3f7dcc7080039)
|
|
14
|
+
- [Deps] update `available-typed-arrays`, `has-proto` [`805cee2`](https://github.com/inspect-js/typed-array-byte-offset/commit/805cee207d73e12d526ff23d2c161f38283a1ed9)
|
|
15
|
+
|
|
16
|
+
## [v1.0.1](https://github.com/inspect-js/typed-array-byte-offset/compare/v1.0.0...v1.0.1) - 2024-02-17
|
|
17
|
+
|
|
18
|
+
### Commits
|
|
19
|
+
|
|
20
|
+
- [Dev Deps] update `aud`, `npmignore`, `object-inspect`, `tape` [`ffe7494`](https://github.com/inspect-js/typed-array-byte-offset/commit/ffe7494826fbb6d6bd11c40e03619b12a4ec2266)
|
|
21
|
+
- [Deps] update `available-typed-arrays`, `call-bind`, `is-typed-array` [`3006bd7`](https://github.com/inspect-js/typed-array-byte-offset/commit/3006bd7e343d191093802473277801d12bfdc7b2)
|
|
22
|
+
- [Refactor] use `gopd` [`45827ea`](https://github.com/inspect-js/typed-array-byte-offset/commit/45827ea7d9709cb1b3a9f2313eed76b71052b9c5)
|
|
23
|
+
- [Dev Deps] update `tape` [`e33d080`](https://github.com/inspect-js/typed-array-byte-offset/commit/e33d080ef6488b5f15afe1078a9e5711d9656538)
|
|
24
|
+
- [meta] add `sideEffects` flag [`f1dc0db`](https://github.com/inspect-js/typed-array-byte-offset/commit/f1dc0db73c1c4b93c15076602a3e30353878312c)
|
|
25
|
+
|
|
8
26
|
## v1.0.0 - 2023-06-06
|
|
9
27
|
|
|
10
28
|
### Commits
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
type TypedArray =
|
|
2
|
+
| Int8Array
|
|
3
|
+
| Uint8Array
|
|
4
|
+
| Uint8ClampedArray
|
|
5
|
+
| Int16Array
|
|
6
|
+
| Uint16Array
|
|
7
|
+
| Int32Array
|
|
8
|
+
| Uint32Array
|
|
9
|
+
| Float32Array
|
|
10
|
+
| Float64Array
|
|
11
|
+
| BigInt64Array
|
|
12
|
+
| BigUint64Array;
|
|
13
|
+
|
|
14
|
+
declare function typedArrayByteOffset(value: TypedArray): number;
|
|
15
|
+
declare function typedArrayByteOffset(value: unknown): false;
|
|
16
|
+
|
|
17
|
+
export = typedArrayByteOffset;
|
package/index.js
CHANGED
|
@@ -5,12 +5,17 @@ var callBind = require('call-bind');
|
|
|
5
5
|
|
|
6
6
|
var typedArrays = require('available-typed-arrays')();
|
|
7
7
|
|
|
8
|
+
/** @typedef {Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array} TypedArray */
|
|
9
|
+
/** @typedef {(x: TypedArray) => number} ByteOffsetGetter */
|
|
10
|
+
|
|
11
|
+
/** @type {Object.<typeof typedArrays, ByteOffsetGetter>} */
|
|
8
12
|
var getters = {};
|
|
9
13
|
var hasProto = require('has-proto')();
|
|
10
14
|
|
|
11
|
-
var gOPD =
|
|
15
|
+
var gOPD = require('gopd');
|
|
12
16
|
var oDP = Object.defineProperty;
|
|
13
17
|
if (gOPD) {
|
|
18
|
+
/** @type {ByteOffsetGetter} */
|
|
14
19
|
var getByteOffset = function (x) {
|
|
15
20
|
return x.byteOffset;
|
|
16
21
|
};
|
|
@@ -18,9 +23,12 @@ if (gOPD) {
|
|
|
18
23
|
// In Safari 7, Typed Array constructors are typeof object
|
|
19
24
|
if (typeof global[typedArray] === 'function' || typeof global[typedArray] === 'object') {
|
|
20
25
|
var Proto = global[typedArray].prototype;
|
|
26
|
+
// @ts-expect-error TS can't guarantee the callback is invoked sync
|
|
21
27
|
var descriptor = gOPD(Proto, 'byteOffset');
|
|
22
28
|
if (!descriptor && hasProto) {
|
|
29
|
+
// @ts-expect-error hush, TS, every object has a dunder proto
|
|
23
30
|
var superProto = Proto.__proto__; // eslint-disable-line no-proto
|
|
31
|
+
// @ts-expect-error TS can't guarantee the callback is invoked sync
|
|
24
32
|
descriptor = gOPD(superProto, 'byteOffset');
|
|
25
33
|
}
|
|
26
34
|
// Opera 12.16 has a magic byteOffset data property on instances AND on Proto
|
|
@@ -29,6 +37,7 @@ if (gOPD) {
|
|
|
29
37
|
} else if (oDP) {
|
|
30
38
|
// this is likely an engine where instances have a magic byteOffset data property
|
|
31
39
|
var arr = new global[typedArray](2);
|
|
40
|
+
// @ts-expect-error TS can't guarantee the callback is invoked sync
|
|
32
41
|
descriptor = gOPD(arr, 'byteOffset');
|
|
33
42
|
if (descriptor && descriptor.configurable) {
|
|
34
43
|
oDP(arr, 'length', { value: 3 });
|
|
@@ -41,9 +50,10 @@ if (gOPD) {
|
|
|
41
50
|
});
|
|
42
51
|
}
|
|
43
52
|
|
|
53
|
+
/** @type {ByteOffsetGetter} */
|
|
44
54
|
var tryTypedArrays = function tryAllTypedArrays(value) {
|
|
45
|
-
var foundOffset;
|
|
46
|
-
forEach(getters, function (getter) {
|
|
55
|
+
/** @type {number} */ var foundOffset;
|
|
56
|
+
forEach(getters, /** @type {(getter: ByteOffsetGetter) => void} */ function (getter) {
|
|
47
57
|
if (typeof foundOffset !== 'number') {
|
|
48
58
|
try {
|
|
49
59
|
var offset = getter(value);
|
|
@@ -53,11 +63,13 @@ var tryTypedArrays = function tryAllTypedArrays(value) {
|
|
|
53
63
|
} catch (e) {}
|
|
54
64
|
}
|
|
55
65
|
});
|
|
66
|
+
// @ts-expect-error TS can't guarantee the callback is invoked sync
|
|
56
67
|
return foundOffset;
|
|
57
68
|
};
|
|
58
69
|
|
|
59
70
|
var isTypedArray = require('is-typed-array');
|
|
60
71
|
|
|
72
|
+
/** @type {import('.')} */
|
|
61
73
|
module.exports = function typedArrayByteOffset(value) {
|
|
62
74
|
if (!isTypedArray(value)) {
|
|
63
75
|
return false;
|
package/package.json
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typed-array-byte-offset",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Robustly get the byte offset of a Typed Array",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": "./index.js",
|
|
8
8
|
"./package.json": "./package.json"
|
|
9
9
|
},
|
|
10
|
+
"types": "./index.d.ts",
|
|
11
|
+
"sideEffects": false,
|
|
10
12
|
"scripts": {
|
|
11
13
|
"prepack": "npmignore --auto --commentLines=autogenerated",
|
|
12
14
|
"prepublishOnly": "safe-publish-latest",
|
|
@@ -54,15 +56,24 @@
|
|
|
54
56
|
},
|
|
55
57
|
"homepage": "https://github.com/inspect-js/typed-array-byte-offset#readme",
|
|
56
58
|
"dependencies": {
|
|
57
|
-
"available-typed-arrays": "^1.0.
|
|
58
|
-
"call-bind": "^1.0.
|
|
59
|
+
"available-typed-arrays": "^1.0.7",
|
|
60
|
+
"call-bind": "^1.0.7",
|
|
59
61
|
"for-each": "^0.3.3",
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
+
"gopd": "^1.0.1",
|
|
63
|
+
"has-proto": "^1.0.3",
|
|
64
|
+
"is-typed-array": "^1.1.13"
|
|
62
65
|
},
|
|
63
66
|
"devDependencies": {
|
|
64
67
|
"@ljharb/eslint-config": "^21.1.0",
|
|
65
|
-
"
|
|
68
|
+
"@types/call-bind": "^1.0.5",
|
|
69
|
+
"@types/for-each": "^0.3.3",
|
|
70
|
+
"@types/gopd": "^1.0.3",
|
|
71
|
+
"@types/is-callable": "^1.1.2",
|
|
72
|
+
"@types/make-arrow-function": "^1.2.2",
|
|
73
|
+
"@types/make-generator-function": "^2.0.3",
|
|
74
|
+
"@types/object-inspect": "^1.8.4",
|
|
75
|
+
"@types/tape": "^5.6.4",
|
|
76
|
+
"aud": "^2.0.4",
|
|
66
77
|
"auto-changelog": "^2.4.0",
|
|
67
78
|
"eslint": "=8.8.0",
|
|
68
79
|
"evalmd": "^0.0.19",
|
|
@@ -70,11 +81,13 @@
|
|
|
70
81
|
"is-callable": "^1.2.7",
|
|
71
82
|
"make-arrow-function": "^1.2.0",
|
|
72
83
|
"make-generator-function": "^2.0.0",
|
|
73
|
-
"npmignore": "^0.3.
|
|
84
|
+
"npmignore": "^0.3.1",
|
|
74
85
|
"nyc": "^10.3.2",
|
|
75
|
-
"object-inspect": "^1.
|
|
86
|
+
"object-inspect": "^1.13.1",
|
|
87
|
+
"possible-typed-array-names": "^1.0.0",
|
|
76
88
|
"safe-publish-latest": "^2.0.0",
|
|
77
|
-
"tape": "^5.
|
|
89
|
+
"tape": "^5.7.5",
|
|
90
|
+
"typescript": "^5.4.0-dev.20240219"
|
|
78
91
|
},
|
|
79
92
|
"engines": {
|
|
80
93
|
"node": ">= 0.4"
|
package/test/index.js
CHANGED
|
@@ -8,22 +8,11 @@ var arrowFn = require('make-arrow-function')();
|
|
|
8
8
|
var forEach = require('for-each');
|
|
9
9
|
var inspect = require('object-inspect');
|
|
10
10
|
|
|
11
|
-
var typedArrayNames =
|
|
12
|
-
'Int8Array',
|
|
13
|
-
'Uint8Array',
|
|
14
|
-
'Uint8ClampedArray',
|
|
15
|
-
'Int16Array',
|
|
16
|
-
'Uint16Array',
|
|
17
|
-
'Int32Array',
|
|
18
|
-
'Uint32Array',
|
|
19
|
-
'Float32Array',
|
|
20
|
-
'Float64Array',
|
|
21
|
-
'BigInt64Array',
|
|
22
|
-
'BigUint64Array'
|
|
23
|
-
];
|
|
11
|
+
var typedArrayNames = require('possible-typed-array-names');
|
|
24
12
|
|
|
25
13
|
test('not arrays', function (t) {
|
|
26
14
|
t.test('non-number/string primitives', function (st) {
|
|
15
|
+
// @ts-expect-error
|
|
27
16
|
st.equal(false, typedArrayByteOffset(), 'undefined is not typed array');
|
|
28
17
|
st.equal(false, typedArrayByteOffset(null), 'null is not typed array');
|
|
29
18
|
st.equal(false, typedArrayByteOffset(false), 'false is not typed array');
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
/* Visit https://aka.ms/tsconfig to read more about this file */
|
|
4
|
+
|
|
5
|
+
/* Projects */
|
|
6
|
+
|
|
7
|
+
/* Language and Environment */
|
|
8
|
+
"target": "ESNext", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
|
|
9
|
+
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
|
10
|
+
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
|
|
11
|
+
"useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
|
|
12
|
+
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
|
|
13
|
+
|
|
14
|
+
/* Modules */
|
|
15
|
+
"module": "commonjs", /* Specify what module code is generated. */
|
|
16
|
+
// "rootDir": "./", /* Specify the root folder within your source files. */
|
|
17
|
+
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
|
|
18
|
+
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
|
19
|
+
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
|
20
|
+
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
|
21
|
+
"typeRoots": ["types"], /* Specify multiple folders that act like './node_modules/@types'. */
|
|
22
|
+
"resolveJsonModule": true, /* Enable importing .json files. */
|
|
23
|
+
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
|
|
24
|
+
|
|
25
|
+
/* JavaScript Support */
|
|
26
|
+
"allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
|
|
27
|
+
"checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
|
|
28
|
+
"maxNodeModuleJsDepth": 0, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
|
|
29
|
+
|
|
30
|
+
/* Emit */
|
|
31
|
+
"declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
|
|
32
|
+
"declarationMap": true, /* Create sourcemaps for d.ts files. */
|
|
33
|
+
"noEmit": true, /* Disable emitting files from a compilation. */
|
|
34
|
+
|
|
35
|
+
/* Interop Constraints */
|
|
36
|
+
"allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
|
|
37
|
+
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
|
|
38
|
+
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
|
|
39
|
+
|
|
40
|
+
/* Type Checking */
|
|
41
|
+
"strict": true, /* Enable all strict type-checking options. */
|
|
42
|
+
|
|
43
|
+
/* Completeness */
|
|
44
|
+
//"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
|
45
|
+
},
|
|
46
|
+
"exclude": [
|
|
47
|
+
"coverage"
|
|
48
|
+
]
|
|
49
|
+
}
|