foxts 1.5.1 → 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=new Map;function t(e){return Array.from(Array(e).keys())}function r(r){if(e.has(r))return e.get(r);const n=t(r);return e.set(r,n),n}const n=new Map;function a(e){let r,a;return n.has(e)&&(a=(r=n.get(e)).deref()),a||(r=new WeakRef(a=t(e)),n.set(e,r)),a}const o="function"==typeof WeakRef?a:r;exports.createFixedArray=o,exports.createFixedArrayWithGC=a,exports.createFixedArrayWithoutGC=r;
1
+ "use strict";const e=new Map;function t(e){return Array.from(Array(e).keys())}function r(r){if(e.has(r))return e.get(r);const n=t(r);return e.set(r,n),n}const n=new Map;function o(e){let r,o;return n.has(e)&&(o=(r=n.get(e)).deref()),o||(r=new WeakRef(o=t(e)),n.set(e,r)),o}const s="function"==typeof WeakRef?o:r,a=s(0);exports.EMPTY_ARRAY=a,exports.createFixedArray=s,exports.createFixedArrayWithGC=o,exports.createFixedArrayWithoutGC=r;
@@ -1,5 +1,6 @@
1
1
  declare function createFixedArrayWithoutGC(length: number): readonly number[];
2
2
  declare function createFixedArrayWithGC(length: number): readonly number[];
3
3
  declare const createFixedArray: typeof createFixedArrayWithGC;
4
+ declare const EMPTY_ARRAY: readonly number[];
4
5
 
