spliterator 6.2.0 → 6.3.1

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.
Files changed (162) hide show
  1. package/out/lib/core/AsyncSpliterator.d.ts +1 -1
  2. package/out/lib/core/AsyncSpliterator.d.ts.map +1 -1
  3. package/out/lib/core/AsyncSpliterator.js +2 -2
  4. package/out/lib/core/AsyncSpliterator.js.map +1 -1
  5. package/out/lib/core/SlidingWindow.d.ts +1 -1
  6. package/out/lib/core/SlidingWindow.d.ts.map +1 -1
  7. package/out/lib/core/SlidingWindow.js.map +1 -1
  8. package/out/lib/core/Spliterator.d.ts +1 -1
  9. package/out/lib/core/Spliterator.d.ts.map +1 -1
  10. package/out/lib/core/Spliterator.js +1 -1
  11. package/out/lib/core/Spliterator.js.map +1 -1
  12. package/out/lib/formats/CSVSpliterator.d.ts +2 -2
  13. package/out/lib/formats/CSVSpliterator.d.ts.map +1 -1
  14. package/out/lib/formats/CSVSpliterator.js +92 -1
  15. package/out/lib/formats/CSVSpliterator.js.map +1 -1
  16. package/out/lib/formats/XLSXSpliterator.d.ts +1 -1
  17. package/out/lib/formats/XLSXSpliterator.d.ts.map +1 -1
  18. package/package.json +2 -3
  19. package/out/lib/AsyncSequence.d.ts +0 -180
  20. package/out/lib/AsyncSequence.d.ts.map +0 -1
  21. package/out/lib/AsyncSequence.js +0 -432
  22. package/out/lib/AsyncSequence.js.map +0 -1
  23. package/out/lib/AsyncSpliterator.d.ts +0 -227
  24. package/out/lib/AsyncSpliterator.d.ts.map +0 -1
  25. package/out/lib/AsyncSpliterator.js +0 -510
  26. package/out/lib/AsyncSpliterator.js.map +0 -1
  27. package/out/lib/BufferController.d.ts +0 -77
  28. package/out/lib/BufferController.d.ts.map +0 -1
  29. package/out/lib/BufferController.js +0 -118
  30. package/out/lib/BufferController.js.map +0 -1
  31. package/out/lib/CSVSpliterator.d.ts +0 -131
  32. package/out/lib/CSVSpliterator.d.ts.map +0 -1
  33. package/out/lib/CSVSpliterator.js +0 -172
  34. package/out/lib/CSVSpliterator.js.map +0 -1
  35. package/out/lib/CharacterSequence.d.ts +0 -72
  36. package/out/lib/CharacterSequence.d.ts.map +0 -1
  37. package/out/lib/CharacterSequence.js +0 -347
  38. package/out/lib/CharacterSequence.js.map +0 -1
  39. package/out/lib/CompositeDataView.d.ts +0 -111
  40. package/out/lib/CompositeDataView.d.ts.map +0 -1
  41. package/out/lib/CompositeDataView.js +0 -241
  42. package/out/lib/CompositeDataView.js.map +0 -1
  43. package/out/lib/IndexQueue.d.ts +0 -48
  44. package/out/lib/IndexQueue.d.ts.map +0 -1
  45. package/out/lib/IndexQueue.js +0 -111
  46. package/out/lib/IndexQueue.js.map +0 -1
  47. package/out/lib/JSONSpliterator.d.ts +0 -44
  48. package/out/lib/JSONSpliterator.d.ts.map +0 -1
  49. package/out/lib/JSONSpliterator.js +0 -77
  50. package/out/lib/JSONSpliterator.js.map +0 -1
  51. package/out/lib/PSVSpliterator.d.ts +0 -21
  52. package/out/lib/PSVSpliterator.d.ts.map +0 -1
  53. package/out/lib/PSVSpliterator.js +0 -22
  54. package/out/lib/PSVSpliterator.js.map +0 -1
  55. package/out/lib/SlidingWindow.d.ts +0 -47
  56. package/out/lib/SlidingWindow.d.ts.map +0 -1
  57. package/out/lib/SlidingWindow.js +0 -63
  58. package/out/lib/SlidingWindow.js.map +0 -1
  59. package/out/lib/Spliterator.d.ts +0 -96
  60. package/out/lib/Spliterator.d.ts.map +0 -1
  61. package/out/lib/Spliterator.js +0 -330
  62. package/out/lib/Spliterator.js.map +0 -1
  63. package/out/lib/TSVSpliterator.d.ts +0 -21
  64. package/out/lib/TSVSpliterator.d.ts.map +0 -1
  65. package/out/lib/TSVSpliterator.js +0 -22
  66. package/out/lib/TSVSpliterator.js.map +0 -1
  67. package/out/lib/TextSpliterator.d.ts +0 -53
  68. package/out/lib/TextSpliterator.d.ts.map +0 -1
  69. package/out/lib/TextSpliterator.js +0 -67
  70. package/out/lib/TextSpliterator.js.map +0 -1
  71. package/out/lib/XLSXSpliterator.d.ts +0 -143
  72. package/out/lib/XLSXSpliterator.d.ts.map +0 -1
  73. package/out/lib/XLSXSpliterator.js +0 -161
  74. package/out/lib/XLSXSpliterator.js.map +0 -1
  75. package/out/lib/adaptive-source.d.ts +0 -39
  76. package/out/lib/adaptive-source.d.ts.map +0 -1
  77. package/out/lib/adaptive-source.js +0 -95
  78. package/out/lib/adaptive-source.js.map +0 -1
  79. package/out/lib/casing.d.ts +0 -27
  80. package/out/lib/casing.d.ts.map +0 -1
  81. package/out/lib/casing.js +0 -68
  82. package/out/lib/casing.js.map +0 -1
  83. package/out/lib/chunks.d.ts +0 -20
  84. package/out/lib/chunks.d.ts.map +0 -1
  85. package/out/lib/chunks.js +0 -36
  86. package/out/lib/chunks.js.map +0 -1
  87. package/out/lib/merge-async-iterators.d.ts +0 -12
  88. package/out/lib/merge-async-iterators.d.ts.map +0 -1
  89. package/out/lib/merge-async-iterators.js +0 -39
  90. package/out/lib/merge-async-iterators.js.map +0 -1
  91. package/out/lib/parallel-map-runtime.d.ts +0 -22
  92. package/out/lib/parallel-map-runtime.d.ts.map +0 -1
  93. package/out/lib/parallel-map-runtime.js +0 -60
  94. package/out/lib/parallel-map-runtime.js.map +0 -1
  95. package/out/lib/parallel-map-worker-entry.d.ts +0 -11
  96. package/out/lib/parallel-map-worker-entry.d.ts.map +0 -1
  97. package/out/lib/parallel-map-worker-entry.js +0 -41
  98. package/out/lib/parallel-map-worker-entry.js.map +0 -1
  99. package/out/lib/parallel-map-workers.d.ts +0 -57
  100. package/out/lib/parallel-map-workers.d.ts.map +0 -1
  101. package/out/lib/parallel-map-workers.js +0 -82
  102. package/out/lib/parallel-map-workers.js.map +0 -1
  103. package/out/lib/parallel-map.d.ts +0 -28
  104. package/out/lib/parallel-map.d.ts.map +0 -1
  105. package/out/lib/parallel-map.js +0 -30
  106. package/out/lib/parallel-map.js.map +0 -1
  107. package/out/lib/pivot.d.ts +0 -30
  108. package/out/lib/pivot.d.ts.map +0 -1
  109. package/out/lib/pivot.js +0 -47
  110. package/out/lib/pivot.js.map +0 -1
  111. package/out/lib/row-emitters.d.ts +0 -35
  112. package/out/lib/row-emitters.d.ts.map +0 -1
  113. package/out/lib/row-emitters.js +0 -50
  114. package/out/lib/row-emitters.js.map +0 -1
  115. package/out/lib/segment-runtime.d.ts +0 -27
  116. package/out/lib/segment-runtime.d.ts.map +0 -1
  117. package/out/lib/segment-runtime.js +0 -41
  118. package/out/lib/segment-runtime.js.map +0 -1
  119. package/out/lib/segment-worker-entry.d.ts +0 -10
  120. package/out/lib/segment-worker-entry.d.ts.map +0 -1
  121. package/out/lib/segment-worker-entry.js +0 -59
  122. package/out/lib/segment-worker-entry.js.map +0 -1
  123. package/out/lib/segment-workers.d.ts +0 -56
  124. package/out/lib/segment-workers.d.ts.map +0 -1
  125. package/out/lib/segment-workers.js +0 -110
  126. package/out/lib/segment-workers.js.map +0 -1
  127. package/out/lib/segments.d.ts +0 -31
  128. package/out/lib/segments.d.ts.map +0 -1
  129. package/out/lib/segments.js +0 -52
  130. package/out/lib/segments.js.map +0 -1
  131. package/out/lib/shared.d.ts +0 -155
  132. package/out/lib/shared.d.ts.map +0 -1
  133. package/out/lib/shared.js +0 -41
  134. package/out/lib/shared.js.map +0 -1
  135. package/out/lib/take.d.ts +0 -42
  136. package/out/lib/take.d.ts.map +0 -1
  137. package/out/lib/take.js +0 -101
  138. package/out/lib/take.js.map +0 -1
  139. package/out/lib/utils.d.ts +0 -37
  140. package/out/lib/utils.d.ts.map +0 -1
  141. package/out/lib/utils.js +0 -39
  142. package/out/lib/utils.js.map +0 -1
  143. package/out/lib/wasm_base64.d.ts +0 -19
  144. package/out/lib/wasm_base64.d.ts.map +0 -1
  145. package/out/lib/wasm_base64.js +0 -19
  146. package/out/lib/wasm_base64.js.map +0 -1
  147. package/out/lib/wasm_module.d.ts +0 -57
  148. package/out/lib/wasm_module.d.ts.map +0 -1
  149. package/out/lib/wasm_module.js +0 -34
  150. package/out/lib/wasm_module.js.map +0 -1
  151. package/out/lib/writer.d.ts +0 -45
  152. package/out/lib/writer.d.ts.map +0 -1
  153. package/out/lib/writer.js +0 -57
  154. package/out/lib/writer.js.map +0 -1
  155. package/out/lib/zip.d.ts +0 -33
  156. package/out/lib/zip.d.ts.map +0 -1
  157. package/out/lib/zip.js +0 -59
  158. package/out/lib/zip.js.map +0 -1
  159. package/out/node/cli/parse-args.d.ts +0 -120
  160. package/out/node/cli/parse-args.d.ts.map +0 -1
  161. package/out/node/cli/parse-args.js +0 -118
  162. package/out/node/cli/parse-args.js.map +0 -1
