@thi.ng/arrays 2.6.4 → 2.7.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 +7 -1
- package/README.md +30 -29
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +7 -4
- package/rotate.d.ts +22 -0
- package/rotate.js +45 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2023-10-
|
|
3
|
+
- **Last updated**: 2023-10-27T16:56:24Z
|
|
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.
|
|
@@ -9,6 +9,12 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
|
|
|
9
9
|
**Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
|
|
10
10
|
and/or version bumps of transitive dependencies.
|
|
11
11
|
|
|
12
|
+
## [2.7.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/arrays@2.7.0) (2023-10-27)
|
|
13
|
+
|
|
14
|
+
#### 🚀 Features
|
|
15
|
+
|
|
16
|
+
- add rotate(), rotateTyped() ([c1d322e](https://github.com/thi-ng/umbrella/commit/c1d322e))
|
|
17
|
+
|
|
12
18
|
## [2.6.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/arrays@2.6.0) (2023-10-05)
|
|
13
19
|
|
|
14
20
|
#### 🚀 Features
|
package/README.md
CHANGED
|
@@ -50,7 +50,7 @@ For Node.js REPL:
|
|
|
50
50
|
const arrays = await import("@thi.ng/arrays");
|
|
51
51
|
```
|
|
52
52
|
|
|
53
|
-
Package sizes (brotli'd, pre-treeshake): ESM: 2.
|
|
53
|
+
Package sizes (brotli'd, pre-treeshake): ESM: 2.89 KB
|
|
54
54
|
|
|
55
55
|
## Dependencies
|
|
56
56
|
|
|
@@ -81,34 +81,35 @@ A selection:
|
|
|
81
81
|
|
|
82
82
|
[Generated API docs](https://docs.thi.ng/umbrella/arrays/)
|
|
83
83
|
|
|
84
|
-
- [arrayIterator()](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays/src/iterator.ts)
|
|
85
|
-
- [argMin() / argMax()](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays/src/argmin.ts)
|
|
86
|
-
- [argSort()](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays/src/arg-sort.ts)
|
|
87
|
-
- [binarySearch()](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays/src/binary-search.ts)
|
|
88
|
-
- [bisect()](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays/src/bisect.ts)
|
|
89
|
-
- [blit1d() / blit2d()](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays/src/blit.ts)
|
|
90
|
-
- [endsWith()](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays/src/ends-with.ts)
|
|
91
|
-
- [ensureArray()](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays/src/ensure-array.ts)
|
|
92
|
-
- [ensureIterable()](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays/src/ensure-iterable.ts)
|
|
93
|
-
- [fillRange()](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays/src/fill-range.ts)
|
|
94
|
-
- [find()](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays/src/find.ts)
|
|
95
|
-
- [floydRivest()](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays/src/floyd-rivest.ts)
|
|
96
|
-
- [fuzzyMatch()](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays/src/fuzzy-match.ts)
|
|
97
|
-
- [insert()](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays/src/insert.ts)
|
|
98
|
-
- [into()](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays/src/into.ts)
|
|
99
|
-
- [isSorted()](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays/src/is-sorted.ts)
|
|
100
|
-
- [levenshtein()](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays/src/levenshtein.ts)
|
|
101
|
-
- [multiSwap()](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays/src/swap.ts)
|
|
102
|
-
- [peek()](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays/src/peek.ts)
|
|
103
|
-
- [quickSort()](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays/src/quicksort.ts)
|
|
104
|
-
- [
|
|
105
|
-
- [
|
|
106
|
-
- [
|
|
107
|
-
- [
|
|
108
|
-
- [
|
|
109
|
-
- [
|
|
110
|
-
- [
|
|
111
|
-
- [
|
|
84
|
+
- [`arrayIterator()`](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays/src/iterator.ts)
|
|
85
|
+
- [`argMin()` / argMax()](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays/src/argmin.ts)
|
|
86
|
+
- [`argSort()`](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays/src/arg-sort.ts)
|
|
87
|
+
- [`binarySearch()`](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays/src/binary-search.ts)
|
|
88
|
+
- [`bisect()`](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays/src/bisect.ts)
|
|
89
|
+
- [`blit1d()` / blit2d()](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays/src/blit.ts)
|
|
90
|
+
- [`endsWith()`](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays/src/ends-with.ts)
|
|
91
|
+
- [`ensureArray()`](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays/src/ensure-array.ts)
|
|
92
|
+
- [`ensureIterable()`](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays/src/ensure-iterable.ts)
|
|
93
|
+
- [`fillRange()`](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays/src/fill-range.ts)
|
|
94
|
+
- [`find()`](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays/src/find.ts)
|
|
95
|
+
- [`floydRivest()`](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays/src/floyd-rivest.ts)
|
|
96
|
+
- [`fuzzyMatch()`](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays/src/fuzzy-match.ts)
|
|
97
|
+
- [`insert()`](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays/src/insert.ts)
|
|
98
|
+
- [`into()`](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays/src/into.ts)
|
|
99
|
+
- [`isSorted()`](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays/src/is-sorted.ts)
|
|
100
|
+
- [`levenshtein()`](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays/src/levenshtein.ts)
|
|
101
|
+
- [`multiSwap()`](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays/src/swap.ts)
|
|
102
|
+
- [`peek()`](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays/src/peek.ts)
|
|
103
|
+
- [`quickSort()`](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays/src/quicksort.ts)
|
|
104
|
+
- [`rotate()` / `rotateTyped()`](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays/src/rotate.ts)
|
|
105
|
+
- [`selectThresholdMin()` / `selectThresholdMax()`](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays/src/threshold.ts)
|
|
106
|
+
- [`shuffle()`](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays/src/shuffle.ts) (w/ custom PRNG support)
|
|
107
|
+
- [`shuffleRange()`](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays/src/shuffle.ts) (w/ custom PRNG support)
|
|
108
|
+
- [`sortByCachedKey()`](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays/src/sort-cached.ts)
|
|
109
|
+
- [`startsWith()`](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays/src/starts-with.ts)
|
|
110
|
+
- [`swap()`](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays/src/swap.ts)
|
|
111
|
+
- [`swizzle()`](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays/src/swizzle.ts)
|
|
112
|
+
- [`topoSort()`](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays/src/topo-sort.ts)
|
|
112
113
|
|
|
113
114
|
### Binary search result predicates
|
|
114
115
|
|
package/index.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ export * from "./iterator.js";
|
|
|
18
18
|
export * from "./levenshtein.js";
|
|
19
19
|
export * from "./peek.js";
|
|
20
20
|
export * from "./quicksort.js";
|
|
21
|
+
export * from "./rotate.js";
|
|
21
22
|
export * from "./shuffle.js";
|
|
22
23
|
export * from "./sort-cached.js";
|
|
23
24
|
export * from "./starts-with.js";
|
package/index.js
CHANGED
|
@@ -18,6 +18,7 @@ export * from "./iterator.js";
|
|
|
18
18
|
export * from "./levenshtein.js";
|
|
19
19
|
export * from "./peek.js";
|
|
20
20
|
export * from "./quicksort.js";
|
|
21
|
+
export * from "./rotate.js";
|
|
21
22
|
export * from "./shuffle.js";
|
|
22
23
|
export * from "./sort-cached.js";
|
|
23
24
|
export * from "./starts-with.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/arrays",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.0",
|
|
4
4
|
"description": "Array / Arraylike utilities",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"@thi.ng/checks": "^3.4.6",
|
|
39
39
|
"@thi.ng/compare": "^2.2.1",
|
|
40
40
|
"@thi.ng/equiv": "^2.1.31",
|
|
41
|
-
"@thi.ng/errors": "^2.
|
|
42
|
-
"@thi.ng/random": "^3.6.
|
|
41
|
+
"@thi.ng/errors": "^2.4.0",
|
|
42
|
+
"@thi.ng/random": "^3.6.10"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@microsoft/api-extractor": "^7.38.0",
|
|
@@ -137,6 +137,9 @@
|
|
|
137
137
|
"./quicksort": {
|
|
138
138
|
"default": "./quicksort.js"
|
|
139
139
|
},
|
|
140
|
+
"./rotate": {
|
|
141
|
+
"default": "./rotate.js"
|
|
142
|
+
},
|
|
140
143
|
"./shuffle": {
|
|
141
144
|
"default": "./shuffle.js"
|
|
142
145
|
},
|
|
@@ -162,5 +165,5 @@
|
|
|
162
165
|
"thi.ng": {
|
|
163
166
|
"year": 2018
|
|
164
167
|
},
|
|
165
|
-
"gitHead": "
|
|
168
|
+
"gitHead": "502e8fa937677ff7bc4fbd0906d8c8b4b0b471e5\n"
|
|
166
169
|
}
|
package/rotate.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { TypedArray } from "@thi.ng/api";
|
|
2
|
+
/**
|
|
3
|
+
* Rotates array by `num` items. If `num < 0` items are rotated left (towards
|
|
4
|
+
* the beginning of the array), otherwise to the right (end). The rotation
|
|
5
|
+
* distance will be `num % buf.length`. The function is no-op if the resulting
|
|
6
|
+
* distance is zero or `buf` is empty.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* Not suitable for typed arrays. Use {@link rotateTyped} for those.
|
|
10
|
+
*
|
|
11
|
+
* @param buf
|
|
12
|
+
* @param num
|
|
13
|
+
*/
|
|
14
|
+
export declare const rotate: <T>(buf: T[], num: number) => T[];
|
|
15
|
+
/**
|
|
16
|
+
* Same as {@link rotate}, but for optimized for typed arrays!
|
|
17
|
+
*
|
|
18
|
+
* @param buf
|
|
19
|
+
* @param num
|
|
20
|
+
*/
|
|
21
|
+
export declare const rotateTyped: (buf: TypedArray, num: number) => TypedArray;
|
|
22
|
+
//# sourceMappingURL=rotate.d.ts.map
|
package/rotate.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rotates array by `num` items. If `num < 0` items are rotated left (towards
|
|
3
|
+
* the beginning of the array), otherwise to the right (end). The rotation
|
|
4
|
+
* distance will be `num % buf.length`. The function is no-op if the resulting
|
|
5
|
+
* distance is zero or `buf` is empty.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* Not suitable for typed arrays. Use {@link rotateTyped} for those.
|
|
9
|
+
*
|
|
10
|
+
* @param buf
|
|
11
|
+
* @param num
|
|
12
|
+
*/
|
|
13
|
+
export const rotate = (buf, num) => {
|
|
14
|
+
if (!(num = __distance(buf, num)))
|
|
15
|
+
return buf;
|
|
16
|
+
if (num < 0) {
|
|
17
|
+
buf.push(...buf.splice(0, -num));
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
buf.unshift(...buf.splice(-num));
|
|
21
|
+
}
|
|
22
|
+
return buf;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Same as {@link rotate}, but for optimized for typed arrays!
|
|
26
|
+
*
|
|
27
|
+
* @param buf
|
|
28
|
+
* @param num
|
|
29
|
+
*/
|
|
30
|
+
export const rotateTyped = (buf, num) => {
|
|
31
|
+
if (!(num = __distance(buf, num)))
|
|
32
|
+
return buf;
|
|
33
|
+
if (num < 0) {
|
|
34
|
+
const tmp = buf.slice(0, -num);
|
|
35
|
+
buf.copyWithin(0, -num);
|
|
36
|
+
buf.set(tmp, buf.length + num);
|
|
37
|
+
}
|
|
38
|
+
else if (num > 0) {
|
|
39
|
+
const tmp = buf.slice(buf.length - num);
|
|
40
|
+
buf.copyWithin(num, 0);
|
|
41
|
+
buf.set(tmp, 0);
|
|
42
|
+
}
|
|
43
|
+
return buf;
|
|
44
|
+
};
|
|
45
|
+
const __distance = (buf, num) => buf.length ? (num | 0) % buf.length : 0;
|