spliterator 2.2.3 → 3.0.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 +42 -0
- package/out/index.d.ts +2 -1
- package/out/index.d.ts.map +1 -1
- package/out/index.js +2 -1
- package/out/index.js.map +1 -1
- package/out/lib/AsyncSpliterator.d.ts +35 -34
- package/out/lib/AsyncSpliterator.d.ts.map +1 -1
- package/out/lib/AsyncSpliterator.js +93 -84
- package/out/lib/AsyncSpliterator.js.map +1 -1
- package/out/lib/BufferController.d.ts +10 -12
- package/out/lib/BufferController.d.ts.map +1 -1
- package/out/lib/BufferController.js +10 -12
- package/out/lib/BufferController.js.map +1 -1
- package/out/lib/CSVSpliterator.d.ts +6 -5
- package/out/lib/CSVSpliterator.d.ts.map +1 -1
- package/out/lib/CSVSpliterator.js +8 -5
- package/out/lib/CSVSpliterator.js.map +1 -1
- package/out/lib/CharacterSequence.d.ts +15 -64
- package/out/lib/CharacterSequence.d.ts.map +1 -1
- package/out/lib/CharacterSequence.js +194 -88
- package/out/lib/CharacterSequence.js.map +1 -1
- package/out/lib/CompositeDataView.d.ts +4 -5
- package/out/lib/CompositeDataView.d.ts.map +1 -1
- package/out/lib/CompositeDataView.js +2 -3
- package/out/lib/CompositeDataView.js.map +1 -1
- package/out/lib/IndexQueue.d.ts +1 -1
- package/out/lib/IndexQueue.d.ts.map +1 -1
- package/out/lib/IndexQueue.js +40 -11
- package/out/lib/IndexQueue.js.map +1 -1
- package/out/lib/JSONSpliterator.d.ts +1 -1
- package/out/lib/JSONSpliterator.js +1 -1
- package/out/lib/PSVSpliterator.d.ts +1 -1
- package/out/lib/PSVSpliterator.js +1 -1
- package/out/lib/SlidingWindow.d.ts +1 -1
- package/out/lib/SlidingWindow.d.ts.map +1 -1
- package/out/lib/SlidingWindow.js +11 -10
- package/out/lib/SlidingWindow.js.map +1 -1
- package/out/lib/Spliterator.d.ts +2 -3
- package/out/lib/Spliterator.d.ts.map +1 -1
- package/out/lib/Spliterator.js +102 -114
- package/out/lib/Spliterator.js.map +1 -1
- package/out/lib/TSVSpliterator.d.ts +1 -1
- package/out/lib/TSVSpliterator.js +1 -1
- package/out/lib/TextSpliterator.d.ts +4 -3
- package/out/lib/TextSpliterator.d.ts.map +1 -1
- package/out/lib/TextSpliterator.js +3 -1
- package/out/lib/TextSpliterator.js.map +1 -1
- package/out/lib/casing.d.ts +2 -3
- package/out/lib/casing.d.ts.map +1 -1
- package/out/lib/casing.js +2 -3
- package/out/lib/casing.js.map +1 -1
- package/out/lib/segment-runtime.d.ts +27 -0
- package/out/lib/segment-runtime.d.ts.map +1 -0
- package/out/lib/segment-runtime.js +38 -0
- package/out/lib/segment-runtime.js.map +1 -0
- package/out/lib/segment-worker-entry.d.ts +10 -0
- package/out/lib/segment-worker-entry.d.ts.map +1 -0
- package/out/lib/segment-worker-entry.js +56 -0
- package/out/lib/segment-worker-entry.js.map +1 -0
- package/out/lib/segment-workers.d.ts +41 -0
- package/out/lib/segment-workers.d.ts.map +1 -0
- package/out/lib/segment-workers.js +105 -0
- package/out/lib/segment-workers.js.map +1 -0
- package/out/lib/segments.d.ts +25 -0
- package/out/lib/segments.d.ts.map +1 -0
- package/out/lib/segments.js +50 -0
- package/out/lib/segments.js.map +1 -0
- package/out/lib/shared.d.ts +6 -5
- package/out/lib/shared.d.ts.map +1 -1
- package/out/lib/shared.js +3 -1
- package/out/lib/shared.js.map +1 -1
- package/out/lib/take.d.ts +3 -3
- package/out/lib/take.d.ts.map +1 -1
- package/out/lib/take.js +3 -3
- package/out/lib/take.js.map +1 -1
- package/out/lib/wasm_base64.d.ts +16 -0
- package/out/lib/wasm_base64.d.ts.map +1 -0
- package/out/lib/wasm_base64.js +16 -0
- package/out/lib/wasm_base64.js.map +1 -0
- package/out/lib/wasm_module.d.ts +36 -0
- package/out/lib/wasm_module.d.ts.map +1 -0
- package/out/lib/wasm_module.js +33 -0
- package/out/lib/wasm_module.js.map +1 -0
- package/out/lib/writer.d.ts +1 -1
- package/out/lib/writer.d.ts.map +1 -1
- package/out/lib/writer.js +1 -1
- package/out/lib/writer.js.map +1 -1
- package/out/node/cli/commands/csv.d.ts +1 -1
- package/out/node/cli/commands/csv.d.ts.map +1 -1
- package/out/node/cli/commands/csv.js +1 -1
- package/out/node/cli/commands/csv.js.map +1 -1
- package/out/node/cli/commands/iterate.d.ts +1 -1
- package/out/node/cli/commands/iterate.d.ts.map +1 -1
- package/out/node/cli/commands/iterate.js +1 -1
- package/out/node/cli/commands/iterate.js.map +1 -1
- package/out/node/cli/index.d.ts +1 -1
- package/out/node/cli/index.js +1 -1
- package/out/node/cli/utils.d.ts +1 -1
- package/out/node/cli/utils.js +1 -1
- package/out/node/fs/index.d.ts +16 -4
- package/out/node/fs/index.d.ts.map +1 -1
- package/out/node/fs/index.js +28 -4
- package/out/node/fs/index.js.map +1 -1
- package/package.json +4 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @copyright Sister Software
|
|
3
|
-
* @license
|
|
3
|
+
* @license MIT
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*/
|
|
6
6
|
/**
|
|
@@ -49,16 +49,14 @@ export class BufferController {
|
|
|
49
49
|
/**
|
|
50
50
|
* Modify the buffer in place, keeping only the bytes between the start and end indices.
|
|
51
51
|
*
|
|
52
|
-
* This is performed after we're confident that any data preceeding `start` or following `end` is
|
|
53
|
-
* no longer needed.
|
|
52
|
+
* This is performed after we're confident that any data preceeding `start` or following `end` is no longer needed.
|
|
54
53
|
*
|
|
55
|
-
* `bytesWritten` is rebased onto the new window so it always reflects the count of valid bytes
|
|
56
|
-
*
|
|
57
|
-
* underlying allocation is larger.
|
|
54
|
+
* `bytesWritten` is rebased onto the new window so it always reflects the count of valid bytes present after
|
|
55
|
+
* compression. Bytes outside the kept window are dropped from the count even if the underlying allocation is larger.
|
|
58
56
|
*
|
|
59
57
|
* @param start - The starting byte index of which bytes to keep.
|
|
60
|
-
* @param end - The ending byte index of which bytes to keep. Defaults to the current buffer
|
|
61
|
-
*
|
|
58
|
+
* @param end - The ending byte index of which bytes to keep. Defaults to the current buffer length. Values past the
|
|
59
|
+
* buffer length are clamped.
|
|
62
60
|
*/
|
|
63
61
|
compress(start = 0, end = this.bytes.length) {
|
|
64
62
|
const clampedEnd = Math.min(end, this.bytes.length);
|
|
@@ -77,8 +75,8 @@ export class BufferController {
|
|
|
77
75
|
this.bytesWritten = 0;
|
|
78
76
|
}
|
|
79
77
|
/**
|
|
80
|
-
* Gets a new Uint8Array view of the ArrayBuffer store for this array, referencing the elements at
|
|
81
|
-
*
|
|
78
|
+
* Gets a new Uint8Array view of the ArrayBuffer store for this array, referencing the elements at begin, inclusive,
|
|
79
|
+
* up to end, exclusive.
|
|
82
80
|
*
|
|
83
81
|
* @param begin — The index of the beginning of the array.
|
|
84
82
|
* @param end — The index of the end of the array
|
|
@@ -97,8 +95,8 @@ export class BufferController {
|
|
|
97
95
|
/**
|
|
98
96
|
* Sets a value or an array of values.
|
|
99
97
|
*
|
|
100
|
-
* Unlike the `TypedArray.set` method, this method will grow the buffer if the offset is greater
|
|
101
|
-
*
|
|
98
|
+
* Unlike the `TypedArray.set` method, this method will grow the buffer if the offset is greater than the current byte
|
|
99
|
+
* length.
|
|
102
100
|
*
|
|
103
101
|
* @param array — A typed or untyped array of values to set.
|
|
104
102
|
* @param offset — The index in the current array at which the values are to be written.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BufferController.js","sourceRoot":"","sources":["../../lib/BufferController.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,MAAM,OAAO,gBAAgB;IAC5B;;OAEG;IACH,kBAAkB,CAAQ;IAE1B;;;;OAIG;IACH,KAAK,CAAY;IAEjB;;;;OAIG;IACH,YAAY,CAAQ;IAEpB;;OAEG;IACH,IAAW,iBAAiB;QAC3B,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,EAAE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,eAAe,KAAK,8BAA8B,GAAG,GAAG,CAAC,CAAA;QAC/E,CAAC;QAED,IAAI,GAAG,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;YAC7B,MAAM,IAAI,UAAU,CAAC,aAAa,GAAG,4CAA4C,IAAI,CAAC,YAAY,GAAG,CAAC,CAAA;QACvG,CAAC;QAED,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;IACvC,CAAC;IAED;;;;;;;;;;OAUG;IACI,GAAG,CAAC,KAAwB,EAAE,SAAiB,CAAC;QACtD,MAAM,UAAU,GAAG,MAAM,GAAG,KAAK,CAAC,MAAM,CAAA;QAExC,IAAI,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;YACpC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;QACtB,CAAC;QAED,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;QAE7B,IAAI,UAAU,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;YACpC,IAAI,CAAC,YAAY,GAAG,UAAU,CAAA;QAC/B,CAAC;QAED,OAAO,UAAU,CAAA;IAClB,CAAC;CACD"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @copyright Sister Software
|
|
3
|
-
* @license
|
|
3
|
+
* @license MIT
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*/
|
|
6
6
|
import { type CharacterSequenceInput } from "./CharacterSequence.js";
|
|
@@ -48,8 +48,8 @@ export interface CSVSpliteratorInit extends SpliteratorInit {
|
|
|
48
48
|
/**
|
|
49
49
|
* Whether to normalize the keys of the header row.
|
|
50
50
|
*
|
|
51
|
-
* This will convert all header names to lowercase and replace spaces with underscores, making
|
|
52
|
-
*
|
|
51
|
+
* This will convert all header names to lowercase and replace spaces with underscores, making them more suitable for
|
|
52
|
+
* use as object keys.
|
|
53
53
|
*/
|
|
54
54
|
normalizeKeys?: boolean;
|
|
55
55
|
/**
|
|
@@ -110,11 +110,12 @@ export declare abstract class CSVSpliterator {
|
|
|
110
110
|
mode?: "array";
|
|
111
111
|
}): AsyncGenerator<T>;
|
|
112
112
|
/**
|
|
113
|
-
* Given an asychronous data source, splits the data by rows(usually by newline) and then by
|
|
114
|
-
*
|
|
113
|
+
* Given an asychronous data source, splits the data by rows(usually by newline) and then by columns (usually by
|
|
114
|
+
* comma).
|
|
115
115
|
*
|
|
116
116
|
* @param source The data source to split.
|
|
117
117
|
* @param init Options for the spliterator.
|
|
118
|
+
*
|
|
118
119
|
* @yields Each row, shaped according to the `mode` option.
|
|
119
120
|
*/
|
|
120
121
|
static fromAsync(source: AsyncDataResource | AsyncChunkIterator, init?: CSVSpliteratorInit & AsyncSpliteratorInit): AsyncGenerator<unknown>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CSVSpliterator.d.ts","sourceRoot":"","sources":["../../lib/CSVSpliterator.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAqB,KAAK,sBAAsB,EAAc,MAAM,wBAAwB,CAAA;AACnG,OAAO,EAAE,KAAK,kBAAkB,EAAE,KAAK,iBAAiB,EAAW,MAAM,aAAa,CAAA;AACtF,OAAO,EAAE,KAAK,oBAAoB,EAAe,KAAK,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAE/F;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,QAAQ,GAAG,SAAS,CAAA;AAC1D,MAAM,MAAM,cAAc,CAAC,CAAC,GAAG,OAAO,IAAI,CAAC,KAAK,EAAE,MAAM,KAAK,CAAC,CAAA;AAE9D,MAAM,MAAM,mBAAmB,CAAC,CAAC,GAAG,OAAO,IAAI,CAAC,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC,CAAA;AACnG,MAAM,MAAM,oBAAoB,GAAG,MAAM,C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,CAAC,SAAS,CAAC,CAAC,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,EAC7C,MAAM,EAAE,iBAAiB,GAAG,kBAAkB,EAC9C,OAAO,CAAC,EAAE,kBAAkB,GAAG,oBAAoB,GAAG;QAAE,IAAI,CAAC,EAAE,OAAO,CAAA;KAAE,GACtE,cAAc,CAAC,CAAC,CAAC;IACpB;;;;;;;;OAQG;IACH,MAAM,CAAC,SAAS,CACf,MAAM,EAAE,iBAAiB,GAAG,kBAAkB,EAC9C,IAAI,CAAC,EAAE,kBAAkB,GAAG,oBAAoB,GAC9C,cAAc,CAAC,OAAO,CAAC;CA4E1B"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @copyright Sister Software
|
|
3
|
-
* @license
|
|
3
|
+
* @license MIT
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*/
|
|
6
6
|
import { normalizeColumnNames } from "./casing.js";
|
|
@@ -89,16 +89,18 @@ export class CSVSpliterator {
|
|
|
89
89
|
}
|
|
90
90
|
if (yieldCount >= yieldLimit)
|
|
91
91
|
break;
|
|
92
|
-
const
|
|
92
|
+
const columnRanges = columnDelimiter.searchAll(row);
|
|
93
|
+
const columns = columnRanges.map(([s, e]) => decoder.decode(row.subarray(s, e)));
|
|
93
94
|
yield emitter ? emitter(columns, transformers) : columns;
|
|
94
95
|
}
|
|
95
96
|
}
|
|
96
97
|
/**
|
|
97
|
-
* Given an asychronous data source, splits the data by rows (usually by newline) and then by
|
|
98
|
-
*
|
|
98
|
+
* Given an asychronous data source, splits the data by rows (usually by newline) and then by columns (usually by
|
|
99
|
+
* comma).
|
|
99
100
|
*
|
|
100
101
|
* @param source The data source to split.
|
|
101
102
|
* @param init Options for the spliterator.
|
|
103
|
+
*
|
|
102
104
|
* @yields Each row, shaped according to the `mode` option.
|
|
103
105
|
*/
|
|
104
106
|
static async *fromAsync(source, init = {}) {
|
|
@@ -139,7 +141,8 @@ export class CSVSpliterator {
|
|
|
139
141
|
}
|
|
140
142
|
if (yieldCount >= yieldLimit)
|
|
141
143
|
break;
|
|
142
|
-
const
|
|
144
|
+
const columnRanges = columnDelimiter.searchAll(row);
|
|
145
|
+
const columns = columnRanges.map(([s, e]) => decoder.decode(row.subarray(s, e)));
|
|
143
146
|
yield emitter ? emitter(columns, transformers) : columns;
|
|
144
147
|
yieldCount++;
|
|
145
148
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CSVSpliterator.js","sourceRoot":"","sources":["../../lib/CSVSpliterator.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAClD,OAAO,EAAE,iBAAiB,EAA+B,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACnG,OAAO,EAAmD,OAAO,EAAE,MAAM,aAAa,CAAA;AACtF,OAAO,EAA6B,WAAW,EAAwB,MAAM,kBAAkB,CAAA;AAa/F,MAAM,QAAQ,GAA2B,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAA;AAezD,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACrC,KAAK,EAAE,IAAI;IAEX,OAAO,CAAC,OAAyB,EAAE,gBAA+C,EAAE;QACnF,OAAO,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC,WAAW,EAAE,KAAK,CAAC,EAAE,GAAG,EAAE,EAAE;YAChF,MAAM,GAAG,GAAG,WAAW,EAAE,CAAC,CAAC,CAAC,CAAA;YAC5B,MAAM,SAAS,GAAG,WAAW,EAAE,CAAC,CAAC,CAAC,IAAI,QAAQ,CAAA;
|
|
1
|
+
{"version":3,"file":"CSVSpliterator.js","sourceRoot":"","sources":["../../lib/CSVSpliterator.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAClD,OAAO,EAAE,iBAAiB,E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+
* @license MIT
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
*/
|
|
6
|
+
import type { ByteRange } from "./shared.js";
|
|
7
|
+
import { type MatchResult } from "./wasm_module.js";
|
|
9
8
|
export declare function isArrayLike<T>(input: unknown): input is ArrayLike<T>;
|
|
10
|
-
/**
|
|
11
|
-
* A possible input for a delimiter:
|
|
12
|
-
*
|
|
13
|
-
* - A single character code.
|
|
14
|
-
* - A string of characters.
|
|
15
|
-
* - An array of character codes.
|
|
16
|
-
* - A buffer.
|
|
17
|
-
* - An iterable of character codes.
|
|
18
|
-
*/
|
|
19
9
|
export type CharacterSequenceInput = number | string | DataView | ArrayBuffer | Buffer | Iterable<number>;
|
|
20
|
-
/**
|
|
21
|
-
* Common delimiter values.
|
|
22
|
-
*/
|
|
23
10
|
export declare const Delimiters: {
|
|
24
|
-
/**
|
|
25
|
-
* Null (␀)
|
|
26
|
-
*/
|
|
27
11
|
readonly Null: 0;
|
|
28
|
-
/**
|
|
29
|
-
* Newline (␊)
|
|
30
|
-
*/
|
|
31
12
|
readonly LineFeed: 10;
|
|
32
|
-
/**
|
|
33
|
-
* Carriage return (␍)
|
|
34
|
-
*/
|
|
35
13
|
readonly CarriageReturn: 13;
|
|
36
|
-
/**
|
|
37
|
-
* Comma (–)
|
|
38
|
-
*/
|
|
39
14
|
readonly Comma: 44;
|
|
40
|
-
/**
|
|
41
|
-
* Tab (␉)
|
|
42
|
-
*/
|
|
43
15
|
readonly Tab: 9;
|
|
44
|
-
/**
|
|
45
|
-
* Space (␠)
|
|
46
|
-
*/
|
|
47
16
|
readonly Space: 32;
|
|
48
|
-
/**
|
|
49
|
-
* One (1)
|
|
50
|
-
*/
|
|
51
17
|
readonly One: 49;
|
|
52
|
-
/**
|
|
53
|
-
* Zero (0)
|
|
54
|
-
*/
|
|
55
18
|
readonly Zero: 48;
|
|
56
|
-
/**
|
|
57
|
-
* Double quote (")
|
|
58
|
-
*/
|
|
59
19
|
readonly DoubleQuote: 34;
|
|
60
|
-
/**
|
|
61
|
-
* Record separator (␞)
|
|
62
|
-
*/
|
|
63
20
|
readonly RecordSeparator: 30;
|
|
64
|
-
/**
|
|
65
|
-
* Pipe (|)
|
|
66
|
-
*/
|
|
67
21
|
readonly Pipe: 124;
|
|
68
22
|
};
|
|
69
23
|
export declare const VisibleDelimiterMap: Map<number, string>;
|
|
70
24
|
export declare function debugAsVisibleCharacters(delimiter: Uint8Array): string;
|
|
71
25
|
export declare function normalizeCharacterInput(input: CharacterSequenceInput): Uint8Array;
|
|
72
|
-
/**
|
|
73
|
-
* An encoded sequence of characters, typically bytes representing a delimiter.
|
|
74
|
-
*
|
|
75
|
-
* Unlike a string, this class is optimized for searching and slicing.
|
|
76
|
-
*
|
|
77
|
-
* This also allows for multi-byte delimiters, such as CRLF or unicode characters.
|
|
78
|
-
*/
|
|
79
26
|
export declare class CharacterSequence extends Uint8Array {
|
|
80
27
|
#private;
|
|
81
28
|
/**
|
|
82
|
-
*
|
|
29
|
+
* Resolve once the WASM SIMD scanner has finished loading, yielding whether it is active.
|
|
83
30
|
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
* @returns The byte index of the pattern in the text, or -1 if not found.
|
|
31
|
+
* The module loads asynchronously, so synchronous callers (`Spliterator.fromSync`, `CSVSpliterator.from`) that run to
|
|
32
|
+
* completion in a single tick would otherwise always fall back to the JS scanner. Await this first to opt into SIMD
|
|
33
|
+
* acceleration.
|
|
89
34
|
*/
|
|
35
|
+
static whenReady(): Promise<boolean>;
|
|
90
36
|
search(haystack: Uint8Array, start?: number, end?: number): number;
|
|
91
|
-
|
|
37
|
+
searchAll(haystack: Uint8Array, start?: number, end?: number): ByteRange[];
|
|
92
38
|
/**
|
|
93
|
-
*
|
|
39
|
+
* Scan for two patterns simultaneously (delimiter + quote) for CSV parsing.
|
|
40
|
+
*
|
|
41
|
+
* Returns sorted MatchResult[] with patternId 0=delimiter, 1=quote. Uses WASM SIMD double-scan when available; JS
|
|
42
|
+
* fallback otherwise.
|
|
94
43
|
*/
|
|
44
|
+
searchMatches(haystack: Uint8Array, quotePattern: Uint8Array, start?: number, end?: number): MatchResult[];
|
|
45
|
+
decode(encoding?: string): string;
|
|
95
46
|
constructor(input?: CharacterSequenceInput);
|
|
96
47
|
}
|
|
97
48
|
//# sourceMappingURL=CharacterSequence.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CharacterSequence.d.ts","sourceRoot":"","sources":["../../lib/CharacterSequence.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH
|
|
1
|
+
{"version":3,"file":"CharacterSequence.d.ts","sourceRoot":"","sources":["../../lib/CharacterSequence.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,EAIN,KAAK,WAAW,EAGhB,MAAM,kBAAkB,CAAA;AAEzB,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,SAAS,CAAC,CAAC,CAAC,CAEpE;AAED,MAAM,MAAM,sBAAsB,GAAG,MAAM,GAAG,MAAM,GAAG,QAAQ,GAAG,WAAW,GAAG,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAA;AAEzG,eAAO,MAAM,UAAU;;;;;;;;;;;;CAYoB,CAAA;AAE3C,eAAO,MAAM,mBAAmB,qBAS9B,CAAA;AAEF,wBAAgB,wBAAwB,CAAC,SAAS,EAAE,UAAU,GAAG,MAAM,CAItE;AAID,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,sBAAsB,GAAG,UAAU,CAcjF;AAaD,qBAAa,iBAAkB,SAAQ,UAAU;;IA4BhD;;;;;;OAMG;WACW,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC;IAIpC,MAAM,CAAC,QAAQ,EAAE,UAAU,EAAE,KAAK,GAAE,MAAU,EAAE,GAAG,GAAE,MAAwB,GAAG,MAAM;IAuDtF,SAAS,CAAC,QAAQ,EAAE,UAAU,EAAE,KAAK,GAAE,MAAU,EAAE,GAAG,GAAE,MAAwB,GAAG,SAAS,EAAE;IA8DrG;;;;;OAKG;IACI,aAAa,CACnB,QAAQ,EAAE,UAAU,EACpB,YAAY,EAAE,UAAU,EACxB,KAAK,GAAE,MAAU,EACjB,GAAG,GAAE,MAAwB,GAC3B,WAAW,EAAE;IAqET,MAAM,CAAC,QAAQ,GAAE,MAAgB,GAAG,MAAM;gBAIrC,KAAK,GAAE,sBAA4C;CAO/D"}
|
|
@@ -1,154 +1,260 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @copyright Sister Software
|
|
3
|
-
* @license
|
|
3
|
+
* @license MIT
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*/
|
|
6
|
-
|
|
7
|
-
* Type-predicate to determine if a value is an array-like object.
|
|
8
|
-
*/
|
|
6
|
+
import { loadWasmModule, WASM_MAX_RESULTS, WASM_THRESHOLD, } from "./wasm_module.js";
|
|
9
7
|
export function isArrayLike(input) {
|
|
10
8
|
return Boolean(input && typeof input === "object" && "length" in input);
|
|
11
9
|
}
|
|
12
|
-
/**
|
|
13
|
-
* Common delimiter values.
|
|
14
|
-
*/
|
|
15
10
|
export const Delimiters = {
|
|
16
|
-
/**
|
|
17
|
-
* Null (␀)
|
|
18
|
-
*/
|
|
19
11
|
Null: 0,
|
|
20
|
-
/**
|
|
21
|
-
* Newline (␊)
|
|
22
|
-
*/
|
|
23
12
|
LineFeed: 10,
|
|
24
|
-
/**
|
|
25
|
-
* Carriage return (␍)
|
|
26
|
-
*/
|
|
27
13
|
CarriageReturn: 13,
|
|
28
|
-
/**
|
|
29
|
-
* Comma (–)
|
|
30
|
-
*/
|
|
31
14
|
Comma: 44,
|
|
32
|
-
/**
|
|
33
|
-
* Tab (␉)
|
|
34
|
-
*/
|
|
35
15
|
Tab: 9,
|
|
36
|
-
/**
|
|
37
|
-
* Space (␠)
|
|
38
|
-
*/
|
|
39
16
|
Space: 32,
|
|
40
|
-
/**
|
|
41
|
-
* One (1)
|
|
42
|
-
*/
|
|
43
17
|
One: 49,
|
|
44
|
-
/**
|
|
45
|
-
* Zero (0)
|
|
46
|
-
*/
|
|
47
18
|
Zero: 48,
|
|
48
|
-
/**
|
|
49
|
-
* Double quote (")
|
|
50
|
-
*/
|
|
51
19
|
DoubleQuote: 34,
|
|
52
|
-
/**
|
|
53
|
-
* Record separator (␞)
|
|
54
|
-
*/
|
|
55
20
|
RecordSeparator: 30,
|
|
56
|
-
/**
|
|
57
|
-
* Pipe (|)
|
|
58
|
-
*/
|
|
59
21
|
Pipe: 124,
|
|
60
22
|
};
|
|
61
23
|
export const VisibleDelimiterMap = new Map([
|
|
62
|
-
[Delimiters.LineFeed, "
|
|
63
|
-
[Delimiters.CarriageReturn, "
|
|
24
|
+
[Delimiters.LineFeed, "\u2424"],
|
|
25
|
+
[Delimiters.CarriageReturn, "\u240D"],
|
|
64
26
|
[Delimiters.Comma, "-"],
|
|
65
|
-
[Delimiters.Tab, "
|
|
66
|
-
[Delimiters.Space, "
|
|
27
|
+
[Delimiters.Tab, "\u2409"],
|
|
28
|
+
[Delimiters.Space, "\u2420"],
|
|
67
29
|
[Delimiters.DoubleQuote, '"'],
|
|
68
|
-
[Delimiters.RecordSeparator, "
|
|
69
|
-
[Delimiters.Null, "
|
|
30
|
+
[Delimiters.RecordSeparator, "\u241E"],
|
|
31
|
+
[Delimiters.Null, "\u2400"],
|
|
70
32
|
]);
|
|
71
33
|
export function debugAsVisibleCharacters(delimiter) {
|
|
72
34
|
return Array.from(delimiter)
|
|
73
|
-
.map((
|
|
74
|
-
const visible = VisibleDelimiterMap.get(charCode);
|
|
75
|
-
return visible ?? String.fromCharCode(charCode);
|
|
76
|
-
})
|
|
35
|
+
.map((c) => VisibleDelimiterMap.get(c) ?? String.fromCharCode(c))
|
|
77
36
|
.join("");
|
|
78
37
|
}
|
|
38
|
+
const encoder = new TextEncoder();
|
|
79
39
|
export function normalizeCharacterInput(input) {
|
|
80
40
|
switch (typeof input) {
|
|
81
41
|
case "number":
|
|
82
|
-
if (!Number.isInteger(input))
|
|
83
|
-
throw new TypeError(`Numeric delimiters must be integers
|
|
84
|
-
}
|
|
42
|
+
if (!Number.isInteger(input))
|
|
43
|
+
throw new TypeError(`Numeric delimiters must be integers.`);
|
|
85
44
|
return Uint8Array.from([input]);
|
|
86
45
|
case "string":
|
|
87
|
-
return
|
|
46
|
+
return encoder.encode(input);
|
|
88
47
|
case "object":
|
|
89
|
-
if (isArrayLike(input))
|
|
48
|
+
if (isArrayLike(input))
|
|
90
49
|
return input;
|
|
91
|
-
|
|
92
|
-
if (Symbol.iterator in input) {
|
|
50
|
+
if (Symbol.iterator in input)
|
|
93
51
|
return Uint8Array.from(input);
|
|
94
|
-
|
|
95
|
-
throw new TypeError(`Invalid delimiter type. Received an object, but it is not an array or buffer.`);
|
|
52
|
+
throw new TypeError(`Invalid delimiter type.`);
|
|
96
53
|
default:
|
|
97
|
-
throw new TypeError(`Invalid delimiter type
|
|
54
|
+
throw new TypeError(`Invalid delimiter type.`);
|
|
98
55
|
}
|
|
99
56
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
*/
|
|
57
|
+
function ensureWasmCapacity(memory, required) {
|
|
58
|
+
if (required <= memory.buffer.byteLength)
|
|
59
|
+
return;
|
|
60
|
+
const pages = Math.ceil((required - memory.buffer.byteLength) / 65536);
|
|
61
|
+
memory.grow(pages);
|
|
62
|
+
}
|
|
63
|
+
/** Round `offset` up to the next multiple of 4 — `Int32Array` views require a 4-byte-aligned base. */
|
|
64
|
+
function alignTo4(offset) {
|
|
65
|
+
return Math.ceil(offset / 4) * 4;
|
|
66
|
+
}
|
|
107
67
|
export class CharacterSequence extends Uint8Array {
|
|
108
|
-
/**
|
|
109
|
-
* A jump table for the Boyer-Moore-Horspool search algorithm.
|
|
110
|
-
*/
|
|
111
68
|
#skipIndex;
|
|
69
|
+
static #wasmScanner;
|
|
70
|
+
static #wasmHaystack = null;
|
|
71
|
+
static #wasmPatternOffset = 0;
|
|
72
|
+
static #wasmReadyPromise;
|
|
73
|
+
static #loadWasm() {
|
|
74
|
+
if (CharacterSequence.#wasmReadyPromise === undefined) {
|
|
75
|
+
// Reflect "load in progress" synchronously so search()'s fast path stops
|
|
76
|
+
// re-triggering loads on every call while the module compiles.
|
|
77
|
+
if (CharacterSequence.#wasmScanner === undefined)
|
|
78
|
+
CharacterSequence.#wasmScanner = null;
|
|
79
|
+
CharacterSequence.#wasmReadyPromise = loadWasmModule().then((mod) => {
|
|
80
|
+
CharacterSequence.#wasmScanner = mod;
|
|
81
|
+
return mod;
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
return CharacterSequence.#wasmReadyPromise;
|
|
85
|
+
}
|
|
86
|
+
static #ensureWasm() {
|
|
87
|
+
void CharacterSequence.#loadWasm();
|
|
88
|
+
}
|
|
112
89
|
/**
|
|
113
|
-
*
|
|
90
|
+
* Resolve once the WASM SIMD scanner has finished loading, yielding whether it is active.
|
|
114
91
|
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
* @returns The byte index of the pattern in the text, or -1 if not found.
|
|
92
|
+
* The module loads asynchronously, so synchronous callers (`Spliterator.fromSync`, `CSVSpliterator.from`) that run to
|
|
93
|
+
* completion in a single tick would otherwise always fall back to the JS scanner. Await this first to opt into SIMD
|
|
94
|
+
* acceleration.
|
|
120
95
|
*/
|
|
96
|
+
static whenReady() {
|
|
97
|
+
return CharacterSequence.#loadWasm().then((mod) => mod !== null);
|
|
98
|
+
}
|
|
121
99
|
search(haystack, start = 0, end = haystack.length) {
|
|
122
100
|
const sequenceLength = this.length;
|
|
101
|
+
// Single-byte delimiters (newline, comma, tab — the common case) are far faster via
|
|
102
|
+
// the native indexOf than the per-match Boyer-Moore-Horspool loop below. indexOf has
|
|
103
|
+
// no end bound, so clamp the result to keep `end` exclusive.
|
|
104
|
+
if (sequenceLength === 1) {
|
|
105
|
+
const index = haystack.indexOf(this[0], start);
|
|
106
|
+
return index !== -1 && index < end ? index : -1;
|
|
107
|
+
}
|
|
108
|
+
if (sequenceLength > 1 && end - start >= WASM_THRESHOLD) {
|
|
109
|
+
const wasm = CharacterSequence.#wasmScanner;
|
|
110
|
+
if (wasm) {
|
|
111
|
+
// Cache the *entire* haystack at offset 0 (so WASM byte `i` === `haystack[i]`),
|
|
112
|
+
// keyed by identity. This keeps repeated searches over the same source (the
|
|
113
|
+
// Spliterator fill loop) copy-free while staying correct for any start/end — the
|
|
114
|
+
// previous "copy [start,end)" scheme mis-mapped offsets when start !== 0 and
|
|
115
|
+
// silently ignored a shrinking `end`.
|
|
116
|
+
if (haystack !== CharacterSequence.#wasmHaystack) {
|
|
117
|
+
const fullLen = haystack.length;
|
|
118
|
+
const totalNeeded = fullLen + sequenceLength;
|
|
119
|
+
ensureWasmCapacity(wasm.memory, totalNeeded);
|
|
120
|
+
const buffer = new Uint8Array(wasm.memory.buffer, 0, totalNeeded);
|
|
121
|
+
buffer.set(haystack, 0);
|
|
122
|
+
buffer.set(this, fullLen);
|
|
123
|
+
CharacterSequence.#wasmHaystack = haystack;
|
|
124
|
+
CharacterSequence.#wasmPatternOffset = fullLen;
|
|
125
|
+
}
|
|
126
|
+
const result = wasm.findDelimiter(start, end - start, CharacterSequence.#wasmPatternOffset, sequenceLength);
|
|
127
|
+
return result >= 0 ? start + result : -1;
|
|
128
|
+
}
|
|
129
|
+
if (CharacterSequence.#wasmScanner === undefined)
|
|
130
|
+
CharacterSequence.#ensureWasm();
|
|
131
|
+
}
|
|
132
|
+
CharacterSequence.#wasmHaystack = null;
|
|
123
133
|
let startIndex = start;
|
|
124
134
|
while (startIndex <= end - sequenceLength) {
|
|
125
135
|
let lastIndex = sequenceLength - 1;
|
|
126
|
-
|
|
127
|
-
while (lastIndex >= 0 && this[lastIndex] === haystack[startIndex + lastIndex]) {
|
|
136
|
+
while (lastIndex >= 0 && this[lastIndex] === haystack[startIndex + lastIndex])
|
|
128
137
|
lastIndex--;
|
|
129
|
-
}
|
|
130
|
-
// Pattern found
|
|
131
138
|
if (lastIndex < 0)
|
|
132
139
|
return startIndex;
|
|
133
|
-
// Jump based on the last character in the window
|
|
134
140
|
startIndex += this.#skipIndex[haystack[startIndex + sequenceLength - 1]];
|
|
135
141
|
}
|
|
136
142
|
return -1;
|
|
137
143
|
}
|
|
138
|
-
|
|
139
|
-
|
|
144
|
+
searchAll(haystack, start = 0, end = haystack.length) {
|
|
145
|
+
const sequenceLength = this.length;
|
|
146
|
+
const haystackLen = end - start;
|
|
147
|
+
if (sequenceLength >= 1 && haystackLen >= WASM_THRESHOLD) {
|
|
148
|
+
const wasm = CharacterSequence.#wasmScanner;
|
|
149
|
+
if (wasm) {
|
|
150
|
+
const resultsOffset = alignTo4(haystackLen + sequenceLength);
|
|
151
|
+
const resultsSize = WASM_MAX_RESULTS * 2 * 4;
|
|
152
|
+
const totalNeeded = resultsOffset + resultsSize;
|
|
153
|
+
ensureWasmCapacity(wasm.memory, totalNeeded);
|
|
154
|
+
const buffer = new Uint8Array(wasm.memory.buffer, 0, totalNeeded);
|
|
155
|
+
buffer.set(haystack.subarray(start, end), 0);
|
|
156
|
+
buffer.set(this, haystackLen);
|
|
157
|
+
// We just overwrote offset 0; any haystack search() cached there is now stale.
|
|
158
|
+
CharacterSequence.#wasmHaystack = null;
|
|
159
|
+
const count = wasm.findAllDelimiters(0, haystackLen, haystackLen, sequenceLength, resultsOffset, WASM_MAX_RESULTS);
|
|
160
|
+
const rv = new Int32Array(wasm.memory.buffer, resultsOffset, count * 2);
|
|
161
|
+
const ranges = [];
|
|
162
|
+
for (let i = 0; i < count; i++)
|
|
163
|
+
ranges.push([start + rv[i * 2], start + rv[i * 2 + 1]]);
|
|
164
|
+
// A full results buffer means the scan may have hit the cap and dropped
|
|
165
|
+
// trailing delimiters; fall back to the uncapped JS scan rather than truncate.
|
|
166
|
+
if (count < WASM_MAX_RESULTS)
|
|
167
|
+
return ranges;
|
|
168
|
+
}
|
|
169
|
+
if (CharacterSequence.#wasmScanner === undefined)
|
|
170
|
+
CharacterSequence.#ensureWasm();
|
|
171
|
+
}
|
|
172
|
+
const ranges = [];
|
|
173
|
+
let searchStart = start, rangeStart = start;
|
|
174
|
+
while (searchStart <= end - sequenceLength) {
|
|
175
|
+
let lastIndex = sequenceLength - 1;
|
|
176
|
+
while (lastIndex >= 0 && this[lastIndex] === haystack[searchStart + lastIndex])
|
|
177
|
+
lastIndex--;
|
|
178
|
+
if (lastIndex < 0) {
|
|
179
|
+
ranges.push([rangeStart, searchStart]);
|
|
180
|
+
searchStart += sequenceLength;
|
|
181
|
+
rangeStart = searchStart;
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
searchStart += this.#skipIndex[haystack[searchStart + sequenceLength - 1]];
|
|
185
|
+
}
|
|
186
|
+
if (rangeStart <= end)
|
|
187
|
+
ranges.push([rangeStart, end]);
|
|
188
|
+
return ranges;
|
|
140
189
|
}
|
|
141
190
|
/**
|
|
142
|
-
*
|
|
191
|
+
* Scan for two patterns simultaneously (delimiter + quote) for CSV parsing.
|
|
192
|
+
*
|
|
193
|
+
* Returns sorted MatchResult[] with patternId 0=delimiter, 1=quote. Uses WASM SIMD double-scan when available; JS
|
|
194
|
+
* fallback otherwise.
|
|
143
195
|
*/
|
|
196
|
+
searchMatches(haystack, quotePattern, start = 0, end = haystack.length) {
|
|
197
|
+
const delimiterLen = this.length;
|
|
198
|
+
const quoteLen = quotePattern.length;
|
|
199
|
+
const haystackLen = end - start;
|
|
200
|
+
if (delimiterLen === 0 || haystackLen === 0)
|
|
201
|
+
return [];
|
|
202
|
+
const wasm = CharacterSequence.#wasmScanner;
|
|
203
|
+
if (wasm && haystackLen >= WASM_THRESHOLD) {
|
|
204
|
+
const patternsSize = delimiterLen + quoteLen;
|
|
205
|
+
const resultsOffset = alignTo4(haystackLen + patternsSize);
|
|
206
|
+
const resultsSize = WASM_MAX_RESULTS * 2 * 4;
|
|
207
|
+
const totalNeeded = resultsOffset + resultsSize;
|
|
208
|
+
ensureWasmCapacity(wasm.memory, totalNeeded);
|
|
209
|
+
const buffer = new Uint8Array(wasm.memory.buffer, 0, totalNeeded);
|
|
210
|
+
buffer.set(haystack.subarray(start, end), 0);
|
|
211
|
+
buffer.set(this, haystackLen);
|
|
212
|
+
buffer.set(quotePattern, haystackLen + delimiterLen);
|
|
213
|
+
// We just overwrote offset 0; any haystack search() cached there is now stale.
|
|
214
|
+
CharacterSequence.#wasmHaystack = null;
|
|
215
|
+
const count = wasm.findAllMatches(0, haystackLen, haystackLen, delimiterLen, quoteLen, resultsOffset, WASM_MAX_RESULTS);
|
|
216
|
+
const rv = new Int32Array(wasm.memory.buffer, resultsOffset, count * 2);
|
|
217
|
+
const matches = [];
|
|
218
|
+
for (let i = 0; i < count; i++)
|
|
219
|
+
matches.push({ offset: start + rv[i * 2], patternId: rv[i * 2 + 1] });
|
|
220
|
+
// A full results buffer means the scan may have hit the cap and dropped
|
|
221
|
+
// trailing matches; fall back to the uncapped JS scan rather than truncate.
|
|
222
|
+
if (count < WASM_MAX_RESULTS)
|
|
223
|
+
return matches;
|
|
224
|
+
}
|
|
225
|
+
if (CharacterSequence.#wasmScanner === undefined)
|
|
226
|
+
CharacterSequence.#ensureWasm();
|
|
227
|
+
// JS fallback: scan both patterns independently and merge in offset order. Both
|
|
228
|
+
// searches honour `end` exclusivity and handle multi-byte patterns (the quote is
|
|
229
|
+
// wrapped in a CharacterSequence so it isn't limited to a single byte).
|
|
230
|
+
const matches = [];
|
|
231
|
+
const quoteSeq = new CharacterSequence(quotePattern);
|
|
232
|
+
let searchStart = start;
|
|
233
|
+
while (searchStart <= end) {
|
|
234
|
+
const delimIdx = this.search(haystack, searchStart, end);
|
|
235
|
+
const quoteIdx = quoteSeq.search(haystack, searchStart, end);
|
|
236
|
+
if (delimIdx < 0 && quoteIdx < 0)
|
|
237
|
+
break;
|
|
238
|
+
if (delimIdx >= 0 && (quoteIdx < 0 || delimIdx <= quoteIdx)) {
|
|
239
|
+
matches.push({ offset: delimIdx, patternId: 0 });
|
|
240
|
+
searchStart = delimIdx + delimiterLen;
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
matches.push({ offset: quoteIdx, patternId: 1 });
|
|
244
|
+
searchStart = quoteIdx + quoteLen;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
return matches;
|
|
248
|
+
}
|
|
249
|
+
decode(encoding = "utf-8") {
|
|
250
|
+
return new TextDecoder(encoding).decode(this);
|
|
251
|
+
}
|
|
144
252
|
constructor(input = Delimiters.LineFeed) {
|
|
145
253
|
const bytes = normalizeCharacterInput(input);
|
|
146
254
|
super(bytes);
|
|
147
|
-
this.#skipIndex =
|
|
148
|
-
|
|
149
|
-
for (let i = 0; i < this.length - 1; i++) {
|
|
255
|
+
this.#skipIndex = Array.from({ length: 256 }, () => this.length);
|
|
256
|
+
for (let i = 0; i < this.length - 1; i++)
|
|
150
257
|
this.#skipIndex[this[i]] = this.length - 1 - i;
|
|
151
|
-
}
|
|
152
258
|
}
|
|
153
259
|
}
|
|
154
260
|
//# sourceMappingURL=CharacterSequence.js.map
|