@thi.ng/arrays 2.7.20 → 2.8.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**: 2024-02-10T08:59:56Z
3
+ - **Last updated**: 2024-02-19T15:50:26Z
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.8.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/arrays@2.8.0) (2024-02-19)
13
+
14
+ #### 🚀 Features
15
+
16
+ - add blitPred1d() predicate version of blit1d() ([c13c4f9](https://github.com/thi-ng/umbrella/commit/c13c4f9))
17
+
12
18
  ## [2.7.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/arrays@2.7.0) (2023-10-27)
13
19
 
14
20
  #### 🚀 Features
package/README.md CHANGED
@@ -65,7 +65,7 @@ For Node.js REPL:
65
65
  const arrays = await import("@thi.ng/arrays");
66
66
  ```
67
67
 
68
- Package sizes (brotli'd, pre-treeshake): ESM: 2.89 KB
68
+ Package sizes (brotli'd, pre-treeshake): ESM: 2.91 KB
69
69
 
70
70
  ## Dependencies
71
71
 
package/blit.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { TypedArray } from "@thi.ng/api";
1
+ import type { Fn3, TypedArray } from "@thi.ng/api";
2
2
  /**
3
3
  * Selectively copies all non-`mask` values from `src` into `dest` starting from
4
4
  * destination position `dx`. Returns `dest`.
@@ -30,6 +30,19 @@ import type { TypedArray } from "@thi.ng/api";
30
30
  */
31
31
  export declare function blit1d<T extends TypedArray>(dest: T, dx: number, src: ArrayLike<number>, mask: number): T;
32
32
  export declare function blit1d<T>(dest: T[], dx: number, src: ArrayLike<T>, mask: T): T[];
33
+ /**
34
+ * Similar to {@link blit1d}, but uses a predicate function to
35
+ * determine/transform copied values. The predicate is called with the src, and
36
+ * dest item values and src index. The result of that function is written to the
37
+ * `dest` array. If the predicate returns `undefined`, no value will be written.
38
+ *
39
+ * @param dest
40
+ * @param dx
41
+ * @param src
42
+ * @param pred
43
+ */
44
+ export declare function blitPred1d<T extends TypedArray>(dest: T, dx: number, src: ArrayLike<number>, pred: Fn3<number, number, number, number | undefined>): T;
45
+ export declare function blitPred1d<T>(dest: T[], dx: number, src: ArrayLike<T>, pred: Fn3<T, T, number, T | undefined>): T[];
33
46
  /**
34
47
  * 2D version of {@link blit1d} (also with region clipping). Positions and sizes
35
48
  * are given as 2D vectors.
package/blit.js CHANGED
@@ -8,6 +8,16 @@ function blit1d(dest, x, src, mask) {
8
8
  }
9
9
  return dest;
10
10
  }
11
+ function blitPred1d(dest, x, src, pred) {
12
+ const [sx, sw, dx, dw] = __clip(0, src.length, x, dest.length);
13
+ if (sw < 1 || dx >= dw)
14
+ return dest;
15
+ for (let i = 0; i < sw; i++) {
16
+ const val = pred(src[sx + i], dest[dx + i], sx + i);
17
+ val !== void 0 && (dest[dx + i] = val);
18
+ }
19
+ return dest;
20
+ }
11
21
  function blit2d(dest, dpos, dsize, src, ssize, mask) {
12
22
  const [sx, sw, dx, dw] = __clip(0, ssize[0], dpos[0], dsize[0]);
13
23
  const [sy, sh, dy, dh] = __clip(0, ssize[1], dpos[1], dsize[1]);
@@ -35,5 +45,6 @@ const __clip = (sx, sw, dx, dw) => {
35
45
  };
36
46
  export {
37
47
  blit1d,
38
- blit2d
48
+ blit2d,
49
+ blitPred1d
39
50
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/arrays",
3
- "version": "2.7.20",
3
+ "version": "2.8.0",
4
4
  "description": "Array / Arraylike utilities",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -165,5 +165,5 @@
165
165
  "thi.ng": {
166
166
  "year": 2018
167
167
  },
168
- "gitHead": "e5e7d5c6ed2eadee7a91d59cbd0c86ce880ab1c5\n"
168
+ "gitHead": "ea2ec2e4f14c572bbfac00c43953a6c4033da09e\n"
169
169
  }