@@ -1,20 +0,0 @@
1
- /**
2
- * @copyright Sister Software
3
- * @license MIT
4
- * @author Teffen Ellis, et al.
5
- */
6
- /**
7
- * Group an iterable's values into arrays of `size`, with a shorter final batch if the collection does not divide
8
- * evenly.
9
- *
10
- * Distinct from `Iterator.prototype.take`, which yields the first `size` _values_. Named for the [iterator chunking
11
- * proposal](https://github.com/tc39/proposal-iterator-chunking).
12
- *
13
- * @param collection The collection to batch.
14
- * @param size The size of each batch.
15
- *
16
- * @yields Each batch of values.
17
- * @see {@linkcode AsyncSequence.chunks} for the asynchronous form.
18
- */
19
- export declare function chunks<T>(collection: Iterable<T>, size: number): Generator<T[]>;
20
- //# sourceMappingURL=chunks.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"chunks.d.ts","sourceRoot":"","sources":["../../lib/chunks.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;;;GAYG;AACH,wBAAiB,MAAM,CAAC,CAAC,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,EAAE,CAAC,CAsBhF"}
package/out/lib/chunks.js DELETED
@@ -1,36 +0,0 @@
1
- /**
2
- * @copyright Sister Software
3
- * @license MIT
4
- * @author Teffen Ellis, et al.
5
- */
6
- /**
7
- * Group an iterable's values into arrays of `size`, with a shorter final batch if the collection does not divide
8
- * evenly.
9
- *
10
- * Distinct from `Iterator.prototype.take`, which yields the first `size` _values_. Named for the [iterator chunking
11
- * proposal](https://github.com/tc39/proposal-iterator-chunking).
12
- *
13
- * @param collection The collection to batch.
14
- * @param size The size of each batch.
15
- *
16
- * @yields Each batch of values.
17
- * @see {@linkcode AsyncSequence.chunks} for the asynchronous form.
18
- */
19
- export function* chunks(collection, size) {
20
- const normalized = Math.trunc(size);
21
- if (!Number.isFinite(normalized) || normalized < 1) {
22
- throw new RangeError(`chunks(${size}): size must be a positive finite number`);
23
- }
24
- let batch = [];
25
- for (const item of collection) {
26
- batch.push(item);
27
- if (batch.length === normalized) {
28
- yield batch;
29
- batch = [];
30
- }
31
- }
32
- if (batch.length) {
33
- yield batch;
34
- }
35
- }
36
- //# sourceMappingURL=chunks.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"chunks.js","sourceRoot":"","sources":["../../lib/chunks.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;;;GAYG;AACH,MAAM,SAAS,CAAC,CAAC,MAAM,CAAI,UAAuB,EAAE,IAAY;IAC/D,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAEnC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,UAAU,GAAG,CAAC,EAAE,CAAC;QACpD,MAAM,IAAI,UAAU,CAAC,UAAU,IAAI,0CAA0C,CAAC,CAAA;IAC/E,CAAC;IAED,IAAI,KAAK,GAAQ,EAAE,CAAA;IAEnB,KAAK,MAAM,IAAI,IAAI,UAAU,EAAE,CAAC;QAC/B,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAEhB,IAAI,KAAK,CAAC,MAAM,KAAK,UAAU,EAAE,CAAC;YACjC,MAAM,KAAK,CAAA;YAEX,KAAK,GAAG,EAAE,CAAA;QACX,CAAC;IACF,CAAC;IAED,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;QAClB,MAAM,KAAK,CAAA;IACZ,CAAC;AACF,CAAC"}
@@ -1,12 +0,0 @@
1
- /**
2
- * @copyright Sister Software
3
- * @license MIT
4
- * @author Teffen Ellis, et al.
5
- */
6
- /**
7
- * Merge several async iterables, pulling from **all of them concurrently** and yielding each value as soon as it
8
- * arrives (completion order, not source order). An error from any source rejects; remaining sources are returned
9
- * (cancelled) on completion, error, or early break.
10
- */
11
- export declare function mergeAsyncIterators<R>(sources: Array<AsyncIterable<R>>): AsyncIterableIterator<R>;
12
- //# sourceMappingURL=merge-async-iterators.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"merge-async-iterators.d.ts","sourceRoot":"","sources":["../../lib/merge-async-iterators.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;GAIG;AACH,wBAAuB,mBAAmB,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,GAAG,qBAAqB,CAAC,CAAC,CAAC,CA6BxG"}
@@ -1,39 +0,0 @@
1
- /**
2
- * @copyright Sister Software
3
- * @license MIT
4
- * @author Teffen Ellis, et al.
5
- */
6
- /**
7
- * Merge several async iterables, pulling from **all of them concurrently** and yielding each value as soon as it
8
- * arrives (completion order, not source order). An error from any source rejects; remaining sources are returned
9
- * (cancelled) on completion, error, or early break.
10
- */
11
- export async function* mergeAsyncIterators(sources) {
12
- const advance = (it) => it.next().then((result) => ({ it, result }));
13
- const pending = new Map();
14
- for (const source of sources) {
15
- const it = source[Symbol.asyncIterator]();
16
- pending.set(it, advance(it));
17
- }
18
- try {
19
- while (pending.size) {
20
- const { it, result } = await Promise.race(pending.values());
21
- if (result.done) {
22
- pending.delete(it);
23
- }
24
- else {
25
- yield result.value;
26
- pending.set(it, advance(it));
27
- }
28
- }
29
- }
30
- finally {
31
- // Stop any iterators we didn't drain (early break / error). Swallow rejections from their
32
- // in-flight `next()` so they don't surface as unhandled.
33
- for (const promise of pending.values()) {
34
- void promise.catch(() => { });
35
- }
36
- await Promise.allSettled(Array.from(pending.keys(), (it) => it.return?.()));
37
- }
38
- }
39
- //# sourceMappingURL=merge-async-iterators.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"merge-async-iterators.js","sourceRoot":"","sources":["../../lib/merge-async-iterators.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;GAIG;AACH,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,mBAAmB,CAAI,OAAgC;IAC7E,MAAM,OAAO,GAAG,CAAC,EAAoB,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC,CAAA;IACtF,MAAM,OAAO,GAAG,IAAI,GAAG,EAAkF,CAAA;IAEzG,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC9B,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAA;QACzC,OAAO,CAAC,GAAG,CAAC,EAAE,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC,CAAA;IAC7B,CAAC;IAED,IAAI,CAAC;QACJ,OAAO,OAAO,CAAC,IAAI,EAAE,CAAC;YACrB,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAA;YAE3D,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC;gBACjB,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;YACnB,CAAC;iBAAM,CAAC;gBACP,MAAM,MAAM,CAAC,KAAK,CAAA;gBAClB,OAAO,CAAC,GAAG,CAAC,EAAE,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC,CAAA;YAC7B,CAAC;QACF,CAAC;IACF,CAAC;YAAS,CAAC;QACV,0FAA0F;QAC1F,yDAAyD;QACzD,KAAK,MAAM,OAAO,IAAI,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;YACxC,KAAK,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAA;QAC7B,CAAC;QAED,MAAM,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAA;IAC5E,CAAC;AACF,CAAC"}
@@ -1,22 +0,0 @@
1
- /**
2
- * @copyright Sister Software
3
- * @license MIT
4
- * @author Teffen Ellis, et al.
5
- *
6
- * Transport-agnostic core of `parallelMap` — a record-dispatch worker pool. `runPool` keeps every
7
- * worker busy mapping batches pulled from one shared source, with no `worker_threads` dependency so it
8
- * unit-tests against fake workers.
9
- */
10
- /**
11
- * One pool slot. `process` ships a batch to its worker and resolves with that batch's results.
12
- */
13
- export interface PoolWorker<T, R> {
14
- process(batch: T[]): Promise<R[]>;
15
- }
16
- /**
17
- * Drive a pool of `workers` over `source`: each worker loops — pull a batch, map it, emit results — until the source is
18
- * exhausted. Results stream out in completion order (a worker's whole batch yields before it pulls the next, which
19
- * bounds in-flight work to the pool size). A worker error propagates and tears the pool down.
20
- */
21
- export declare function runPool<T, R>(workers: Array<PoolWorker<T, R>>, source: AsyncIterable<T> | Iterable<T>, batchSize: number): AsyncIterableIterator<R>;
22
- //# sourceMappingURL=parallel-map-runtime.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"parallel-map-runtime.d.ts","sourceRoot":"","sources":["../../lib/parallel-map-runtime.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH;;GAEG;AACH,MAAM,WAAW,UAAU,CAAC,CAAC,EAAE,CAAC;IAC/B,OAAO,CAAC,KAAK,EAAE,CAAC,EAAE,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC,CAAA;CACjC;AA+CD;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,CAAC,EAC3B,OAAO,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAChC,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,EACtC,SAAS,EAAE,MAAM,GACf,qBAAqB,CAAC,CAAC,CAAC,CAgB1B"}
@@ -1,60 +0,0 @@
1
- /**
2
- * @copyright Sister Software
3
- * @license MIT
4
- * @author Teffen Ellis, et al.
5
- *
6
- * Transport-agnostic core of `parallelMap` — a record-dispatch worker pool. `runPool` keeps every
7
- * worker busy mapping batches pulled from one shared source, with no `worker_threads` dependency so it
8
- * unit-tests against fake workers.
9
- */
10
- import { mergeAsyncIterators } from "./merge-async-iterators.js";
11
- /**
12
- * Serialize pulls from `source` into batches of up to `batchSize`. Returns a `next()` that is safe to call concurrently
13
- * (each call awaits the prior pull) — concurrent worker loops share one source without racing the underlying iterator.
14
- * Resolves `null` once the source is exhausted.
15
- */
16
- function makeBatcher(source, batchSize) {
17
- const iterator = Symbol.asyncIterator in source
18
- ? source[Symbol.asyncIterator]()
19
- : source[Symbol.iterator]();
20
- let chain = Promise.resolve();
21
- let exhausted = false;
22
- return () => {
23
- const pull = chain.then(async () => {
24
- if (exhausted)
25
- return null;
26
- const batch = [];
27
- while (batch.length < batchSize) {
28
- const { value, done } = await iterator.next();
29
- if (done) {
30
- exhausted = true;
31
- break;
32
- }
33
- batch.push(value);
34
- }
35
- return batch.length ? batch : null;
36
- });
37
- // Keep the chain alive regardless of this pull's outcome so the next call still serializes.
38
- chain = pull.then(() => undefined, () => undefined);
39
- return pull;
40
- };
41
- }
42
- /**
43
- * Drive a pool of `workers` over `source`: each worker loops — pull a batch, map it, emit results — until the source is
44
- * exhausted. Results stream out in completion order (a worker's whole batch yields before it pulls the next, which
45
- * bounds in-flight work to the pool size). A worker error propagates and tears the pool down.
46
- */
47
- export function runPool(workers, source, batchSize) {
48
- const nextBatch = makeBatcher(source, batchSize);
49
- async function* workerLoop(worker) {
50
- for (;;) {
51
- const batch = await nextBatch();
52
- if (batch === null)
53
- return;
54
- const results = await worker.process(batch);
55
- yield* results;
56
- }
57
- }
58
- return mergeAsyncIterators(workers.map((worker) => workerLoop(worker)));
59
- }
60
- //# sourceMappingURL=parallel-map-runtime.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"parallel-map-runtime.js","sourceRoot":"","sources":["../../lib/parallel-map-runtime.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAA;AAShE;;;;GAIG;AACH,SAAS,WAAW,CAAI,MAAsC,EAAE,SAAiB;IAChF,MAAM,QAAQ,GACb,MAAM,CAAC,aAAa,IAAI,MAAM;QAC7B,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE;QAChC,CAAC,CAAE,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAkC,CAAA;IAE9D,IAAI,KAAK,GAAqB,OAAO,CAAC,OAAO,EAAE,CAAA;IAC/C,IAAI,SAAS,GAAG,KAAK,CAAA;IAErB,OAAO,GAAG,EAAE;QACX,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE;YAClC,IAAI,SAAS;gBAAE,OAAO,IAAI,CAAA;YAE1B,MAAM,KAAK,GAAQ,EAAE,CAAA;YAErB,OAAO,KAAK,CAAC,MAAM,GAAG,SAAS,EAAE,CAAC;gBACjC,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;gBAE7C,IAAI,IAAI,EAAE,CAAC;oBACV,SAAS,GAAG,IAAI,CAAA;oBAEhB,MAAK;gBACN,CAAC;gBAED,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;YAClB,CAAC;YAED,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAA;QACnC,CAAC,CAAC,CAAA;QAEF,4FAA4F;QAC5F,KAAK,GAAG,IAAI,CAAC,IAAI,CAChB,GAAG,EAAE,CAAC,SAAS,EACf,GAAG,EAAE,CAAC,SAAS,CACf,CAAA;QAED,OAAO,IAAI,CAAA;IACZ,CAAC,CAAA;AACF,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,OAAO,CACtB,OAAgC,EAChC,MAAsC,EACtC,SAAiB;IAEjB,MAAM,SAAS,GAAG,WAAW,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;IAEhD,KAAK,SAAS,CAAC,CAAC,UAAU,CAAC,MAAwB;QAClD,SAAS,CAAC;YACT,MAAM,KAAK,GAAG,MAAM,SAAS,EAAE,CAAA;YAE/B,IAAI,KAAK,KAAK,IAAI;gBAAE,OAAM;YAE1B,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;YAE3C,KAAK,CAAC,CAAC,OAAO,CAAA;QACf,CAAC;IACF,CAAC;IAED,OAAO,mBAAmB,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;AACxE,CAAC"}
@@ -1,11 +0,0 @@
1
- /**
2
- * @copyright Sister Software
3
- * @license MIT
4
- * @author Teffen Ellis, et al.
5
- *
6
- * Runs inside a worker thread (spawned by parallelMap). Imports the handler module once (top-level =
7
- * per-worker init), then maps each dispatched batch and posts the results back. Processes one batch at
8
- * a time — the pool never dispatches the next until this batch's result returns.
9
- */
10
- export {};
11
- //# sourceMappingURL=parallel-map-worker-entry.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"parallel-map-worker-entry.d.ts","sourceRoot":"","sources":["../../lib/parallel-map-worker-entry.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG"}
@@ -1,41 +0,0 @@
1
- /**
2
- * @copyright Sister Software
3
- * @license MIT
4
- * @author Teffen Ellis, et al.
5
- *
6
- * Runs inside a worker thread (spawned by parallelMap). Imports the handler module once (top-level =
7
- * per-worker init), then maps each dispatched batch and posts the results back. Processes one batch at
8
- * a time — the pool never dispatches the next until this batch's result returns.
9
- */
10
- import { parentPort, workerData } from "node:worker_threads";
11
- const data = workerData;
12
- const port = parentPort;
13
- let nextIndex = 0;
14
- const handlerReady = import(data.handlerUrl).then((mod) => mod.handleItem ?? mod.default);
15
- port.on("message", async (msg) => {
16
- const message = msg;
17
- if (message?.type !== "batch")
18
- return;
19
- try {
20
- const handleItem = await handlerReady;
21
- if (typeof handleItem !== "function") {
22
- throw new TypeError(`Worker module ${data.handlerUrl} has no handleItem export.`);
23
- }
24
- const results = [];
25
- const transfer = [];
26
- for (const item of message.batch) {
27
- const result = await handleItem(item, { index: nextIndex++ });
28
- if (result === undefined)
29
- continue;
30
- results.push(result);
31
- if (result instanceof Uint8Array) {
32
- transfer.push(result.buffer);
33
- }
34
- }
35
- port.postMessage({ type: "result", results }, transfer);
36
- }
37
- catch (error) {
38
- port.postMessage({ type: "error", message: error instanceof Error ? error.message : String(error) });
39
- }
40
- });
41
- //# sourceMappingURL=parallel-map-worker-entry.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"parallel-map-worker-entry.js","sourceRoot":"","sources":["../../lib/parallel-map-worker-entry.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAS5D,MAAM,IAAI,GAAG,UAAwB,CAAA;AACrC,MAAM,IAAI,GAAG,UAAW,CAAA;AAExB,IAAI,SAAS,GAAG,CAAC,CAAA;AAEjB,MAAM,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,IAAI,CAChD,CAAC,GAAgE,EAAE,EAAE,CAAC,GAAG,CAAC,UAAU,IAAI,GAAG,CAAC,OA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* @copyright Sister Software
3
- * @license MIT
4
- * @author Teffen Ellis, et al.
5
- */
6
- /**
7
- * Per-item handler a parallelMapWorkers worker module exports. `index` is per-worker monotonic.
8
- */
9
- export type ParallelHandler<T = unknown, R = unknown> = (item: T, ctx: {
10
- index: number;
11
- }) => R | Uint8Array | undefined | Promise<R | Uint8Array | undefined>;
12
- export interface ParallelMapWorkersOptions {
13
- /**
14
- * Worker module path/URL exporting `handleItem(item, ctx)`. Top-level code = per-worker init.
15
- */
16
- worker: string | URL;
17
- /**
18
- * Number of worker threads in the pool. Keep it SMALL for I/O- or memory-bound handlers (per-row DB lookups, large
19
- * shared datasets): throughput typically peaks at ~2–3 and _degrades_ past that as workers contend for the shared
20
- * resource — only CPU-bound handlers scale toward the core count. Also bounded by RAM (each worker re-inits its
21
- * deps). Sweep it for your workload rather than defaulting to `availableParallelism()`.
22
- */
23
- concurrency: number;
24
- /**
25
- * Items per dispatched batch. @default 64
26
- */
27
- batchSize?: number;
28
- /**
29
- * Forwarded to every worker via `workerData.userData` (must be structured-cloneable).
30
- */
31
- workerData?: unknown;
32
- }
33
- /**
34
- * Map an async (or sync) iterable through a pool of worker threads. Main pulls items from `source`, batches them, and
35
- * dispatches each batch to an idle worker running the `worker` handler module; results stream back as a single merged
36
- * async iterator in **completion order** (not input order). A handler returning `undefined` drops that item; a
37
- * `Uint8Array` is transferred zero-copy.
38
- *
39
- * **When it pays (measure — don't assume).** Threading only wins when per-item work is heavy relative to the ~µs
40
- * cross-thread dispatch cost (structured-clone in + out). From real workloads: light per-row work — CSV/JSON parse,
41
- * string normalize, `JSON.parse` — is _dispatch-bound_ and runs **0.3–0.9× of single-threaded (a net loss)**; ms-scale
42
- * per-row work — model inference, geocoding, crypto/image ops — is where threads win. If the per-row cost isn't clearly
43
- * milliseconds, benchmark against the single-threaded version before adopting.
44
- *
45
- * **Concurrency is not core count.** Heavy work that is I/O- or memory-bound (random reads into one large on-disk DB,
46
- * anything sharing memory bandwidth) peaks _low_ — often ~2–3 workers — and then _degrades_, because the workers
47
- * contend for the shared resource, not the CPU. Start small and sweep; don't reach for `availableParallelism()`. Only
48
- * CPU-bound per-row work (pure compute) scales out toward the core count.
49
- *
50
- * All workers are terminated on completion, error, or early `return()`.
51
- *
52
- * @see `parallelMap` for the same shape on the caller's thread — it takes a closure, which is why it cannot cross a
53
- * thread boundary and this takes a module path instead.
54
- * @see The "Choosing a primitive" table in the README, which keys the decision off per-row work.
55
- */
56
- export declare function parallelMapWorkers<T, R = unknown>(source: AsyncIterable<T> | Iterable<T>, options: ParallelMapWorkersOptions): AsyncIterableIterator<R>;
57
- //# sourceMappingURL=parallel-map-workers.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"parallel-map-workers.d.ts","sourceRoot":"","sources":["../../lib/parallel-map-workers.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH;;GAEG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,GAAG,OAAO,IAAI,CACvD,IAAI,EAAE,CAAC,EACP,GAAG,EAAE;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,KAClB,CAAC,GAAG,UAAU,GAAG,SAAS,GAAG,OAAO,CAAC,CAAC,GAAG,UAAU,GAAG,SAAS,CAAC,CAAA;AAErE,MAAM,WAAW,yBAAyB;IACzC;;OAEG;IACH,MAAM,EAAE,MAAM,GAAG,GAAG,CAAA;IACpB;;;;;OAKG;IACH,WAAW,EAAE,MAAM,CAAA;IACnB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAA;CACpB;AAqCD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,CAAC,GAAG,OAAO,EAChD,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,EACtC,OAAO,EAAE,yBAAyB,GAChC,qBAAqB,CAAC,CAAC,CAAC,CAyB1B"}
@@ -1,82 +0,0 @@
1
- /**
2
- * @copyright Sister Software
3
- * @license MIT
4
- * @author Teffen Ellis, et al.
5
- */
6
- import { Worker } from "node:worker_threads";
7
- import { runPool } from "./parallel-map-runtime.js";
8
- /**
9
- * Wrap a worker as a pool slot: dispatch one batch, await its result. One batch in flight at a time.
10
- */
11
- function workerHandle(worker) {
12
- let pending = null;
13
- const settle = (fn) => {
14
- if (!pending)
15
- return;
16
- const p = pending;
17
- pending = null;
18
- fn(p);
19
- };
20
- worker.on("message", (msg) => {
21
- if (msg?.type === "result") {
22
- settle((p) => p.resolve(msg.results));
23
- }
24
- else if (msg?.type === "error") {
25
- settle((p) => p.reject(new Error(msg.message)));
26
- }
27
- });
28
- worker.on("error", (error) => settle((p) => p.reject(error instanceof Error ? error : new Error(String(error)))));
29
- return {
30
- process(batch) {
31
- return new Promise((resolve, reject) => {
32
- pending = { resolve, reject };
33
- worker.postMessage({ type: "batch", batch });
34
- });
35
- },
36
- };
37
- }
38
- /**
39
- * Map an async (or sync) iterable through a pool of worker threads. Main pulls items from `source`, batches them, and
40
- * dispatches each batch to an idle worker running the `worker` handler module; results stream back as a single merged
41
- * async iterator in **completion order** (not input order). A handler returning `undefined` drops that item; a
42
- * `Uint8Array` is transferred zero-copy.
43
- *
44
- * **When it pays (measure — don't assume).** Threading only wins when per-item work is heavy relative to the ~µs
45
- * cross-thread dispatch cost (structured-clone in + out). From real workloads: light per-row work — CSV/JSON parse,
46
- * string normalize, `JSON.parse` — is _dispatch-bound_ and runs **0.3–0.9× of single-threaded (a net loss)**; ms-scale
47
- * per-row work — model inference, geocoding, crypto/image ops — is where threads win. If the per-row cost isn't clearly
48
- * milliseconds, benchmark against the single-threaded version before adopting.
49
- *
50
- * **Concurrency is not core count.** Heavy work that is I/O- or memory-bound (random reads into one large on-disk DB,
51
- * anything sharing memory bandwidth) peaks _low_ — often ~2–3 workers — and then _degrades_, because the workers
52
- * contend for the shared resource, not the CPU. Start small and sweep; don't reach for `availableParallelism()`. Only
53
- * CPU-bound per-row work (pure compute) scales out toward the core count.
54
- *
55
- * All workers are terminated on completion, error, or early `return()`.
56
- *
57
- * @see `parallelMap` for the same shape on the caller's thread — it takes a closure, which is why it cannot cross a
58
- * thread boundary and this takes a module path instead.
59
- * @see The "Choosing a primitive" table in the README, which keys the decision off per-row work.
60
- */
61
- export function parallelMapWorkers(source, options) {
62
- const handlerUrl = options.worker instanceof URL ? options.worker.href : new URL(options.worker, `file://${process.cwd()}/`).href;
63
- const concurrency = Math.max(1, Math.floor(options.concurrency));
64
- const batchSize = options.batchSize ?? 64;
65
- const entryUrl = new URL("./parallel-map-worker-entry.js", import.meta.url);
66
- const workers = [];
67
- async function* run() {
68
- try {
69
- const pool = Array.from({ length: concurrency }, () => {
70
- const worker = new Worker(entryUrl, { workerData: { handlerUrl, userData: options.workerData } });
71
- workers.push(worker);
72
- return workerHandle(worker);
73
- });
74
- yield* runPool(pool, source, batchSize);
75
- }
76
- finally {
77
- await Promise.all(workers.map((worker) => worker.terminate()));
78
- }
79
- }
80
- return run();
81
- }
82
- //# sourceMappingURL=parallel-map-workers.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"parallel-map-workers.js","sourceRoot":"","sources":["../../lib/parallel-map-workers.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAE5C,OAAO,EAAmB,OAAO,EAAE,MAAM,2BAA2B,CAAA;AAgCpE;;GAEG;AACH,SAAS,YAAY,CAAO,MAAc;IACzC,IAAI,OAAO,GAA+E,IAAI,CAAA;IAE9F,MAAM,MAAM,GAAG,CAAC,EAA4C,EAAE,EAAE;QAC/D,IAAI,CAAC,OAAO;YAAE,OAAM;QACpB,MAAM,CAAC,GAAG,OAAO,CAAA;QACjB,OAAO,GAAG,IAAI,CAAA;QACd,EAAE,CAAC,CAAC,CAAC,CAAA;IACN,CAAC,CAAA;IAED,MAAM,CAAC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ParallelMapSequenceOptions } from "./AsyncSequence.js";
7
- /**
8
- * Map an iterable through a callback with up to `concurrency` calls in flight, yielding in **completion order** — not
9
- * input order.
10
- *
11
- * The callback is a closure, so every call runs on the caller's thread. This overlaps _latency_ — file reads, network
12
- * round-trips, anything that spends its time waiting — and does nothing for CPU-bound work, which still occupies the
13
- * one thread it always did.
14
- *
15
- * **Concurrency is not core count.** Work that contends for a shared resource (one disk, one socket pool, one on-disk
16
- * database) peaks _low_ — often ~2–3 — and then degrades. Sweep it.
17
- *
18
- * @param source The collection to map.
19
- * @param fn The callback, receiving `(value, counter)`.
20
- * @param options Concurrency ceiling and optional abort signal.
21
- *
22
- * @yields Each result, in completion order.
23
- * @see {@linkcode parallelMapWorkers} to run the handler on worker threads instead — it takes a module path rather than
24
- * a closure, because a closure cannot cross a thread boundary.
25
- * @see The "Choosing a primitive" table in the README, which keys the decision off per-row work.
26
- */
27
- export declare function parallelMap<T, U>(source: AsyncIterable<T> | Iterable<T>, fn: (value: T, counter: number) => U | PromiseLike<U>, options: ParallelMapSequenceOptions): AsyncSequence<U>;
28
- //# sourceMappingURL=parallel-map.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"parallel-map.d.ts","sourceRoot":"","sources":["../../lib/parallel-map.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,aAAa,EAAE,KAAK,0BAA0B,EAAE,MAAM,oBAAoB,CAAA;AAEnF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,CAAC,EAC/B,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,EACtC,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,EACrD,OAAO,EAAE,0BAA0B,GACjC,aAAa,CAAC,CAAC,CAAC,CAElB"}
@@ -1,30 +0,0 @@
1
- /**
2
- * @copyright Sister Software
3
- * @license MIT
4
- * @author Teffen Ellis, et al.
5
- */
6
- import { AsyncSequence } from "./AsyncSequence.js";
7
- /**
8
- * Map an iterable through a callback with up to `concurrency` calls in flight, yielding in **completion order** — not
9
- * input order.
10
- *
11
- * The callback is a closure, so every call runs on the caller's thread. This overlaps _latency_ — file reads, network
12
- * round-trips, anything that spends its time waiting — and does nothing for CPU-bound work, which still occupies the
13
- * one thread it always did.
14
- *
15
- * **Concurrency is not core count.** Work that contends for a shared resource (one disk, one socket pool, one on-disk
16
- * database) peaks _low_ — often ~2–3 — and then degrades. Sweep it.
17
- *
18
- * @param source The collection to map.
19
- * @param fn The callback, receiving `(value, counter)`.
20
- * @param options Concurrency ceiling and optional abort signal.
21
- *
22
- * @yields Each result, in completion order.
23
- * @see {@linkcode parallelMapWorkers} to run the handler on worker threads instead — it takes a module path rather than
24
- * a closure, because a closure cannot cross a thread boundary.
25
- * @see The "Choosing a primitive" table in the README, which keys the decision off per-row work.
26
- */
27
- export function parallelMap(source, fn, options) {
28
- return AsyncSequence.from(source).parallelMap(fn, options);
29
- }
30
- //# sourceMappingURL=parallel-map.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"parallel-map.js","sourceRoot":"","sources":["../../lib/parallel-map.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,aAAa,EAAmC,MAAM,oBAAoB,CAAA;AAEnF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,WAAW,CAC1B,MAAsC,EACtC,EAAqD,EACrD,OAAmC;IAEnC,OAAO,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,WAAW,CAAC,EAAE,EAAE,OAAO,CAAC,CAAA;AAC3D,CAAC"}
@@ -1,30 +0,0 @@
1
- /**
2
- * @copyright Sister Software
3
- * @license MIT
4
- * @author Teffen Ellis, et al.
5
- */
6
- /**
7
- * Given an iterable of values, maps each value to a record of the value and the result of the callback.
8
- *
9
- * This is a convenience function when an iterable needs mapping to an object-like structure.
10
- *
11
- * ```ts
12
- * const iterable = ["a", "b", "c"]
13
- * const result = pivot(iterable, (value) => value.toUpperCase())
14
- *
15
- * // { a: "A", b: "B", c: "C" }
16
- * ```
17
- *
18
- * @category Collections
19
- * @category Object
20
- */
21
- export declare function pivot<T extends PropertyKey, C extends (value: T) => Promise<unknown> | unknown>(
22
- /**
23
- * The iterable to pivot.
24
- */
25
- iterable: Iterable<T>,
26
- /**
27
- * The callback to transform each value.
28
- */
29
- callback: C): ReturnType<C> extends PromiseLike<infer U> ? Promise<Record<T, U>> : Record<T, ReturnType<C>>;
30
- //# sourceMappingURL=pivot.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"pivot.d.ts","sourceRoot":"","sources":["../../lib/pivot.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,KAAK,CAAC,CAAC,SAAS,WAAW,EAAE,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO;AAC9F;;GAEG;AACH,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC;AACrB;;GAEG;AACH,QAAQ,EAAE,CAAC,GACT,UAAU,CAAC,CAAC,CAAC,SAAS,WAAW,CAAC,MAAM,CAAC,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CA6B/F"}
package/out/lib/pivot.js DELETED
@@ -1,47 +0,0 @@
1
- /**
2
- * @copyright Sister Software
3
- * @license MIT
4
- * @author Teffen Ellis, et al.
5
- */
6
- /**
7
- * Given an iterable of values, maps each value to a record of the value and the result of the callback.
8
- *
9
- * This is a convenience function when an iterable needs mapping to an object-like structure.
10
- *
11
- * ```ts
12
- * const iterable = ["a", "b", "c"]
13
- * const result = pivot(iterable, (value) => value.toUpperCase())
14
- *
15
- * // { a: "A", b: "B", c: "C" }
16
- * ```
17
- *
18
- * @category Collections
19
- * @category Object
20
- */
21
- export function pivot(
22
- /**
23
- * The iterable to pivot.
24
- */
25
- iterable,
26
- /**
27
- * The callback to transform each value.
28
- */
29
- callback) {
30
- const entries = [];
31
- let foundThenable = false;
32
- for (const value of iterable) {
33
- const result = callback(value);
34
- if (result && typeof result === "object" && "then" in result) {
35
- foundThenable = true;
36
- }
37
- entries.push([value, result]);
38
- }
39
- if (foundThenable) {
40
- return Promise.all(entries.map(([key, value]) => {
41
- return Promise.resolve(value).then((resolvedValue) => [key, resolvedValue]);
42
- })).then(Object.fromEntries);
43
- }
44
- const pivotedRecord = Object.fromEntries(entries);
45
- return pivotedRecord;
46
- }
47
- //# sourceMappingURL=pivot.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"pivot.js","sourceRoot":"","sources":["../../lib/pivot.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,KAAK;AACpB;;GAEG;AACH,QAAqB;AACrB;;GAEG;AACH,QAAW;IAEX,MAAM,OAAO,GAA8B,EAAE,CAAA;IAC7C,IAAI,aAAa,GAAG,KAAK,CAAA;IAEzB,KAAK,MAAM,KAAK,IAAI,QAAQ,EAAE,CAAC;QAC9B,MAAM,MAAM,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAA;QAE9B,IAAI,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,IAAI,MAAM,EAAE,CAAC;YAC9D,aAAa,GAAG,IAAI,CAAA;QACrB,CAAC;QAED,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,MAAuB,CAAC,CAAC,CAAA;IAC/C,CAAC;IAED,IAAI,aAAa,EAAE,CAAC;QACnB,OAAO,OAAO,CAAC,GAAG,CACjB,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;YAC5B,OAAO,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,aAAa,CAAU,CAAC,CAAA;QACrF,CAAC,CAAC,CACF,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,CAEE,CAAA;IAC5B,CAAC;IAED,MAAM,aAAa,GAAG,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAA;IAEjD,OAAO,aAEoB,CAAA;AAC5B,CAAC"}
@@ -1,35 +0,0 @@
1
- /**
2
- * @copyright Sister Software
3
- * @license MIT
4
- * @author Teffen Ellis, et al.
5
- */
6
- /**
7
- * An output mode for row-emitting spliterators.
8
- */
9
- export type RowOutputMode = "array" | "object" | "entries";
10
- export type RowTransformer<V, T = unknown> = (value: V) => T;
11
- export type RowTransformerEntry<V, T = unknown> = [columnName: string, transformer: RowTransformer<V, T>];
12
- export type RowTransformerRecord<V> = Record<string, RowTransformer<V> | undefined>;
13
- export type RowEmitter<V, T = unknown> = (columns: Iterable<V>, headerColumns?: Iterable<RowTransformerEntry<V>>) => T;
14
- export type EmittedRecord<V = unknown> = Record<string, V>;
15
- /**
16
- * A row emitted in `entries` mode, as a 3-tuple:
17
- *
18
- * - The key of the column.
19
- * - The value of the column.
20
- * - The index of the row.
21
- */
22
- export type RowTuple<V = string | number> = [key: string, value: V, idx: number];
23
- export declare const identity: <V>(value: V) => V;
24
- /**
25
- * Create the `mode`-keyed emitter table for a cell type.
26
- *
27
- * `missingValue` fills columns absent from a short row (CSV binds `""`, XLSX binds `null`).
28
- */
29
- export declare function createRowEmitters<V>(missingValue: V): Record<RowOutputMode, RowEmitter<V> | null>;
30
- /**
31
- * Bind a header row to the caller's transformers, producing the `headerColumns` entries the emitters consume. Columns
32
- * without a transformer pass through {@linkcode identity}.
33
- */
34
- export declare function bindTransformers<V>(headers: string[], transformersInput: Iterable<RowTransformerEntry<V>> | RowTransformerRecord<V>): RowTransformerEntry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