5
- export { createFixedArray, createFixedArrayWithGC, createFixedArrayWithoutGC };
6
+ export { EMPTY_ARRAY, createFixedArray, createFixedArrayWithGC, createFixedArrayWithoutGC };
@@ -1 +1 @@
1
- const e=new Map;function t(e){return Array.from(Array(e).keys())}function r(r){if(e.has(r))return e.get(r);const n=t(r);return e.set(r,n),n}const n=new Map;function a(e){let r,a;return n.has(e)&&(a=(r=n.get(e)).deref()),a||(r=new WeakRef(a=t(e)),n.set(e,r)),a}const o="function"==typeof WeakRef?a:r;export{o as createFixedArray,a as createFixedArrayWithGC,r as createFixedArrayWithoutGC};
1
+ const e=new Map;function t(e){return Array.from(Array(e).keys())}function r(r){if(e.has(r))return e.get(r);const n=t(r);return e.set(r,n),n}const n=new Map;function a(e){let r,a;return n.has(e)&&(a=(r=n.get(e)).deref()),a||(r=new WeakRef(a=t(e)),n.set(e,r)),a}const o="function"==typeof WeakRef?a:r,c=o(0);export{c as EMPTY_ARRAY,o as createFixedArray,a as createFixedArrayWithGC,r as createFixedArrayWithoutGC};
@@ -0,0 +1 @@
1
+ "use strict";const e=/["&'<>]/;exports.escapeHTML=function(t){const c=e.exec(t);if(null===c)return t;let s="",a="",r=c.index,n=0;for(const e=t.length;r<e;r++){switch(t.charCodeAt(r)){case 34:s="&quot;";break;case 38:s="&amp;";break;case 39:s="&#39;";break;case 60:s="&lt;";break;case 62:s="&gt;";break;default:continue}n!==r&&(a+=t.slice(n,r)),n=r+1,a+=s}return n===r?a:a+t.slice(n,r)};
@@ -0,0 +1,3 @@
1
+ declare function escapeHTML(str: string): string;
2
+
3
+ export { escapeHTML };
@@ -0,0 +1 @@
1
+ const e=/["&'<>]/;function c(c){const t=e.exec(c);if(null===t)return c;let a="",n="",r=t.index,s=0;for(const e=c.length;r<e;r++){switch(c.charCodeAt(r)){case 34:a="&quot;";break;case 38:a="&amp;";break;case 39:a="&#39;";break;case 60:a="&lt;";break;case 62:a="&gt;";break;default:continue}s!==r&&(n+=c.slice(s,r)),s=r+1,n+=a}return s===r?n:n+c.slice(s,r)}export{c as escapeHTML};
@@ -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.5.1",
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,14 +41,14 @@
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",
44
+ "./async-write-to-stream": {
45
+ "types": "./async-write-to-stream/index.d.ts",
46
46
  "import": {
47
- "types": "./ahocorasick/index.d.ts",
48
- "default": "./ahocorasick/index.mjs"
47
+ "types": "./async-write-to-stream/index.d.ts",
48
+ "default": "./async-write-to-stream/index.mjs"
49
49
  },
50
- "require": "./ahocorasick/index.cjs",
51
- "default": "./ahocorasick/index.cjs"
50
+ "require": "./async-write-to-stream/index.cjs",
51
+ "default": "./async-write-to-stream/index.cjs"
52
52
  },
53
53
  "./append-set-elements-to-array": {
54
54
  "types": "./append-set-elements-to-array/index.d.ts",
@@ -59,15 +59,6 @@
59
59
  "require": "./append-set-elements-to-array/index.cjs",
60
60
  "default": "./append-set-elements-to-array/index.cjs"
61
61
  },
62
- "./async-write-to-stream": {
63
- "types": "./async-write-to-stream/index.d.ts",
64
- "import": {
65
- "types": "./async-write-to-stream/index.d.ts",
66
- "default": "./async-write-to-stream/index.mjs"
67
- },
68
- "require": "./async-write-to-stream/index.cjs",
69
- "default": "./async-write-to-stream/index.cjs"
70
- },
71
62
  "./bitwise": {
72
63
  "types": "./bitwise/index.d.ts",
73
64
  "import": {
@@ -95,6 +86,24 @@
95
86
  "require": "./detect-eol/index.cjs",
96
87
  "default": "./detect-eol/index.cjs"
97
88
  },
89
+ "./ahocorasick": {
90
+ "types": "./ahocorasick/index.d.ts",
91
+ "import": {
92
+ "types": "./ahocorasick/index.d.ts",
93
+ "default": "./ahocorasick/index.mjs"
94
+ },
95
+ "require": "./ahocorasick/index.cjs",
96
+ "default": "./ahocorasick/index.cjs"
97
+ },
98
+ "./escape-html": {
99
+ "types": "./escape-html/index.d.ts",
100
+ "import": {
101
+ "types": "./escape-html/index.d.ts",
102
+ "default": "./escape-html/index.mjs"
103
+ },
104
+ "require": "./escape-html/index.cjs",
105
+ "default": "./escape-html/index.cjs"
106
+ },
98
107
  "./escape-string-regexp": {
99
108
  "types": "./escape-string-regexp/index.d.ts",
100
109
  "import": {
@@ -104,6 +113,15 @@
104
113
  "require": "./escape-string-regexp/index.cjs",
105
114
  "default": "./escape-string-regexp/index.cjs"
106
115
  },
116
+ "./fast-string-array-join": {
117
+ "types": "./fast-string-array-join/index.d.ts",
118
+ "import": {
119
+ "types": "./fast-string-array-join/index.d.ts",
120
+ "default": "./fast-string-array-join/index.mjs"
121
+ },
122
+ "require": "./fast-string-array-join/index.cjs",
123
+ "default": "./fast-string-array-join/index.cjs"
124
+ },
107
125
  "./fifo": {
108
126
  "types": "./fifo/index.d.ts",
109
127
  "import": {
@@ -257,6 +275,15 @@
257
275
  "require": "./tagged/index.cjs",
258
276
  "default": "./tagged/index.cjs"
259
277
  },
278
+ "./text-line-stream": {
279
+ "types": "./text-line-stream/index.d.ts",
280
+ "import": {
281
+ "types": "./text-line-stream/index.d.ts",
282
+ "default": "./text-line-stream/index.mjs"
283
+ },
284
+ "require": "./text-line-stream/index.cjs",
285
+ "default": "./text-line-stream/index.cjs"
286
+ },
260
287
  "./wait": {
261
288
  "types": "./wait/index.d.ts",
262
289
  "import": {
@@ -265,15 +292,6 @@
265
292
  },
266
293
  "require": "./wait/index.cjs",
267
294
  "default": "./wait/index.cjs"
268
- },
269
- "./fast-string-array-join": {
270
- "types": "./fast-string-array-join/index.d.ts",
271
- "import": {
272
- "types": "./fast-string-array-join/index.d.ts",
273
- "default": "./fast-string-array-join/index.mjs"
274
- },
275
- "require": "./fast-string-array-join/index.cjs",
276
- "default": "./fast-string-array-join/index.cjs"
277
295
  }
278
296
  }
279
297
  }
@@ -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};