foxts 1.6.0 → 1.7.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.
@@ -1 +1 @@
1
- "use strict";const e=/[$()*+.?[\\\]^{|}-]/g,t={"\\":"\\\\","^":"\\^",$:"\\$",".":"\\.","*":"\\*","+":"\\+","?":"\\?","(":"\\(",")":"\\)","[":"\\[","]":"\\]","{":"\\{","}":"\\}","|":"\\|","-":"\\x2d"},r=e=>t[e];exports.escapeStringRegexp=function(t){return t.replaceAll(e,r)};
1
+ "use strict";const e=/[$()*+.?[\\\]^{|}-]/;exports.escapeStringRegexp=function(a){const c=e.exec(a);if(null===c)return a;let s="",r="",t=c.index,b=0;for(const e=a.length;t<e;t++){switch(a.charCodeAt(t)){case 92:s="\\\\";break;case 94:s="\\^";break;case 36:s="\\$";break;case 46:s="\\.";break;case 42:s="\\*";break;case 43:s="\\+";break;case 63:s="\\?";break;case 40:s="\\(";break;case 41:s="\\)";break;case 91:s="\\[";break;case 93:s="\\]";break;case 123:s="\\{";break;case 125:s="\\}";break;case 124:s="\\|";break;case 45:s="\\x2d";break;default:continue}b!==t&&(r+=a.slice(b,t)),b=t+1,r+=s}return b===t?r:r+a.slice(b,t)};
@@ -1,3 +1,7 @@
1
- declare function escapeStringRegexp(string: string): string;
1
+ /**
2
+ * Escape characters with special meaning either inside or outside character sets.
3
+ * Use a simple backslash escape when it’s always valid, and a `\xnn` escape when the simpler form would be disallowed by Unicode patterns’ stricter grammar.
4
+ */
5
+ declare function escapeStringRegexp(str: string): string;
2
6
 
3
7
  export { escapeStringRegexp };
@@ -1 +1 @@
1
- const e=/[$()*+.?[\\\]^{|}-]/g,n={"\\":"\\\\","^":"\\^",$:"\\$",".":"\\.","*":"\\*","+":"\\+","?":"\\?","(":"\\(",")":"\\)","[":"\\[","]":"\\]","{":"\\{","}":"\\}","|":"\\|","-":"\\x2d"},r=e=>n[e];function t(n){return n.replaceAll(e,r)}export{t as escapeStringRegexp};
1
+ const e=/[$()*+.?[\\\]^{|}-]/;function a(a){const c=e.exec(a);if(null===c)return a;let r="",s="",b=c.index,k=0;for(const e=a.length;b<e;b++){switch(a.charCodeAt(b)){case 92:r="\\\\";break;case 94:r="\\^";break;case 36:r="\\$";break;case 46:r="\\.";break;case 42:r="\\*";break;case 43:r="\\+";break;case 63:r="\\?";break;case 40:r="\\(";break;case 41:r="\\)";break;case 91:r="\\[";break;case 93:r="\\]";break;case 123:r="\\{";break;case 125:r="\\}";break;case 124:r="\\|";break;case 45:r="\\x2d";break;default:continue}k!==b&&(s+=a.slice(k,b)),k=b+1,s+=r}return k===b?s:s+a.slice(k,b)}export{a as escapeStringRegexp};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foxts",
3
- "version": "1.6.0",
3
+ "version": "1.7.0",
4
4
  "description": "Opinionated collection of common TypeScript utils by @SukkaW",
5
5
  "repository": {
6
6
  "url": "https://github.com/SukkaW/foxts"
@@ -41,15 +41,6 @@
41
41
  "require": "./add-array-elements-to-set/index.cjs",
42
42
  "default": "./add-array-elements-to-set/index.cjs"
43
43
  },
