@augment-vir/common 31.43.3 → 31.44.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/README.md CHANGED
@@ -5,7 +5,6 @@ A collection of augments, helpers types, functions, and classes for any JavaScri
5
5
  - Examples: [`filterObject`](https://electrovir.github.io/augment-vir/functions/filterObject.html), [`wait`](https://electrovir.github.io/augment-vir/functions/wait.html), [`getEnumValues`](https://electrovir.github.io/augment-vir/functions/getEnumValues.html)
6
6
  - Includes a colored logger implementation: [`log`](https://electrovir.github.io/augment-vir/variables/log.html)
7
7
  - Includes a SQL-select-like runtime implementation of TypeScript's `Pick`: [`selectFrom`](https://electrovir.github.io/augment-vir/functions/selectFrom-1.html)
8
- - Includes Prisma type helpers.
9
8
  - and much more...
10
9
 
11
10
  See all `@augment-vir` docs here: https://electrovir.github.io/augment-vir
@@ -15,6 +15,7 @@ export type ArrayPaginationOptions = {
15
15
  * `getPage` is `0` indexed.
16
16
  *
17
17
  * @category Array
18
+ * @category Package : @augment-vir/common
18
19
  * @example
19
20
  *
20
21
  * ```ts
@@ -51,6 +52,7 @@ export type ChunkArrayOptions = RequireExactlyOne<{
51
52
  * Split an array into multiple sub array "chunks" based on the given options.
52
53
  *
53
54
  * @category Array
55
+ * @category Package : @augment-vir/common
54
56
  * @example
55
57
  *
56
58
  * ```ts
@@ -3,6 +3,7 @@
3
3
  * `getPage` is `0` indexed.
4
4
  *
5
5
  * @category Array
6
+ * @category Package : @augment-vir/common
6
7
  * @example
7
8
  *
8
9
  * ```ts
@@ -30,6 +31,7 @@ export function getArrayPage(originalArray, options) {
30
31
  * Split an array into multiple sub array "chunks" based on the given options.
31
32
  *
32
33
  * @category Array
34
+ * @category Package : @augment-vir/common
33
35
  * @example
34
36
  *
35
37
  * ```ts
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Convert an async iterator or async iterable into an array.
3
+ *
4
+ * @category Array
5
+ * @category Package : @augment-vir/common
6
+ */
7
+ export declare function fromAsyncIterable<T>(asyncInput: AsyncIterable<T> | AsyncIterator<T>): Promise<T[]>;
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Convert an async iterator or async iterable into an array.
3
+ *
4
+ * @category Array
5
+ * @category Package : @augment-vir/common
6
+ */
7
+ export async function fromAsyncIterable(asyncInput) {
8
+ const collapsed = [];
9
+ if (isAsyncIterable(asyncInput)) {
10
+ for await (const entry of asyncInput) {
11
+ collapsed.push(entry);
12
+ }
13
+ return collapsed;
14
+ }
15
+ else if (isAsyncIterator(asyncInput)) {
16
+ for (;;) {
17
+ const { value, done } = await asyncInput.next();
18
+ if (done) {
19
+ break;
20
+ }
21
+ collapsed.push(value);
22
+ }
23
+ return collapsed;
24
+ }
25
+ else {
26
+ throw new TypeError('Input is neither AsyncIterable nor AsyncIterator.');
27
+ }
28
+ }
29
+ function isAsyncIterable(value) {
30
+ return typeof value[Symbol.asyncIterator] === 'function';
31
+ }
32
+ function isAsyncIterator(value) {
33
+ return typeof value.next === 'function';
34
+ }
package/dist/index.d.ts CHANGED
@@ -10,6 +10,7 @@ export * from './augments/array/cross-product.js';
10
10
  export * from './augments/array/ensure-array.js';
11
11
  export * from './augments/array/extract-duplicates.js';
12
12
  export * from './augments/array/filter.js';
13
+ export * from './augments/array/from-async-iterable.js';
13
14
  export * from './augments/array/repeat-array.js';
14
15
  export * from './augments/array/shuffle-array.js';
15
16
  export * from './augments/array/string-array.js';
package/dist/index.js CHANGED
@@ -10,6 +10,7 @@ export * from './augments/array/cross-product.js';
10
10
  export * from './augments/array/ensure-array.js';
11
11
  export * from './augments/array/extract-duplicates.js';
12
12
  export * from './augments/array/filter.js';
13
+ export * from './augments/array/from-async-iterable.js';
13
14
  export * from './augments/array/repeat-array.js';
14
15
  export * from './augments/array/shuffle-array.js';
15
16
  export * from './augments/array/string-array.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@augment-vir/common",
3
- "version": "31.43.3",
3
+ "version": "31.44.0",
4
4
  "description": "A collection of augments, helpers types, functions, and classes for any JavaScript environment.",
5
5
  "keywords": [
6
6
  "augment",
@@ -40,8 +40,8 @@
40
40
  "test:web": "virmator --no-deps test web"
41
41
  },
42
42
  "dependencies": {
43
- "@augment-vir/assert": "^31.43.3",
44
- "@augment-vir/core": "^31.43.3",
43
+ "@augment-vir/assert": "^31.44.0",
44
+ "@augment-vir/core": "^31.44.0",
45
45
  "@date-vir/duration": "^8.0.0",
46
46
  "ansi-styles": "^6.2.3",
47
47
  "deepcopy-esm": "^2.1.1",