@thi.ng/arrays 2.12.0 → 2.13.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2025-06-14T20:56:27Z
3
+ - **Last updated**: 2025-06-18T12:01:21Z
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,13 @@ 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.13.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/arrays@2.13.0) (2025-06-18)
15
+
16
+ #### 🚀 Features
17
+
18
+ - add filterAll() ([91791ba](https://github.com/thi-ng/umbrella/commit/91791ba))
19
+ - add docs & code example
20
+
14
21
  ## [2.12.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/arrays@2.12.0) (2025-06-14)
15
22
 
16
23
  #### 🚀 Features
package/README.md CHANGED
@@ -60,7 +60,7 @@ For Node.js REPL:
60
60
  const arr = await import("@thi.ng/arrays");
61
61
  ```
62
62
 
63
- Package sizes (brotli'd, pre-treeshake): ESM: 3.11 KB
63
+ Package sizes (brotli'd, pre-treeshake): ESM: 3.17 KB
64
64
 
65
65
  ## Dependencies
66
66
 
@@ -0,0 +1,36 @@
1
+ import type { Predicate } from "@thi.ng/api";
2
+ /**
3
+ * Similar to JS native `filter()`, but for filtering multiple arrays at once.
4
+ * All arrays are assumed to have the same length as the first. Applies given
5
+ * predicate `pred` to first array ONLY. If predicate is truthy for the current
6
+ * index, the values for that index in all arrays will be copied to their
7
+ * filtered results. Function returns result arrays as tuple.
8
+ *
9
+ * @example
10
+ * ```ts tangle:../export/filter-all.ts
11
+ * import { filterAll } from "@thi.ng/arrays";
12
+ *
13
+ * const [a, b, c] = filterAll(
14
+ * (x) => x==="a",
15
+ * // the predicate is applied to this array
16
+ * ["a", "b", "a"],
17
+ * // any number of additional arrays...
18
+ * [1, 2, 3],
19
+ * [{ id: 123 }, { id: 456 }, { id: 789 }]
20
+ * );
21
+ *
22
+ * console.log("a", a);
23
+ * // [ "a", "a" ]
24
+ *
25
+ * console.log("b", b);
26
+ * // [ 1, 3 ]
27
+ *
28
+ * console.log("c", c);
29
+ * // [{ id: 123 }, { id: 789 }]
30
+ * ```
31
+ *
32
+ * @param pred
33
+ * @param xs
34
+ */
35
+ export declare const filterAll: <A, Xs extends [A[], ...any[][]]>(pred: Predicate<A>, ...xs: Xs) => Xs;
36
+ //# sourceMappingURL=filter-all.d.ts.map
package/filter-all.js ADDED
@@ -0,0 +1,13 @@
1
+ const filterAll = (pred, ...xs) => {
2
+ const res = new Array(xs.length + 1).fill(0).map(() => []);
3
+ const a = xs[0];
4
+ for (let i = 0, n = a.length, m = xs.length; i < n; i++) {
5
+ if (pred(a[i])) {
6
+ for (let j = 0; j < m; j++) res[j].push(xs[j][i]);
7
+ }
8
+ }
9
+ return res;
10
+ };
11
+ export {
12
+ filterAll
13
+ };
package/index.d.ts CHANGED
@@ -8,6 +8,7 @@ export * from "./ends-with.js";
8
8
  export * from "./ensure-array.js";
9
9
  export * from "./ensure-iterable.js";
10
10
  export * from "./fill-range.js";
11
+ export * from "./filter-all.js";
11
12
  export * from "./find.js";
12
13
  export * from "./find-sequence.js";
13
14
  export * from "./floyd-rivest.js";
package/index.js CHANGED
@@ -8,6 +8,7 @@ export * from "./ends-with.js";
8
8
  export * from "./ensure-array.js";
9
9
  export * from "./ensure-iterable.js";
10
10
  export * from "./fill-range.js";
11
+ export * from "./filter-all.js";
11
12
  export * from "./find.js";
12
13
  export * from "./find-sequence.js";
13
14
  export * from "./floyd-rivest.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/arrays",
3
- "version": "2.12.0",
3
+ "version": "2.13.0",
4
4
  "description": "Array / Arraylike utilities",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -56,11 +56,18 @@
56
56
  "array",
57
57
  "binary",
58
58
  "distance",
59
+ "fill",
60
+ "floyd-rivest",
59
61
  "fuzzy",
60
62
  "levenshtein",
63
+ "lookup",
64
+ "permutation",
65
+ "range",
61
66
  "search",
67
+ "sequence",
62
68
  "shuffle",
63
69
  "sort",
70
+ "swap",
64
71
  "swizzle",
65
72
  "topology",
66
73
  "typescript"
@@ -109,6 +116,9 @@
109
116
  "./fill-range": {
110
117
  "default": "./fill-range.js"
111
118
  },
119
+ "./filter-all": {
120
+ "default": "./filter-all.js"
121
+ },
112
122
  "./find-sequence": {
113
123
  "default": "./find-sequence.js"
114
124
  },
@@ -177,5 +187,5 @@
177
187
  "tag": "array",
178
188
  "year": 2018
179
189
  },
180
- "gitHead": "14e994e531d32053e948768998324d443436a542\n"
190
+ "gitHead": "b076434a497b291ad33e81b1a15f6a71e2c82cc2\n"
181
191
  }