44
- "./ahocorasick": {
45
- "types": "./ahocorasick/index.d.ts",
46
- "import": {
47
- "types": "./ahocorasick/index.d.ts",
48
- "default": "./ahocorasick/index.mjs"
49
- },
50
- "require": "./ahocorasick/index.cjs",
51
- "default": "./ahocorasick/index.cjs"
52
- },
53
44
  "./async-write-to-stream": {
54
45
  "types": "./async-write-to-stream/index.d.ts",
55
46
  "import": {
@@ -59,6 +50,24 @@
59
50
  "require": "./async-write-to-stream/index.cjs",
60
51
  "default": "./async-write-to-stream/index.cjs"
61
52
  },
53
+ "./append-set-elements-to-array": {
54
+ "types": "./append-set-elements-to-array/index.d.ts",
55
+ "import": {
56
+ "types": "./append-set-elements-to-array/index.d.ts",
57
+ "default": "./append-set-elements-to-array/index.mjs"
58
+ },
59
+ "require": "./append-set-elements-to-array/index.cjs",
60
+ "default": "./append-set-elements-to-array/index.cjs"
61
+ },
62
+ "./bitwise": {
63
+ "types": "./bitwise/index.d.ts",
64
+ "import": {
65
+ "types": "./bitwise/index.d.ts",
66
+ "default": "./bitwise/index.mjs"
67
+ },
68
+ "require": "./bitwise/index.cjs",
69
+ "default": "./bitwise/index.cjs"
70
+ },
62
71
  "./create-fixed-array": {
63
72
  "types": "./create-fixed-array/index.d.ts",
64
73
  "import": {
@@ -77,23 +86,14 @@
77
86
  "require": "./detect-eol/index.cjs",
78
87
  "default": "./detect-eol/index.cjs"
79
88
  },
80
- "./append-set-elements-to-array": {
81
- "types": "./append-set-elements-to-array/index.d.ts",
82
- "import": {
83
- "types": "./append-set-elements-to-array/index.d.ts",
84
- "default": "./append-set-elements-to-array/index.mjs"
85
- },
86
- "require": "./append-set-elements-to-array/index.cjs",
87
- "default": "./append-set-elements-to-array/index.cjs"
88
- },
89
- "./bitwise": {
90
- "types": "./bitwise/index.d.ts",
89
+ "./ahocorasick": {
90
+ "types": "./ahocorasick/index.d.ts",
91
91
  "import": {
92
- "types": "./bitwise/index.d.ts",
93
- "default": "./bitwise/index.mjs"
92
+ "types": "./ahocorasick/index.d.ts",
93
+ "default": "./ahocorasick/index.mjs"
94
94
  },
95
- "require": "./bitwise/index.cjs",
96
- "default": "./bitwise/index.cjs"
95
+ "require": "./ahocorasick/index.cjs",
96
+ "default": "./ahocorasick/index.cjs"
97
97
  },
98
98
  "./escape-html": {
99
99
  "types": "./escape-html/index.d.ts",
@@ -104,6 +104,15 @@
104
104
  "require": "./escape-html/index.cjs",
105
105
  "default": "./escape-html/index.cjs"
106
106
  },
107
+ "./escape-string-regexp": {
108
+ "types": "./escape-string-regexp/index.d.ts",
109
+ "import": {
110
+ "types": "./escape-string-regexp/index.d.ts",
111
+ "default": "./escape-string-regexp/index.mjs"
112
+ },
113
+ "require": "./escape-string-regexp/index.cjs",
114
+ "default": "./escape-string-regexp/index.cjs"
115
+ },
107
116
  "./fast-string-array-join": {
108
117
  "types": "./fast-string-array-join/index.d.ts",
109
118
  "import": {
@@ -140,24 +149,6 @@
140
149
  "require": "./fnv1a52/index.cjs",
141
150
  "default": "./fnv1a52/index.cjs"
142
151
  },
143
- "./escape-string-regexp": {
144
- "types": "./escape-string-regexp/index.d.ts",
145
- "import": {
146
- "types": "./escape-string-regexp/index.d.ts",
147
- "default": "./escape-string-regexp/index.mjs"
148
- },
149
- "require": "./escape-string-regexp/index.cjs",
150
- "default": "./escape-string-regexp/index.cjs"
151
- },
152
- "./identity": {
153
- "types": "./identity/index.d.ts",
154
- "import": {
155
- "types": "./identity/index.d.ts",
156
- "default": "./identity/index.mjs"
157
- },
158
- "require": "./identity/index.cjs",
159
- "default": "./identity/index.cjs"
160
- },
161
152
  "./guard": {
162
153
  "types": "./guard/index.d.ts",
163
154
  "import": {
@@ -176,14 +167,14 @@
176
167
  "require": "./headers-to-object/index.cjs",
177
168
  "default": "./headers-to-object/index.cjs"
178
169
  },
179
- "./noop": {
180
- "types": "./noop/index.d.ts",
170
+ "./identity": {
171
+ "types": "./identity/index.d.ts",
181
172
  "import": {
182
- "types": "./noop/index.d.ts",
183
- "default": "./noop/index.mjs"
173
+ "types": "./identity/index.d.ts",
174
+ "default": "./identity/index.mjs"
184
175
  },
185
- "require": "./noop/index.cjs",
186
- "default": "./noop/index.cjs"
176
+ "require": "./identity/index.cjs",
177
+ "default": "./identity/index.cjs"
187
178
  },
188
179
  "./is-probably-ip": {
189
180
  "types": "./is-probably-ip/index.d.ts",
@@ -203,14 +194,14 @@
203
194
  "require": "./merge-headers/index.cjs",
204
195
  "default": "./merge-headers/index.cjs"
205
196
  },
206
- "./pick-random": {
207
- "types": "./pick-random/index.d.ts",
197
+ "./noop": {
198
+ "types": "./noop/index.d.ts",
208
199
  "import": {
209
- "types": "./pick-random/index.d.ts",
210
- "default": "./pick-random/index.mjs"
200
+ "types": "./noop/index.d.ts",
201
+ "default": "./noop/index.mjs"
211
202
  },
212
- "require": "./pick-random/index.cjs",
213
- "default": "./pick-random/index.cjs"
203
+ "require": "./noop/index.cjs",
204
+ "default": "./noop/index.cjs"
214
205
  },
215
206
  "./once": {
216
207
  "types": "./once/index.d.ts",
@@ -221,6 +212,15 @@
221
212
  "require": "./once/index.cjs",
222
213
  "default": "./once/index.cjs"
223
214
  },
215
+ "./pick-random": {
216
+ "types": "./pick-random/index.d.ts",
217
+ "import": {
218
+ "types": "./pick-random/index.d.ts",
219
+ "default": "./pick-random/index.mjs"
220
+ },
221
+ "require": "./pick-random/index.cjs",
222
+ "default": "./pick-random/index.cjs"
223
+ },
224
224
  "./random-int": {
225
225
  "types": "./random-int/index.d.ts",
226
226
  "import": {
@@ -257,6 +257,15 @@
257
257
  "require": "./serialized-memo/index.cjs",
258
258
  "default": "./serialized-memo/index.cjs"
259
259
  },
260
+ "./simple-string-hash": {
261
+ "types": "./simple-string-hash/index.d.ts",
262
+ "import": {
263
+ "types": "./simple-string-hash/index.d.ts",
264
+ "default": "./simple-string-hash/index.mjs"
265
+ },
266
+ "require": "./simple-string-hash/index.cjs",
267
+ "default": "./simple-string-hash/index.cjs"
268
+ },
260
269
  "./tagged": {
261
270
  "types": "./tagged/index.d.ts",
262
271
  "import": {
@@ -266,14 +275,14 @@
266
275
  "require": "./tagged/index.cjs",
267
276
  "default": "./tagged/index.cjs"
268
277
  },
269
- "./simple-string-hash": {
270
- "types": "./simple-string-hash/index.d.ts",
278
+ "./text-line-stream": {
279
+ "types": "./text-line-stream/index.d.ts",
271
280
  "import": {
272
- "types": "./simple-string-hash/index.d.ts",
273
- "default": "./simple-string-hash/index.mjs"
281
+ "types": "./text-line-stream/index.d.ts",
282
+ "default": "./text-line-stream/index.mjs"
274
283
  },
275
- "require": "./simple-string-hash/index.cjs",
276
- "default": "./simple-string-hash/index.cjs"
284
+ "require": "./text-line-stream/index.cjs",
285
+ "default": "./text-line-stream/index.cjs"
277
286
  },
278
287
  "./wait": {
279
288
  "types": "./wait/index.d.ts",
@@ -0,0 +1 @@
1
+ "use strict";var e=require("node:stream/web"),n=require("../noop/index.cjs");class t extends e.TransformStream{constructor({allowCR:e=!1,skipEmptyLines:t=!1}={}){let r="",s=0;const i=e?(e,n,r)=>{const i=e.indexOf("\r",s);if(-1!==i&&i!==e.length-1&&(-1===n||n-1>i)){const n=e.slice(s,i);return t&&0===n.length||r.enqueue(e.slice(s,i)),s=i+1,!0}return!1}:n.falseFn;super({transform(e,n){for(e=r+e,s=0;;){const r=e.indexOf("\n",s);if(i(e,r,n))continue;if(-1===r)break;let u=r;"\r"===e[r-1]&&u--;const c=e.slice(s,u);if(t&&0===c.length){s=r+1;continue}n.enqueue(c),s=r+1}r=e.slice(s)},flush(n){r.length>0&&(e&&"\r"===r[r.length-1]?n.enqueue(r.slice(0,-1)):n.enqueue(r))}})}}exports.TextLineStream=t;
@@ -0,0 +1,22 @@
1
+ import { TransformStream } from 'node:stream/web';
2
+
3
+ interface TextLineStreamOptions {
4
+ /** Allow splitting by solo \r */
5
+ allowCR?: boolean;
6
+ skipEmptyLines?: boolean;
7
+ }
8
+ /** Transform a stream into a stream where each chunk is divided by a newline,
9
+ * be it `\n` or `\r\n`. `\r` can be enabled via the `allowCR` option.
10
+ *
11
+ * ```ts
12
+ * const res = await fetch('https://example.com');
13
+ * const lines = res.body!
14
+ * .pipeThrough(new TextDecoderStream())
15
+ * .pipeThrough(new TextLineStream());
16
+ * ```
17
+ */
18
+ declare class TextLineStream extends TransformStream<string, string> {
19
+ constructor({ allowCR, skipEmptyLines }?: TextLineStreamOptions);
20
+ }
21
+
22
+ export { TextLineStream };
@@ -0,0 +1 @@
1
+ import{TransformStream as e}from"node:stream/web";import{falseFn as n}from"../noop/index.mjs";class t extends e{constructor({allowCR:e=!1,skipEmptyLines:t=!1}={}){let r="",o=0;const s=e?(e,n,r)=>{const s=e.indexOf("\r",o);if(-1!==s&&s!==e.length-1&&(-1===n||n-1>s)){const n=e.slice(o,s);return t&&0===n.length||r.enqueue(e.slice(o,s)),o=s+1,!0}return!1}:n;super({transform(e,n){for(e=r+e,o=0;;){const r=e.indexOf("\n",o);if(s(e,r,n))continue;if(-1===r)break;let i=r;"\r"===e[r-1]&&i--;const c=e.slice(o,i);if(t&&0===c.length){o=r+1;continue}n.enqueue(c),o=r+1}r=e.slice(o)},flush(n){r.length>0&&(e&&"\r"===r[r.length-1]?n.enqueue(r.slice(0,-1)):n.enqueue(r))}})}}export{t as TextLineStream};