@thi.ng/arrays 2.11.2 → 2.12.0
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 +11 -1
- package/README.md +1 -1
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/lookup.d.ts +29 -0
- package/lookup.js +7 -0
- package/package.json +5 -2
- package/swizzle.js +3 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2025-06-
|
|
3
|
+
- **Last updated**: 2025-06-14T20:56:27Z
|
|
4
4
|
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
|
|
5
5
|
|
|
6
6
|
All notable changes to this project will be documented in this file.
|
|
@@ -11,6 +11,16 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
|
|
|
11
11
|
**Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
|
|
12
12
|
and/or version bumps of transitive dependencies.
|
|
13
13
|
|
|
14
|
+
## [2.12.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/arrays@2.12.0) (2025-06-14)
|
|
15
|
+
|
|
16
|
+
#### 🚀 Features
|
|
17
|
+
|
|
18
|
+
- add lookup() / lookupUnsafe() fns ([deb2b37](https://github.com/thi-ng/umbrella/commit/deb2b37))
|
|
19
|
+
|
|
20
|
+
#### ♻️ Refactoring
|
|
21
|
+
|
|
22
|
+
- minor update swizzle() ([84d3aba](https://github.com/thi-ng/umbrella/commit/84d3aba))
|
|
23
|
+
|
|
14
24
|
## [2.11.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/arrays@2.11.0) (2025-04-30)
|
|
15
25
|
|
|
16
26
|
#### 🚀 Features
|
package/README.md
CHANGED
package/index.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export * from "./insert.js";
|
|
|
17
17
|
export * from "./into.js";
|
|
18
18
|
export * from "./iterator.js";
|
|
19
19
|
export * from "./levenshtein.js";
|
|
20
|
+
export * from "./lookup.js";
|
|
20
21
|
export * from "./peek.js";
|
|
21
22
|
export * from "./permutation.js";
|
|
22
23
|
export * from "./quicksort.js";
|
package/index.js
CHANGED
|
@@ -17,6 +17,7 @@ export * from "./insert.js";
|
|
|
17
17
|
export * from "./into.js";
|
|
18
18
|
export * from "./iterator.js";
|
|
19
19
|
export * from "./levenshtein.js";
|
|
20
|
+
export * from "./lookup.js";
|
|
20
21
|
export * from "./peek.js";
|
|
21
22
|
export * from "./permutation.js";
|
|
22
23
|
export * from "./quicksort.js";
|
package/lookup.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Similar to {@link swizzle}, but immediate and bounds-checked. Takes an array
|
|
3
|
+
* of `table` values and an array of indices `ids`. Returns an array of
|
|
4
|
+
* looked-up values for given IDs, ensuring each index is valid (otherwise
|
|
5
|
+
* throws an error).
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts tangle:../export/lookup.ts
|
|
9
|
+
* import { lookup } from "@thi.ng/arrays";
|
|
10
|
+
*
|
|
11
|
+
* console.log(lookup([10,20,30], [2,2,0,1,1]));
|
|
12
|
+
* // [30, 30, 10, 20, 20]
|
|
13
|
+
*
|
|
14
|
+
* console.log(lookup([10,20,30], [3]));
|
|
15
|
+
* // error: index out of bounds: 3
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @param table
|
|
19
|
+
* @param ids
|
|
20
|
+
*/
|
|
21
|
+
export declare const lookup: <T>(table: ArrayLike<T>, ids: number[]) => T[];
|
|
22
|
+
/**
|
|
23
|
+
* Non-bounds-checked version of {@link lookup}.
|
|
24
|
+
*
|
|
25
|
+
* @param table
|
|
26
|
+
* @param ids
|
|
27
|
+
*/
|
|
28
|
+
export declare const lookupUnsafe: <T>(table: ArrayLike<T>, ids: number[]) => T[];
|
|
29
|
+
//# sourceMappingURL=lookup.d.ts.map
|
package/lookup.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/arrays",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.12.0",
|
|
4
4
|
"description": "Array / Arraylike utilities",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -136,6 +136,9 @@
|
|
|
136
136
|
"./levenshtein": {
|
|
137
137
|
"default": "./levenshtein.js"
|
|
138
138
|
},
|
|
139
|
+
"./lookup": {
|
|
140
|
+
"default": "./lookup.js"
|
|
141
|
+
},
|
|
139
142
|
"./peek": {
|
|
140
143
|
"default": "./peek.js"
|
|
141
144
|
},
|
|
@@ -174,5 +177,5 @@
|
|
|
174
177
|
"tag": "array",
|
|
175
178
|
"year": 2018
|
|
176
179
|
},
|
|
177
|
-
"gitHead": "
|
|
180
|
+
"gitHead": "14e994e531d32053e948768998324d443436a542\n"
|
|
178
181
|
}
|
package/swizzle.js
CHANGED
|
@@ -21,10 +21,9 @@ const swizzle = (order) => {
|
|
|
21
21
|
return (x) => [x[a], x[b], x[c], x[d], x[e], x[f], x[g], x[h]];
|
|
22
22
|
default:
|
|
23
23
|
return (x) => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
24
|
+
let n = order.length;
|
|
25
|
+
const res = new Array(n);
|
|
26
|
+
for (; n-- > 0; ) res[n] = x[order[n]];
|
|
28
27
|
return res;
|
|
29
28
|
};
|
|
30
29
|
}
|