@ssttevee/streamsearch 0.3.1 → 0.4.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 +57 -2
- package/lib/index.cjs +29 -265
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.ts +13 -10
- package/lib/index.mjs +21 -301
- package/lib/index.mjs.map +1 -1
- package/lib/iterate-chunks-concatted.cjs +15 -0
- package/lib/iterate-chunks-concatted.cjs.map +1 -0
- package/lib/iterate-chunks-concatted.d.ts +2 -0
- package/lib/iterate-chunks-concatted.mjs +13 -0
- package/lib/iterate-chunks-concatted.mjs.map +1 -0
- package/lib/iterate-chunks.cjs +22 -0
- package/lib/iterate-chunks.cjs.map +1 -0
- package/lib/iterate-chunks.d.ts +2 -0
- package/lib/iterate-chunks.mjs +20 -0
- package/lib/iterate-chunks.mjs.map +1 -0
- package/lib/iterate-strings.cjs +16 -0
- package/lib/iterate-strings.cjs.map +1 -0
- package/lib/iterate-strings.d.ts +2 -0
- package/lib/iterate-strings.mjs +14 -0
- package/lib/iterate-strings.mjs.map +1 -0
- package/lib/iterator.cjs +42 -0
- package/lib/iterator.cjs.map +1 -0
- package/lib/iterator.d.ts +7 -0
- package/lib/iterator.mjs +40 -0
- package/lib/iterator.mjs.map +1 -0
- package/lib/queueable.cjs +55 -0
- package/lib/queueable.cjs.map +1 -0
- package/lib/queueable.d.ts +11 -11
- package/lib/queueable.mjs +53 -0
- package/lib/queueable.mjs.map +1 -0
- package/lib/readable.cjs +36 -0
- package/lib/readable.cjs.map +1 -0
- package/lib/readable.d.ts +7 -7
- package/lib/readable.mjs +34 -0
- package/lib/readable.mjs.map +1 -0
- package/lib/search-BXQkEs3p.js +97 -0
- package/lib/search-BXQkEs3p.js.map +1 -0
- package/lib/search-D_ihawrM.js +108 -0
- package/lib/search-D_ihawrM.js.map +1 -0
- package/lib/search.cjs +188 -0
- package/lib/search.cjs.map +1 -0
- package/lib/search.d.ts +13 -14
- package/lib/search.mjs +185 -0
- package/lib/search.mjs.map +1 -0
- package/lib/split.cjs +26 -0
- package/lib/split.cjs.map +1 -0
- package/lib/split.d.ts +1 -0
- package/lib/split.mjs +24 -0
- package/lib/split.mjs.map +1 -0
- package/package.json +85 -37
- package/lib/index.js +0 -318
- package/lib/index.js.map +0 -1
package/lib/search.mjs
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { concat } from 'uint8arrays/concat';
|
|
2
|
+
import { fromString } from 'uint8arrays/from-string';
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
Based heavily on the Streaming Boyer-Moore-Horspool C++ implementation
|
|
6
|
+
by Hongli Lai at: https://github.com/FooBarWidget/boyer-moore-horspool
|
|
7
|
+
*/
|
|
8
|
+
function jsmemcmp(buf1, pos1, buf2, pos2, len) {
|
|
9
|
+
for (let i = 0; i < len; i++) {
|
|
10
|
+
if (buf1[pos1 + i] !== buf2[pos2 + i]) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
function createOccurenceTable(s) {
|
|
17
|
+
// Populate occurrence table with analysis of the needle,
|
|
18
|
+
// ignoring last letter.
|
|
19
|
+
const table = new Array(256).fill(s.length);
|
|
20
|
+
if (s.length > 1) {
|
|
21
|
+
for (let i = 0; i < s.length - 1; i++) {
|
|
22
|
+
table[s[i]] = s.length - 1 - i;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return table;
|
|
26
|
+
}
|
|
27
|
+
const MATCH = Symbol("Match");
|
|
28
|
+
class StreamSearch {
|
|
29
|
+
_needle;
|
|
30
|
+
_lastChar;
|
|
31
|
+
_occ;
|
|
32
|
+
_lookbehind = new Uint8Array();
|
|
33
|
+
constructor(needle) {
|
|
34
|
+
if (typeof needle === "string") {
|
|
35
|
+
this._needle = needle = fromString(needle);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
this._needle = needle;
|
|
39
|
+
}
|
|
40
|
+
this._lastChar = needle[needle.length - 1];
|
|
41
|
+
this._occ = createOccurenceTable(needle);
|
|
42
|
+
}
|
|
43
|
+
feed(chunk) {
|
|
44
|
+
let pos = 0;
|
|
45
|
+
let tokens;
|
|
46
|
+
const allTokens = [];
|
|
47
|
+
while (pos !== chunk.length) {
|
|
48
|
+
[pos, ...tokens] = this._feed(chunk, pos);
|
|
49
|
+
allTokens.push(...tokens);
|
|
50
|
+
}
|
|
51
|
+
return allTokens;
|
|
52
|
+
}
|
|
53
|
+
end() {
|
|
54
|
+
const tail = this._lookbehind;
|
|
55
|
+
this._lookbehind = new Uint8Array();
|
|
56
|
+
return tail;
|
|
57
|
+
}
|
|
58
|
+
_feed(data, buf_pos) {
|
|
59
|
+
const tokens = [];
|
|
60
|
+
// Positive: points to a position in `data`
|
|
61
|
+
// pos == 3 points to data[3]
|
|
62
|
+
// Negative: points to a position in the lookbehind buffer
|
|
63
|
+
// pos == -2 points to lookbehind[lookbehind_size - 2]
|
|
64
|
+
let pos = -this._lookbehind.length;
|
|
65
|
+
if (pos < 0) {
|
|
66
|
+
// Lookbehind buffer is not empty. Perform Boyer-Moore-Horspool
|
|
67
|
+
// search with character lookup code that considers both the
|
|
68
|
+
// lookbehind buffer and the current round's haystack data.
|
|
69
|
+
//
|
|
70
|
+
// Loop until (condition 1)
|
|
71
|
+
// there is a match.
|
|
72
|
+
// or until
|
|
73
|
+
// we've moved past the position that requires the
|
|
74
|
+
// lookbehind buffer. In this case we switch to the
|
|
75
|
+
// optimized loop.
|
|
76
|
+
// or until (condition 3)
|
|
77
|
+
// the character to look at lies outside the haystack.
|
|
78
|
+
while (pos < 0 && pos <= data.length - this._needle.length) {
|
|
79
|
+
const cpos = pos + this._needle.length - 1;
|
|
80
|
+
const ch = cpos < 0
|
|
81
|
+
? this._lookbehind[this._lookbehind.length + cpos]
|
|
82
|
+
: data[cpos];
|
|
83
|
+
if (ch === this._lastChar &&
|
|
84
|
+
this._memcmp(data, pos, this._needle.length - 1)) {
|
|
85
|
+
if (pos > -this._lookbehind.length) {
|
|
86
|
+
tokens.push(this._lookbehind.subarray(0, this._lookbehind.length + pos));
|
|
87
|
+
}
|
|
88
|
+
tokens.push(MATCH);
|
|
89
|
+
this._lookbehind = new Uint8Array();
|
|
90
|
+
return [pos + this._needle.length, ...tokens];
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
pos += this._occ[ch];
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
// No match.
|
|
97
|
+
if (pos < 0) {
|
|
98
|
+
// There's too little data for Boyer-Moore-Horspool to run,
|
|
99
|
+
// so we'll use a different algorithm to skip as much as
|
|
100
|
+
// we can.
|
|
101
|
+
// Forward pos until
|
|
102
|
+
// the trailing part of lookbehind + data
|
|
103
|
+
// looks like the beginning of the needle
|
|
104
|
+
// or until
|
|
105
|
+
// pos == 0
|
|
106
|
+
while (pos < 0 && !this._memcmp(data, pos, data.length - pos)) {
|
|
107
|
+
pos++;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (pos >= 0) {
|
|
111
|
+
// Discard lookbehind buffer.
|
|
112
|
+
tokens.push(this._lookbehind);
|
|
113
|
+
this._lookbehind = new Uint8Array();
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
// Cut off part of the lookbehind buffer that has
|
|
117
|
+
// been processed and append the entire haystack
|
|
118
|
+
// into it.
|
|
119
|
+
const bytesToCutOff = this._lookbehind.length + pos;
|
|
120
|
+
if (bytesToCutOff > 0) {
|
|
121
|
+
// The cut off data is guaranteed not to contain the needle.
|
|
122
|
+
tokens.push(this._lookbehind.subarray(0, bytesToCutOff));
|
|
123
|
+
this._lookbehind = this._lookbehind.subarray(bytesToCutOff);
|
|
124
|
+
}
|
|
125
|
+
this._lookbehind = concat([this._lookbehind, data]);
|
|
126
|
+
return [data.length, ...tokens];
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
pos += buf_pos;
|
|
130
|
+
// Lookbehind buffer is now empty. Perform Boyer-Moore-Horspool
|
|
131
|
+
// search with optimized character lookup code that only considers
|
|
132
|
+
// the current round's haystack data.
|
|
133
|
+
while (pos <= data.length - this._needle.length) {
|
|
134
|
+
const ch = data[pos + this._needle.length - 1];
|
|
135
|
+
if (ch === this._lastChar &&
|
|
136
|
+
data[pos] === this._needle[0] &&
|
|
137
|
+
jsmemcmp(this._needle, 0, data, pos, this._needle.length - 1)) {
|
|
138
|
+
if (pos > buf_pos) {
|
|
139
|
+
tokens.push(data.subarray(buf_pos, pos));
|
|
140
|
+
}
|
|
141
|
+
tokens.push(MATCH);
|
|
142
|
+
return [pos + this._needle.length, ...tokens];
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
pos += this._occ[ch];
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
// There was no match. If there's trailing haystack data that we cannot
|
|
149
|
+
// match yet using the Boyer-Moore-Horspool algorithm (because the trailing
|
|
150
|
+
// data is less than the needle size) then match using a modified
|
|
151
|
+
// algorithm that starts matching from the beginning instead of the end.
|
|
152
|
+
// Whatever trailing data is left after running this algorithm is added to
|
|
153
|
+
// the lookbehind buffer.
|
|
154
|
+
if (pos < data.length) {
|
|
155
|
+
while (pos < data.length &&
|
|
156
|
+
(data[pos] !== this._needle[0] ||
|
|
157
|
+
!jsmemcmp(data, pos, this._needle, 0, data.length - pos))) {
|
|
158
|
+
++pos;
|
|
159
|
+
}
|
|
160
|
+
if (pos < data.length) {
|
|
161
|
+
this._lookbehind = data.subarray(pos);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
// Everything until pos is guaranteed not to contain needle data.
|
|
165
|
+
if (pos > 0) {
|
|
166
|
+
tokens.push(data.subarray(buf_pos, pos < data.length ? pos : data.length));
|
|
167
|
+
}
|
|
168
|
+
return [data.length, ...tokens];
|
|
169
|
+
}
|
|
170
|
+
_memcmp(data, pos, len) {
|
|
171
|
+
if (pos < 0) {
|
|
172
|
+
if (!jsmemcmp(this._lookbehind, this._lookbehind.length + pos, this._needle, 0, Math.min(-pos, len))) {
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
if (len < -pos) {
|
|
176
|
+
return true;
|
|
177
|
+
}
|
|
178
|
+
len += pos;
|
|
179
|
+
}
|
|
180
|
+
return jsmemcmp(data, Math.max(0, pos), this._needle, -Math.min(0, pos), len);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export { MATCH, StreamSearch };
|
|
185
|
+
//# sourceMappingURL=search.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.mjs","sources":["../src/search.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AAAA;;;AAGE;AAKF,SAAS,QAAQ,CAChB,IAAgB,EAChB,IAAY,EACZ,IAAgB,EAChB,IAAY,EACZ,GAAW,EAAA;AAEX,IAAA,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE,EAAE;AAC7B,QAAA,IAAI,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,KAAK,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,EAAE;AACtC,YAAA,OAAO,KAAK;QACb;IACD;AAEA,IAAA,OAAO,IAAI;AACZ;AAEA,SAAS,oBAAoB,CAAC,CAAa,EAAA;;;AAG1C,IAAA,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC;AAC3C,IAAA,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;AACjB,QAAA,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE;AACtC,YAAA,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC,GAAG,CAAC;QAC/B;IACD;AAEA,IAAA,O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,GAAG,EAC7B,IAAI,CAAC,OAAO,EACZ,CAAC,EACD,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,CACnB,EACA;AACD,gBAAA,OAAO,KAAK;YACb;AAEA,YAAA,IAAI,GAAG,GAAG,CAAC,GAAG,EAAE;AACf,gBAAA,OAAO,IAAI;YACZ;YAEA,GAAG,IAAI,GAAG;QACX;AAEA,QAAA,OAAO,QAAQ,CACd,IAAI,EACJ,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,EAChB,IAAI,CAAC,OAAO,EACZ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,EACjB,GAAG,CACH;IACF;AACA;;;;"}
|
package/lib/split.cjs
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var concat = require('uint8arrays/concat');
|
|
4
|
+
var search = require('./search.cjs');
|
|
5
|
+
require('uint8arrays/from-string');
|
|
6
|
+
|
|
7
|
+
function split(chunks, needle) {
|
|
8
|
+
const search$1 = new search.StreamSearch(needle);
|
|
9
|
+
const outchunks = [[]];
|
|
10
|
+
for (const chunk of Array.isArray(chunks) ? chunks : [chunks]) {
|
|
11
|
+
for (const token of search$1.feed(chunk)) {
|
|
12
|
+
if (token === search.MATCH) {
|
|
13
|
+
outchunks.push([]);
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
outchunks[outchunks.length - 1].push(token);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const end = search$1.end();
|
|
21
|
+
outchunks[outchunks.length - 1].push(end);
|
|
22
|
+
return outchunks.map((chunks) => concat.concat(chunks));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
exports.split = split;
|
|
26
|
+
//# sourceMappingURL=split.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"split.cjs","sources":["../src/split.ts"],"sourcesContent":[null],"names":["search","StreamSearch","MATCH","concat"],"mappings":";;;;;;AAIM,SAAU,KAAK,CACpB,MAAiC,EACjC,MAA2B,EAAA;AAE3B,IAAA,MAAMA,QAAM,GAAG,IAAIC,mBAAY,CAAC,MAAM,CAAC;AAEvC,IAAA,MAAM,SAAS,GAAmB,CAAC,EAAE,CAAC;IACtC,KAAK,MAAM,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,GAAG,CAAC,MAAM,CAAC,EAAE;QAC9D,KAAK,MAAM,KAAK,IAAID,QAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;AACvC,YAAA,IAAI,KAAK,KAAKE,YAAK,EAAE;AACpB,gBAAA,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;YACnB;iBAAO;AACN,gBAAA,SAAS,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC;YAC5C;QACD;IACD;AAEA,IAAA,MAAM,GAAG,GAAGF,QAAM,CAAC,GAAG,EAAE;AACxB,IAAA,SAAS,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;AAEzC,IAAA,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC,MAAM,KAAKG,aAAM,CAAC,MAAM,CAAC,CAAC;AACjD;;;;"}
|
package/lib/split.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function split(chunks: Uint8Array | Uint8Array[], needle: Uint8Array | string): Uint8Array[];
|
package/lib/split.mjs
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { concat } from 'uint8arrays/concat';
|
|
2
|
+
import { StreamSearch, MATCH } from './search.mjs';
|
|
3
|
+
import 'uint8arrays/from-string';
|
|
4
|
+
|
|
5
|
+
function split(chunks, needle) {
|
|
6
|
+
const search = new StreamSearch(needle);
|
|
7
|
+
const outchunks = [[]];
|
|
8
|
+
for (const chunk of Array.isArray(chunks) ? chunks : [chunks]) {
|
|
9
|
+
for (const token of search.feed(chunk)) {
|
|
10
|
+
if (token === MATCH) {
|
|
11
|
+
outchunks.push([]);
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
outchunks[outchunks.length - 1].push(token);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
const end = search.end();
|
|
19
|
+
outchunks[outchunks.length - 1].push(end);
|
|
20
|
+
return outchunks.map((chunks) => concat(chunks));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { split };
|
|
24
|
+
//# sourceMappingURL=split.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"split.mjs","sources":["../src/split.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAIM,SAAU,KAAK,CACpB,MAAiC,EACjC,MAA2B,EAAA;AAE3B,IAAA,MAAM,MAAM,GAAG,IAAI,YAAY,CAAC,MAAM,CAAC;AAEvC,IAAA,MAAM,SAAS,GAAmB,CAAC,EAAE,CAAC;IACtC,KAAK,MAAM,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,GAAG,CAAC,MAAM,CAAC,EAAE;QAC9D,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;AACvC,YAAA,IAAI,KAAK,KAAK,KAAK,EAAE;AACpB,gBAAA,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;YACnB;iBAAO;AACN,gBAAA,SAAS,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC;YAC5C;QACD;IACD;AAEA,IAAA,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,EAAE;AACxB,IAAA,SAAS,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;AAEzC,IAAA,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC;AACjD;;;;"}
|
package/package.json
CHANGED
|
@@ -1,39 +1,87 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
2
|
+
"name": "@ssttevee/streamsearch",
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "A port of streamsearch for es modules using Web APIs",
|
|
6
|
+
"main": "lib/index.js",
|
|
7
|
+
"module": "lib/index.mjs",
|
|
8
|
+
"source": "src/index.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"lib/**/*"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"test": "tap run",
|
|
14
|
+
"coverage": "npm run test -- --coverage-report=lcov --coverage-report=text",
|
|
15
|
+
"fuzz": "ts-node testing/fuzz.ts",
|
|
16
|
+
"build": "rollup -c && tsc -d --emitDeclarationOnly --declarationDir lib",
|
|
17
|
+
"prepack": "npm run build"
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/ssttevee/js-streamsearch"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [],
|
|
24
|
+
"author": "ssttevee",
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@biomejs/biome": "^2.3.13",
|
|
28
|
+
"@rollup/plugin-typescript": "^12.3.0",
|
|
29
|
+
"@types/tap": "^18.0.0",
|
|
30
|
+
"esm": "^3.2.25",
|
|
31
|
+
"rollup": "^4.57.0",
|
|
32
|
+
"tap": "^21.5.0",
|
|
33
|
+
"ts-node": "^10.9.2",
|
|
34
|
+
"tslib": "^2.8.1",
|
|
35
|
+
"typescript": "^5.9.3"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"uint8arrays": "^5.1.0"
|
|
39
|
+
},
|
|
40
|
+
"exports": {
|
|
41
|
+
".": {
|
|
42
|
+
"import": "./lib/index.mjs",
|
|
43
|
+
"require": "./lib/index.cjs",
|
|
44
|
+
"types": "./lib/index.d.ts"
|
|
45
|
+
},
|
|
46
|
+
"./iterate-chunks": {
|
|
47
|
+
"import": "./lib/iterate-chunks.mjs",
|
|
48
|
+
"require": "./lib/iterate-chunks.cjs",
|
|
49
|
+
"types": "./lib/iterate-chunks.d.ts"
|
|
50
|
+
},
|
|
51
|
+
"./iterate-chunks-concatted": {
|
|
52
|
+
"import": "./lib/iterate-chunks-concatted.mjs",
|
|
53
|
+
"require": "./lib/iterate-chunks-concatted.cjs",
|
|
54
|
+
"types": "./lib/iterate-chunks-concatted.d.ts"
|
|
55
|
+
},
|
|
56
|
+
"./iterate-strings": {
|
|
57
|
+
"import": "./lib/iterate-strings.mjs",
|
|
58
|
+
"require": "./lib/iterate-strings.cjs",
|
|
59
|
+
"types": "./lib/iterate-strings.d.ts"
|
|
60
|
+
},
|
|
61
|
+
"./iterator": {
|
|
62
|
+
"import": "./lib/iterator.mjs",
|
|
63
|
+
"require": "./lib/iterator.cjs",
|
|
64
|
+
"types": "./lib/iterator.d.ts"
|
|
65
|
+
},
|
|
66
|
+
"./queuable": {
|
|
67
|
+
"import": "./lib/queuable.mjs",
|
|
68
|
+
"require": "./lib/queuable.cjs",
|
|
69
|
+
"types": "./lib/queuable.d.ts"
|
|
70
|
+
},
|
|
71
|
+
"./readable": {
|
|
72
|
+
"import": "./lib/readable.mjs",
|
|
73
|
+
"require": "./lib/readable.cjs",
|
|
74
|
+
"types": "./lib/readable.d.ts"
|
|
75
|
+
},
|
|
76
|
+
"./search": {
|
|
77
|
+
"import": "./lib/search.mjs",
|
|
78
|
+
"require": "./lib/search.cjs",
|
|
79
|
+
"types": "./lib/search.d.ts"
|
|
80
|
+
},
|
|
81
|
+
"./split": {
|
|
82
|
+
"import": "./lib/split.mjs",
|
|
83
|
+
"require": "./lib/split.cjs",
|
|
84
|
+
"types": "./lib/split.d.ts"
|
|
85
|
+
}
|
|
86
|
+
}
|
|
39
87
|
}
|