@thi.ng/api 8.7.5 → 8.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**: 2023-03-27T19:05:48Z
3
+ - **Last updated**: 2023-04-19T09:28:07Z
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
+ ## [8.8.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/api@8.8.0) (2023-04-19)
13
+
14
+ #### 🚀 Features
15
+
16
+ - add typedArrayOfVec() ([39307bf](https://github.com/thi-ng/umbrella/commit/39307bf))
17
+
12
18
  ## [8.7.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/api@8.7.0) (2023-02-05)
13
19
 
14
20
  #### 🚀 Features
package/README.md CHANGED
@@ -55,7 +55,7 @@ For Node.js REPL:
55
55
  const api = await import("@thi.ng/api");
56
56
  ```
57
57
 
58
- Package sizes (brotli'd, pre-treeshake): ESM: 2.30 KB
58
+ Package sizes (brotli'd, pre-treeshake): ESM: 2.36 KB
59
59
 
60
60
  ## Dependencies
61
61
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/api",
3
- "version": "8.7.5",
3
+ "version": "8.8.0",
4
4
  "description": "Common, generic types, interfaces & mixins",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -38,11 +38,11 @@
38
38
  },
39
39
  "devDependencies": {
40
40
  "@microsoft/api-extractor": "^7.34.4",
41
- "@thi.ng/testament": "^0.3.14",
41
+ "@thi.ng/testament": "^0.3.15",
42
42
  "rimraf": "^4.4.1",
43
43
  "tools": "^0.0.1",
44
44
  "typedoc": "^0.23.28",
45
- "typescript": "^5.0.2"
45
+ "typescript": "^5.0.4"
46
46
  },
47
47
  "keywords": [
48
48
  "assert",
@@ -225,5 +225,5 @@
225
225
  "default": "./watch.js"
226
226
  }
227
227
  },
228
- "gitHead": "83b15b34326d480cbca0472b20390d4d3bbb792a\n"
228
+ "gitHead": "3a56bc490f1e68754762a503d06327b5b34ff7eb\n"
229
229
  }
package/typedarray.d.ts CHANGED
@@ -158,6 +158,32 @@ export declare function typedArray<T extends Type | GLType>(type: T, buf: ArrayB
158
158
  export declare function typedArray<T extends BigType>(type: T, length: number): BigTypedArrayTypeMap[T];
159
159
  export declare function typedArray<T extends BigType>(type: T, src: ArrayLike<bigint> | ArrayBufferLike): BigTypedArrayTypeMap[T];
160
160
  export declare function typedArray<T extends BigType>(type: T, buf: ArrayBufferLike, byteOffset: number, length?: number): BigTypedArrayTypeMap[T];
161
+ /**
162
+ * Constructs a typed array for given `type` and populates it with given vector
163
+ * values.
164
+ *
165
+ * @remarks
166
+ * The size of the array will be `data.length * stride`, where `stride` is the
167
+ * number of elements per item and defaulting to the size of the first data
168
+ * item/vector given.
169
+ *
170
+ * @example
171
+ * ```ts
172
+ * // inferred stride=2 (2d vectors)
173
+ * typedArrayOfVec("f32", [[1,2], [3,4], [-10,20]]);
174
+ * // Float32Array(6) [ 1, 2, 3, 4, -10, 20 ]
175
+ *
176
+ * // with custom stride=4
177
+ * typedArrayOfVec("f32", [[1,2], [3,4], [-10,20]], 4);
178
+ * // Float32Array(12) [ 1, 2, 0, 0, 3,4, 0, 0, -10, 20, 0, 0 ]
179
+ * ```
180
+ *
181
+ * @param type
182
+ * @param data
183
+ * @param stride
184
+ */
185
+ export declare function typedArrayOfVec<T extends Type | GLType>(type: T, data: Iterable<ArrayLike<number>>, stride?: number): TypedArrayTypeMap[T];
186
+ export declare function typedArrayOfVec<T extends BigType>(type: T, data: Iterable<ArrayLike<bigint>>, stride?: number): BigTypedArrayTypeMap[T];
161
187
  /**
162
188
  * Takes an {@link NumericArray} and returns its corresponding {@link Type} ID.
163
189
  * Standard JS arrays will default to {@link "f64"}.
package/typedarray.js CHANGED
@@ -149,6 +149,17 @@ export function typedArray(type, ...xs) {
149
149
  const ctor = BIGINT_ARRAY_CTORS[type];
150
150
  return new (ctor || TYPEDARRAY_CTORS[asNativeType(type)])(...xs);
151
151
  }
152
+ export function typedArrayOfVec(type, data, stride) {
153
+ const $data = Array.isArray(data) ? data : [...data];
154
+ if (stride === undefined)
155
+ stride = $data[0].length;
156
+ const num = $data.length;
157
+ const res = typedArray(type, num * stride);
158
+ for (let i = 0, j = 0; i < num; i++, j += stride) {
159
+ res.set($data[i], j);
160
+ }
161
+ return res;
162
+ }
152
163
  /**
153
164
  * Takes an {@link NumericArray} and returns its corresponding {@link Type} ID.
154
165
  * Standard JS arrays will default to {@link "f64"}.