iconv-tiny 1.3.0 → 1.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 CHANGED
@@ -43,7 +43,7 @@ or use CDN:
43
43
  <script type="importmap">
44
44
  {
45
45
  "imports": {
46
- "iconv-tiny": "https://unpkg.com/iconv-tiny@1.3.0/dist/iconv-tiny.mjs"
46
+ "iconv-tiny": "https://unpkg.com/iconv-tiny@1.4.0/dist/iconv-tiny.mjs"
47
47
  }
48
48
  }
49
49
  </script>
@@ -88,16 +88,16 @@ import { UTF16LE } from "iconv-tiny";
88
88
  const utf16 = UTF16LE.create();
89
89
 
90
90
  // Create decoder, it works like TextDecoder with {stream: true} option.
91
- const decoder = utf16.newDecoder();
91
+ const decoder = utf16.getDecoder();
92
92
 
93
93
  // Decode a fragment
94
- const part = decoder.decode(new Uint8Array([0x3d, 0xd8, 0x0a]));
94
+ const part = decoder.write(new Uint8Array([0x3d, 0xd8, 0x0a]));
95
95
 
96
96
  // Decode the next fragment
97
- const str = decoder.decode(new Uint8Array([0xde])); // 😊
97
+ const str = decoder.write(new Uint8Array([0xde])); // 😊
98
98
 
99
99
  // Finish stream decoding
100
- const tail = decoder.decode();
100
+ const tail = decoder.end();
101
101
  ```
102
102
 
103
103
  See more [examples](examples).
@@ -123,10 +123,10 @@ All encodings are generated automatically from https://www.unicode.org/Public/MA
123
123
  Comparison with iconv-lite module (Core i7-7500U CPU @ 2.7GHz, Node v24.2.0). Note: your results may vary, so please always check on your hardware.
124
124
 
125
125
  ```
126
- operation iconv-lite@0.7.0 iconv-tiny@1.3.0
126
+ operation iconv-lite@0.7.2 iconv-tiny@1.4.0
127
127
  ------------------------------------------------------
128
- encode('win1251') ~598 Mb/s ~622 Mb/s
129
- decode('win1251') ~218 Mb/s ~263 Mb/s
128
+ encode('win1251') ~270 Mb/s ~270 Mb/s
129
+ decode('win1251') ~120 Mb/s ~220 Mb/s
130
130
  ```
131
131
 
132
132
  **iconv-lite** is NodeJS oriented and use specific API like `Buffer` and native NodeJS encodings.
@@ -141,7 +141,7 @@ decode('win1251') ~218 Mb/s ~263 Mb/s
141
141
  1. UTF-16 is an alias of UTF-16LE
142
142
  1. UTF-32 is an alias of UTF-32LE
143
143
 
144
- ## Testing
144
+ ## Testing & Coverage
145
145
 
146
146
  ```
147
147
  $ git clone https://github.com/vip-delete/iconv-tiny.git
@@ -154,16 +154,22 @@ $ node tests\perf-test-unicode.mjs
154
154
 
155
155
  $ # To view test coverage:
156
156
  $ npm run coverage
157
-
158
- ----------------|---------|----------|---------|---------|-------------------
159
- File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
160
- ----------------|---------|----------|---------|---------|-------------------
161
- All files | 100 | 100 | 96.72 | 100 |
162
- commons.mjs | 100 | 100 | 81.81 | 100 |
163
- iconv-tiny.mjs | 100 | 100 | 100 | 100 |
164
- sbcs.mjs | 100 | 100 | 100 | 100 |
165
- unicode.mjs | 100 | 100 | 100 | 100 |
166
- ----------------|---------|----------|---------|---------|-------------------
157
+ -------------|---------|----------|---------|---------|-------------------
158
+ File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
159
+ -------------|---------|----------|---------|---------|-------------------
160
+ All files | 97.86 | 95.55 | 96.66 | 97.93 |
161
+ commons.mjs | 93.83 | 95 | 97.29 | 94.2 | 36-41,53-56
162
+ dbcs.mjs | 97.02 | 89.47 | 100 | 96.87 | 27,134,143
163
+ iconv.mjs | 100 | 100 | 100 | 100 |
164
+ mapped.mjs | 100 | 100 | 100 | 100 |
165
+ native.mjs | 100 | 100 | 100 | 100 |
166
+ sbcs.mjs | 100 | 90.9 | 100 | 100 | 36-66
167
+ types.mjs | 100 | 100 | 50 | 100 |
168
+ unicode.mjs | 100 | 100 | 100 | 100 |
169
+ utf16.mjs | 100 | 100 | 100 | 100 |
170
+ utf32.mjs | 98.76 | 97.5 | 100 | 98.76 | 224
171
+ utf8.mjs | 100 | 100 | 100 | 100 |
172
+ -------------|---------|----------|---------|---------|-------------------
167
173
  ```
168
174
 
169
175
  ## Commands
@@ -11,39 +11,67 @@ export function canonicalize(encoding: string): string;
11
11
  * @param encodings - A map of encodings to support.
12
12
  * @param aliases - Comma-separated groups, each containing space-separated aliases for the same encoding.
13
13
  */
14
- export function createIconv(encodings?: { [key: string]: EncodingFactory }, aliases?: string): IconvTiny;
14
+ export function createIconv(encodings?: { [key: string]: EncodingFactory }, aliases?: string): Iconv;
15
15
 
16
- interface IconvTiny {
17
- decode(array: Uint8Array, encoding: string, options?: OptionsAndDecoderOptions): string;
18
- encode(content: string, encoding: string, options?: OptionsAndEncoderOptions): Uint8Array;
16
+ interface EncodingFactory {
17
+ create(options?: Options): Encoding;
18
+ }
19
+
20
+ interface Iconv {
21
+ /** get/create an encoding, create a decoder, decode and flush */
22
+ decode(buf: Uint8Array, encoding: string, options?: OptionsAndDecoderOptions): string;
23
+ /** get/create an encoding, create a encoder, encode and flush */
24
+ encode(str: string, encoding: string, options?: OptionsAndEncoderOptions): Uint8Array;
25
+ /** get/create an encoding */
19
26
  getEncoding(encoding: string, options?: Options): Encoding;
20
27
  }
21
28
 
29
+ /** Encoding that doesn't keep any state */
22
30
  interface Encoding {
23
31
  getName(): string;
24
- decode(array: Uint8Array, options?: DecoderOptions): string;
25
- encode(text: string, options?: EncoderOptions): Uint8Array;
26
- newDecoder(options?: DecoderOptions): CharsetDecoder;
27
- newEncoder(options?: EncoderOptions): CharsetEncoder;
28
- }
29
32
 
30
- interface EncodingFactory {
31
- create(options?: Options): Encoding;
32
- }
33
-
34
- interface CharsetDecoder {
35
- decode(array?: Uint8Array): string;
36
- }
33
+ /** get/create a decoder, decode and flush */
34
+ decode(buf: Uint8Array, options?: DecodeOptions): string;
35
+ /** get/create a encoder, encode and flush */
36
+ encode(str: string, options?: EncodeOptions): Uint8Array;
37
37
 
38
- interface CharsetEncoder {
39
- encode(text?: string): Uint8Array;
40
- encodeInto(text: string, dst: Uint8Array): TextEncoderEncodeIntoResult;
41
38
  /**
42
- * Similar to Buffer.byteLength;
43
- * @param text - input to calculate the length of
39
+ * Similar to Buffer.byteLength.
40
+ *
41
+ * @param str - input to calculate the length of
44
42
  * @returns The number of bytes of the specified string
45
43
  */
46
- byteLength(text: string): number;
44
+ byteLength(str: string): number;
45
+
46
+ // --- Low-level Stream APIs ---
47
+
48
+ /** create a decoder to keep the decoding state. */
49
+ getDecoder(options?: DecodeOptions): DecoderStream;
50
+ /** create an encoder to keep the encoding state. */
51
+ getEncoder(options?: EncodeOptions): EncoderStream;
52
+ }
53
+
54
+ /** Decoder to keep the decoding state */
55
+ interface DecoderStream {
56
+ /** decode, keep the leftover in the state */
57
+ write(buf: Uint8Array): string;
58
+ /** flush the leftover */
59
+ end(): string;
60
+ }
61
+
62
+ /** Encoder to keep the encoding state */
63
+ interface EncoderStream {
64
+ /** encode into a new array, keep the leftover in the state */
65
+ write(str: string): Uint8Array;
66
+ /** flush the leftover into a new array */
67
+ end(): Uint8Array;
68
+
69
+ // --- Low-Level Encoding APIs ---
70
+
71
+ /** encode into the given array, keep the leftover in the state */
72
+ encodeInto(str: string, buf: Uint8Array): TextEncoderEncodeIntoResult;
73
+ /** flush the leftover into the given array */
74
+ flushInto(buf: Uint8Array): TextEncoderEncodeIntoResult;
47
75
  }
48
76
 
49
77
  type TextEncoderEncodeIntoResult = {
@@ -51,11 +79,11 @@ type TextEncoderEncodeIntoResult = {
51
79
  written: number;
52
80
  }
53
81
 
54
- type DecoderOptions = {
82
+ type DecodeOptions = {
55
83
  /**
56
84
  * Sets the replacement character used by the "decode" method for unmapped bytes (default: "�").
57
85
  */
58
- defaultCharUnicode?: string | DefaultCharUnicodeFunction;
86
+ defaultCharUnicode?: string | DefaultFunction;
59
87
  /**
60
88
  * Specifies the behavior of the "decode" method (default: false)
61
89
  *
@@ -71,11 +99,11 @@ type DecoderOptions = {
71
99
  stripBOM?: boolean;
72
100
  };
73
101
 
74
- type EncoderOptions = {
102
+ type EncodeOptions = {
75
103
  /**
76
104
  * Sets the replacement byte used by the "encode" method for unmapped symbols (default: "?").
77
105
  */
78
- defaultCharByte?: string | DefaultCharByteFunction;
106
+ defaultCharByte?: string | DefaultFunction;
79
107
  /**
80
108
  * Unicode only. No BOM added by default, unless overridden by addBOM: true
81
109
  */
@@ -97,28 +125,14 @@ type Options = {
97
125
  type Overrides = Array<number | string>;
98
126
 
99
127
  /**
100
- * @param {number} input
101
- * @param {number} index
102
- * @returns {number}
128
+ * @param {number} input - input character code (0-65535) if encoding; or an input byte (0-255) if decoding
129
+ * @param {number} index - index of the character if encoding; or an index of the byte if decoding
130
+ * @returns {number} default byte (0-255) if encoding; or a default character code (0-65535) if decoding
103
131
  */
104
132
  type DefaultFunction = (input: number, index: number) => number | null | undefined;
105
133
 
106
- /**
107
- * @param {number} input - input character code (0-65536)
108
- * @param {number} index - index of the character
109
- * @returns {number} default byte (0-255)
110
- */
111
- type DefaultCharByteFunction = DefaultFunction;
112
-
113
- /**
114
- * @param {number} input - input byte (0-255)
115
- * @param {number} index - index of the byte
116
- * @returns {number} default character code (0-65536)
117
- */
118
- type DefaultCharUnicodeFunction = DefaultFunction;
119
-
120
- type OptionsAndDecoderOptions = Options & DecoderOptions;
121
- type OptionsAndEncoderOptions = Options & EncoderOptions;
134
+ type OptionsAndDecoderOptions = Options & DecodeOptions;
135
+ type OptionsAndEncoderOptions = Options & EncodeOptions;
122
136
 
123
137
  export const US_ASCII: EncodingFactory;
124
138
  export const ISO_8859_1: EncodingFactory;
@@ -1,25 +1,29 @@
1
1
  /**
2
- * iconv-tiny v1.3.0
2
+ * iconv-tiny v1.4.0
3
3
  * (c) 2025-present vip.delete <vip.delete@gmail.com>
4
4
  * @license MIT
5
5
  **/
6
6
  const ns = {};
7
- const n=new TextDecoder("utf-16le",{fatal:!0}),p=a=>{if(a.length<=192)return String.fromCharCode(...a);try{return n.decode(a)}catch{const b=a.length,c=[];for(let d=0;d<b;d+=1024)c.push(String.fromCharCode(...a.subarray(d,d+1024)));return c.join("")}},q=(a,b,c)=>{let d=0;const f=new Uint8Array(4096);do{const {read:e,written:g}=b.o(a,c,f);c=c.slice(e);d+=g}while(c.length);return d};class r{constructor(a,b,c){this.h=b.M(a,c??{});this.g=b}decode(a){return this.g.N(this.h,a)}}
8
- class t{constructor(a,b,c){this.u=a;this.g=b;this.h=c??{};this.S=b.m(a,this.h)}encode(a){if(!a)return new Uint8Array(0);const b=this.g;var c=b.L(b.m(this.u,this.h),b,a);c=new Uint8Array(c);({written:a}=b.o(this.S,a,c));return c.subarray(0,a)}encodeInto(a,b){return this.g.o(this.S,a,b)}byteLength(a){const b=this.g;return b.K(b.m(this.u,this.h),b,a)}}
9
- class u{constructor(a,b,c){this.g=a;this.D=b;this.G=c}getName(){return this.g.j}decode(a,b){b=this.newDecoder(b);return b.decode(a)+b.decode()}encode(a,b){return this.newEncoder(b).encode(a)}newDecoder(a){return new r(this.g,this.D,a)}newEncoder(a){return new t(this.g,this.G,a)}};const v=a=>a.toLowerCase().replace(/[^a-z0-9]/gu,"").replace(/(?<!\d)0+/gu,"");
10
- class w{constructor(a,b){a??={};this.g=new Map;this.cache=new Map;b=(b??"").split(",").map(c=>c.split(" ").map(v));for(const c of Object.keys(a)){const d=a[c];if(d?.create){const f=v(c);this.g.set(f,d);b.filter(e=>e.includes(f)).forEach(e=>e.forEach(g=>this.g.set(g,d)))}}}decode(a,b,c){return this.getEncoding(b,c).decode(a,c)}encode(a,b,c){return this.getEncoding(b,c).encode(a,c)}getEncoding(a,b){a=v(a);const c=a+(b?.overrides??"");var d=this.cache.get(c);if(!d){d=this.g.get(a);if(!d)throw Error(`Encoding "${a}" not supported`);
11
- d=d.create(b);this.cache.set(c,d)}return d}};const x=(a,b)=>a.C.decode(b,{stream:!!b}),y=(a,b)=>{var c=a.B;if(!a.l){var d=(new Uint16Array(65536)).fill(65533);for(let f=0;f<c.length;f++){const e=c[f];e!==65533&&(d[e]=f)}a.l=d}a=a.l;b=b.defaultCharByte;c=63;d=null;typeof b==="string"?b.length&&(c=b.charCodeAt(0)):typeof b==="function"&&(d=b);return{l:a,F:c,H:d}},A={M:(a,b)=>{const c=a.j,d=a.B,f=a.Y,e=b.defaultCharUnicode;let g=65533,k=null,h=null;(a=a.W&&(b?.native??!1))?h=new TextDecoder(c):typeof e==="string"?e.length&&(g=e.charCodeAt(0)):
12
- typeof e==="function"&&(k=e);return{B:d,F:g,H:k,T:a?x:f,C:h,v:-1}},N:(a,b)=>{const c=a.T;return c(a,b)}},B=(a,b,c,d)=>{try{new TextDecoder(a);var f=!0}catch{f=!1}return new u({j:a,W:f,B:b,l:null,Y:c},A,d)};const C=(a,b,c,d)=>{a=a.charCodeAt(b);c[d]=a;c[d+1]=a>>8;return 0},D=(a,b,c,d)=>{a=a.charCodeAt(b);c[d]=a>>8;c[d+1]=a;return 0},E=(a,b,c,d)=>{a=a.codePointAt(b);c[d]=a;c[d+1]=a>>8;c[d+2]=a>>16;c[d+3]=a>>24;return a>65535?1:0},F=(a,b,c,d)=>{a=a.codePointAt(b);c[d]=a>>24;c[d+1]=a>>16;c[d+2]=a>>8;c[d+3]=a;return a>65535?1:0},G=(a,b)=>(a[b]|a[b+1]<<8|a[b+2]<<16|a[b+3]<<24)>>>0,H=(a,b)=>(a[b]<<24|a[b+1]<<16|a[b+2]<<8|a[b+3])>>>0,I=(a,b,c)=>{if(c<=65535)return a[b]=c,a[b+1]=c>>8,2;if(c>1114111)return a[b]=
13
- 65533,a[b+1]=255,2;c-=65536;const d=55296|c>>10;c=56320|c&1023;a[b]=d;a[b+1]=d>>8;a[b+2]=c;a[b+3]=c>>8;return 4},J=(a,b,c)=>(a.R?a.O:0)+c.length*a.O,K={m:(a,b)=>{const c=a.J;a=a.P;b=b.addBOM??!1;return{R:b,A:b,O:1<<c+1,put:c?a?F:E:a?D:C}},o:(a,b,c)=>{const d=a.O,f=a.put;let e=0;if(a.A){if(c.length<d)return{read:0,written:0};f("",0,c,e);e+=d;a.A=!1}a=Math.min(b.length,c.length-e&~(d-1));for(let g=0;g<a;g++,e+=d)g+=f(b,g,c,e);return{read:a,written:e}},L:J,K:(a,b,c)=>a.O===4?q(a,b,c):J(a,b,c)},L=[{J:16,
14
- D:{M:(a,b)=>({C:new TextDecoder("UTF-16"+["LE","BE"][a.P],{ignoreBOM:!(b.stripBOM??!0)})}),N:(a,b)=>a.C.decode(b,{stream:!!b})},G:K},{J:32,D:{M:(a,b)=>({v:new Uint8Array(4),i:0,V:a.P?H:G,X:!(b.stripBOM??!0)}),N:(a,b)=>{const c=a.v,d=a.V,f=a.X;if(!b)return a.i?(a.i=0,String.fromCharCode(65533)):"";const e=new Uint8Array(b.length+4);let g=0,k=0;if(a.i){for(;a.i<4&&g<b.length;)c[a.i++]=b[g++];if(a.i<4)return"";k+=I(e,k,d(c,0))}const h=b.length-3;for(;g<h;g+=4)k+=I(e,k,d(b,g));a.i=b.length-g;a.i&&c.set(b.subarray(g));
15
- return(new TextDecoder("UTF-16",{ignoreBOM:f})).decode(e.subarray(0,k))}},G:K},{J:8,D:{M:(a,b)=>({C:new TextDecoder("UTF-8",{ignoreBOM:!(b.stripBOM??!0)})}),N:(a,b)=>a.C.decode(b,{stream:!!b})},G:{m:(a,b)=>{a=b.addBOM??!1;return{R:a,A:a,U:new TextEncoder,I:""}},o:(a,b,c)=>{let d=0;if(a.A){if(c.length<3)return{read:0,written:0};c[0]=239;c[1]=187;c[2]=191;d+=3;a.A=!1}a.I&&(b=a.I+b,a.I="");const f=b.length-1;if(b.length>0){const k=b.charCodeAt(f);k>=55296&&k<56320&&(a.I=b.charAt(f),b=b.slice(0,f))}const {read:e,
16
- written:g}=a.U.encodeInto(b,c.subarray(d));return{read:e+(a.I?1:0),written:g+d}},L:(a,b,c)=>(a.R?4:0)+c.length*4,K:q}}];class M{constructor(a,b){const c=L[a];this.g=new u({j:"UTF-"+c.J+["LE","BE",""][b],J:a,P:b},c.D,c.G)}create(){return this.g}};const N=(a,b)=>{if(!b)return"";const c=a.B,d=a.F;a=a.H;const f=b.length,e=new Uint16Array(f);for(let g=0;g<f;g++){const k=b[g],h=c[k];e[g]=h!==65533?h:a?.(k,g)??d}return p(e)},O=(a,b,c)=>c.length,P={m:y,o:(a,b,c)=>{const d=a.l,f=a.F;a=a.H;const e=Math.min(b.length,c.length);for(let g=0;g<e;g++){const k=b.charCodeAt(g),h=d[k];c[g]=h!==65533?h:a?.(k,g)??f}return{read:e,written:e}},L:O,K:O};
17
- class Q{constructor(a,b,c){this.j=a;this.h=b;this.u=c??""}create(a){return B(this.j,this.g(a),N,P)}g(a){var b=this.h,c=this.u;const d=(new Uint16Array(256)).fill(65533);for(var f=0;f<256-b.length;)d[f]=f++;let e=0;for(;f<256;)d[f++]=b.charCodeAt(e++);for(b=0;b<c.length;)d[c.charCodeAt(b)]=c.charCodeAt(b+1),b+=2;for(c=128;c<256;)b=d[c],b===32&&(d[c]=c),b===63&&(d[c]=65533),c++;a=a?.overrides??[];for(c=0;c<a.length-1;)b=a[c++],f=a[c++],d[Number(b)]=typeof f==="number"?f:f.charCodeAt(0);return d}};const R=(a,b)=>{const c=a.B,d=a.F,f=a.H;var e=a.v;if(!b)return a.v=-1,e===-1?"":String.fromCharCode(f?.(e,-1)??d);const g=b.length;if(g===0)return"";const k=new Uint16Array(g+1);let h=0,m=0;e===-1?e=b[0]:h=a.v=-1;for(;;){let l=c[e];if(l!==65533)k[m++]=l;else if(h+1<g)l=c[e<<8|b[h+1]],l!==65533?h++:l=f?.(l,h)??d,k[m++]=l;else{a.v=e;break}h++;if(h<g)e=b[h];else break}return p(k.subarray(0,m))},S={m:y,o:(a,b,c)=>{const d=a.l,f=a.F;a=a.H;let e=0,g=0;const k=b.length,h=c.length,m=h-1;for(;e<k;e++){var l=
18
- b.charCodeAt(e);const z=d[l];l=z!==65533?z:a?.(l,e)??f;if(l>255){if(g>=m)break;c[g]=l>>8;c[g+1]=l;g+=2}else{if(g>=h)break;c[g]=l;g+=1}}return{read:e,written:g}},L:(a,b,c)=>c.length*2,K:q};
19
- class T{constructor(a,b,c){this.j=a;this.h=b;this.u=c}create(){return B(this.j,this.g(),R,S)}g(){const a=(new Uint16Array(65536)).fill(65533);var b=this.h,c=this.u;for(var d=0;d<c.length;d++){const e=c[d];let g=Number.parseInt(e[0],16);var f=-1;for(let k=1;k<e.length;k++){const h=e[k];if(typeof h==="string"){for(f=0;f<h.length;f++)a[g++]=h.charCodeAt(f);f=h.charCodeAt(h.length-1)}if(typeof h==="number")for(let m=0;m<h;m++)a[g++]=f+1,f++}}if(b)for(b=b.g(),c=0;c<b.length;c++)d=b[c],d===65533||a[c]===
20
- 65533&&(a[c]=d);return a}};ns.Z=T;ns.canonicalize=v;ns.createIconv=(a,b)=>new w(a,b);ns.SBCS=Q;ns.Unicode=M;
7
+ {
8
+ const p=a=>a.toLowerCase().replace(/[^a-z0-9]/gu,"").replace(/(?<!\d)0+/gu,"");
9
+ class q{constructor(a,b){a??={};this.g=new Map;this.cache=new Map;b=(b??"").split(",").map(c=>c.split(" ").map(p));for(const c of Object.keys(a)){const d=a[c];if(d?.create){const e=p(c);this.g.set(e,d);b.filter(f=>f.includes(e)).forEach(f=>f.forEach(h=>this.g.set(h,d)))}}}decode(a,b,c){return this.getEncoding(b,c).decode(a,c)}encode(a,b,c){return this.getEncoding(b,c).encode(a,c)}getEncoding(a,b){a=p(a);const c=a+(b?.overrides??"");var d=this.cache.get(c);if(!d){d=this.g.get(a);if(!d)throw Error(`Encoding "${a}" not supported`);
10
+ d=d.create(b);this.cache.set(c,d)}return d}};var r;r={I:(a,b)=>({S:new TextDecoder(a.j,{ignoreBOM:!(b?.stripBOM??!0)})}),K:(a,b)=>a.S.decode(b,{stream:!0}),J:a=>a.S.decode()};const t=new TextEncoder,u=new TextDecoder("utf-16le",{fatal:!0,ignoreBOM:!0}),v=a=>{if(a.length<=192)return String.fromCharCode(...a);try{return u.decode(a)}catch{const b=a.length,c=[];for(let d=0;d<b;d+=1024)c.push(String.fromCharCode(...a.subarray(d,d+1024)));return c.join("")}},w=()=>"",x=()=>{},y=a=>a.length,z=a=>2*a.length,A=a=>4*a.length,B=(a,b,c)=>{b[c]=a;b[c+1]=a>>8},C=(a,b,c)=>{b[c]=a>>8;b[c+1]=a},D=(a,b,c)=>{b[c]=a;b[c+1]=a>>8;b[c+2]=a>>16;b[c+3]=a>>24},aa=(a,b,c)=>{b[c]=a>>24;b[c+1]=a>>
11
+ 16;b[c+2]=a>>8;b[c+3]=a},ba=(a,b)=>(a[b]|a[b+1]<<8|a[b+2]<<16|a[b+3]<<24)>>>0,ca=(a,b)=>(a[b]<<24|a[b+1]<<16|a[b+2]<<8|a[b+3])>>>0,E=(a,b,c)=>{if(a<=65535)return b[c]=a,1;if(a>1114111)return b[c]=65533,1;a-=65536;b[c]=55296|a>>10;b[c+1]=56320|a&1023;return 2},F=new Uint8Array(4096),G=(a,b,c)=>{b=c.u(b,{});do{const d=b.r;c.l(b,a,F);a=a.slice(b.r-d)}while(a.length);c.m(b,F);return b.w};class da{constructor(a,b){this.h=a;this.g=b}write(a){return this.g.K(this.h,a)}end(){return this.g.J(this.h)}}
12
+ class ea{constructor(a,b){this.h=a;this.g=b}write(a){const b=this.h,c=this.g,d=new Uint8Array(c.B(a)+4),e=b.w;c.l(b,a,d);return d.subarray(0,b.w-e)}end(){const a=this.h,b=this.g,c=new Uint8Array(4),d=a.w;b.m(a,c);return c.subarray(0,a.w-d)}encodeInto(a,b){const c=this.h,d=c.r,e=c.w;this.g.l(c,a,b);return{read:c.r-d,written:c.w-e}}flushInto(a){const b=this.h,c=b.r,d=b.w;this.g.m(b,a);return{read:b.r-c,written:b.w-d}}}
13
+ class H{constructor(a,b,c,d,e){this.g=a;this.X=b;this.T=c;this.N=d;this.h=e;try{new TextDecoder(a.j);var f=!0}catch{f=!1}this.Y=f}getName(){return this.g.j}decode(a,b){b=this.getDecoder(b);a=b.write(a);return(b=b.end())?a+b:a}encode(a,b){b??={};const c=this.h&&typeof b.defaultCharByte!=="function"?this.h:this.N;b=c.u(this.g,b);const d=new Uint8Array(c.B(a)+4);c.l(b,a,d);c.m(b,d);return d.subarray(0,b.w)}byteLength(a){const b=this.N;return b.F(a,this.g,b)}getDecoder(a){a??={};const b=this.Y&&a.native?
14
+ r:this.T&&typeof a.defaultCharUnicode!=="function"?this.T:this.X;a=b.I(this.g,a);return new da(a,b)}getEncoder(a){a??={};const b=this.h&&typeof a.defaultCharByte!=="function"?this.h:this.N;a=b.u(this.g,a);return new ea(a,b)}}class fa{constructor(a){this.g=a}create(){return this.g}};const I=(a,b)=>typeof a==="string"&&a.length>0?a.charCodeAt(0):b,J=(a,b)=>{b=b.defaultCharUnicode;return{A:a.A,D:-1,G:I(b,65533),H:typeof b==="function"?b:null}},K=(a,b)=>{const c=a.slice();for(let d=0;d<a.length;d++)a[d]!==65533||(c[d]=b);return c},L=(a,b)=>{b=b.defaultCharByte;return{r:0,w:0,C:a.C,G:I(b,63),H:typeof b==="function"?b:null}},M=(a,b,c,d,e,f)=>{const h=(new Uint16Array(65536)).fill(65533);for(let g=0;g<b.length;g++){const k=b[g];k!==65533&&(h[k]=g)}return new H({j:a,A:b,L:null,P:0,
15
+ C:h,M:null,R:0},c,d,e,f)};var N;N={I:J,K:(a,b)=>{const c=a.A,d=a.G;a=a.H;const e=new Uint16Array(b.length);for(let f=0;f<b.length;f++){const h=b[f],g=c[h];e[f]=g!==65533?g:a(h,f)??d}return Buffer?Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString("ucs2"):v(e)},J:w};var O;
16
+ O={I:(a,b)=>{b=I(b.defaultCharUnicode,65533);a.L&&a.P===b||(a.L=K(a.A,b),a.P=b);return{A:a.L}},K:(a,b)=>{a=a.A;const c=new Uint16Array(b.length);for(let d=0;d<b.length;d++)c[d]=a[b[d]];return Buffer?Buffer.from(c.buffer,c.byteOffset,c.byteLength).toString("ucs2"):v(c)},J:w};var P;P={u:L,l:(a,b,c)=>{const d=a.C,e=a.G,f=a.H,h=Math.min(b.length,c.length);for(let g=0;g<h;g++){const k=b.charCodeAt(g),l=d[k];c[g]=l!==65533?l:f(k,g)??e}a.r+=h;a.w+=h},m:x,B:y,F:y};var Q;
17
+ Q={u:(a,b)=>{b=I(b.defaultCharByte,63);a.M&&a.R===b||(a.M=K(a.C,b),a.R=b);return{r:0,w:0,C:a.M}},l:(a,b,c)=>{const d=a.C,e=Math.min(b.length,c.length);for(let f=0;f<e;f++)c[f]=d[b.charCodeAt(f)];a.r+=e;a.w+=e},m:x,B:y,F:y};
18
+ class ha{constructor(a,b,c){this.j=a;this.h={symbols:b,V:c??""}}create(a){return M(this.j,this.g(a),N,O,P,Q)}g(a){var b=this.h,c=b.symbols,d=b.V;b=(new Uint16Array(256)).fill(65533);for(var e=0;e<256-c.length;)b[e]=e++;let f=0;for(;e<256;)b[e++]=c.charCodeAt(f++);for(c=0;c<d.length;)b[d.charCodeAt(c)]=d.charCodeAt(c+1),c+=2;for(c=128;c<256;)d=b[c],d===32&&(b[c]=c),d===63&&(b[c]=65533),c++;a=a?.overrides??[];for(c=0;c<a.length-1;)d=a[c++],e=a[c++],b[Number(d)]=typeof e==="number"?e:e.charCodeAt(0);
19
+ return b}};var R;R={I:J,K:(a,b)=>{const c=a.A,d=a.G,e=a.H;var f=a.D;const h=b.length;if(h===0)return"";const g=new Uint16Array(h+1);let k=0,l=0;f===-1?f=b[0]:k=a.D=-1;for(;;){let m=c[f];if(m!==65533)g[l++]=m;else if(k+1<h)m=c[f<<8|b[k+1]],m!==65533?k++:m=e?.(m,k)??d,g[l++]=m;else{a.D=f;break}k++;if(k<h)f=b[k];else break}return v(g.subarray(0,l))},J:a=>{const b=a.D;a.D=-1;return b===-1?"":String.fromCharCode(a.H?.(b,-1)??a.G)}};var S;
20
+ S={u:L,l:(a,b,c)=>{const d=a.C,e=a.G,f=a.H;let h=0,g=0;const k=b.length,l=c.length,m=l-1;for(;h<k;h++){var n=b.charCodeAt(h);const T=d[n];n=T!==65533?T:f?.(n,h)??e;if(n>255){if(g>=m)break;c[g]=n>>8;c[g+1]=n;g+=2}else{if(g>=l)break;c[g]=n;g+=1}}a.r+=h;a.w+=g},m:x,B:z,F:G};
21
+ class ia{constructor(a,b,c){this.j=a;this.h={parent:b,Z:c}}create(a){return M(this.j,this.g(a),R,R,S,S)}g(){var a=this.h,b=a.parent,c=a.Z;a=(new Uint16Array(65536)).fill(65533);for(var d=0;d<c.length;d++){const f=c[d];let h=Number.parseInt(f[0],16);var e=-1;for(let g=1;g<f.length;g++){const k=f[g];if(typeof k==="string"){for(e=0;e<k.length;e++)a[h++]=k.charCodeAt(e);e=k.charCodeAt(k.length-1)}if(typeof k==="number")for(let l=0;l<k;l++)a[h++]=e+1,e++}}if(b)for(b=b.g(),c=0;c<b.length;c++)d=b[c],d===
22
+ 65533||a[c]===65533&&(a[c]=d);return a}};const U=(a,b,c,d)=>new H({j:"UTF-"+a+(b?"LE":"BE"),O:b},c,c,d,d);var V;V={u:(a,b)=>({r:0,w:0,o:b.addBOM??!1,i:""}),l:(a,b,c)=>{let d=0;if(a.o){if(c.length<3)return;c[0]=239;c[1]=187;c[2]=191;d=3;a.o=!1}a.i&&(b=a.i+b,a.i="");let e=0;if(b.length>0){const g=b.charCodeAt(b.length-1);g>=55296&&g<56320&&(a.i=b.charAt(b.length-1),b=b.slice(0,b.length-1),e=1)}const {read:f,written:h}=t.encodeInto(b,c.subarray(d));a.r+=f+e;a.w+=h+d},m:(a,b)=>{if(a.i){const {read:c,written:d}=t.encodeInto(a.i,b);a.i="";a.r+=1+c;a.w+=d}},B:A,F:G};var W;W=new H({j:"UTF-8"},r,r,V,V);var X;X={u:(a,b)=>({r:0,w:0,o:b.addBOM??!1,put:a.O?B:C}),l:(a,b,c)=>{const d=a.put;let e=0;if(a.o){if(c.length<2)return;d(65279,c,0);e+=2;a.o=!1}let f=0;for(;f<b.length&&!(c.length-e<2);)d(b.charCodeAt(f),c,e),e+=2,f++;a.r+=f;a.w+=e},m:x,B:z,F:z};const ja=U(16,!0,r,X),ka=U(16,!1,r,X);var Y;Y={I:(a,b)=>{a=a.O;return{D:new Uint8Array(4),v:0,W:a?ba:ca,U:b.stripBOM??!0}},K:(a,b)=>{const c=a.D,d=a.W,e=new Uint16Array((b.length>>1)+2);let f=0,h=0;if(a.v){for(;a.v<4&&f<b.length;)c[a.v++]=b[f++];if(a.v<4)return"";h+=E(d(c,0),e,h)}for(;f<b.length-3;f+=4)h+=E(d(b,f),e,h);a.v=b.length-f;a.v&&c.set(b.subarray(f));b=v(e.subarray(0,h));a.U&&b.charCodeAt(0)===65279&&(b=b.slice(1),a.U=!1);return b},J:a=>a.v?(a.v=0,String.fromCharCode(65533)):""};var Z;
23
+ Z={u:(a,b)=>({r:0,w:0,o:b.addBOM??!1,put:a.O?D:aa,i:0}),l:(a,b,c)=>{const d=a.put;let e=0;if(a.o){if(c.length<4)return;d(65279,c,0);e+=4;a.o=!1}let f=0,h=0;a.i&&(b=String.fromCharCode(a.i)+b,a.i=0,h=1);for(;f<b.length;){const g=b.codePointAt(f);if(f===b.length-1&&g>55296){a.i=g;break}if(c.length-e<4)break;d(g,c,e);f+=g>65535?2:1;e+=4}a.r+=f-h;a.w+=e},m:(a,b)=>{const c=a.put,d=a.i;!d||b.length<4||(c(d,b,0),a.i=0,a.r+=0,a.w+=4)},B:A,F:G};const la=U(32,!0,Y,Z),ma=U(32,!1,Y,Z);ns.Singleton=fa;ns.DBCS=ia;ns.canonicalize=p;ns.createIconv=(a,b)=>new q(a,b);ns.SBCS=ha;ns.UTF_16BE=ka;ns.UTF_16LE=ja;ns.UTF_32BE=ma;ns.UTF_32LE=la;ns.UTF_8=W;
24
+ }
21
25
  export const { canonicalize, createIconv } = ns;
22
- const { DBCS, SBCS, Unicode } = ns;
26
+ const { Singleton, DBCS, SBCS, UTF_16BE, UTF_16LE, UTF_32BE, UTF_32LE, UTF_8 } = ns;
23
27
 
24
28
  export const
25
29
  US_ASCII=new SBCS("US-ASCII","?".repeat(128)),
@@ -195,10 +199,10 @@ CP932=new DBCS("CP932",SHIFT_JIS,[
195
199
  ["fb80","祥禔福禛竑竧靖竫箞精絈絜綷綠緖繒罇羡羽茁荢荿菇菶葈蒴蕓蕙蕫﨟薰蘒﨡蠇裵訒訷詹誧誾諟諸諶譓譿賰賴贒赶﨣軏﨤逸遧郞都鄕鄧釚釗釞釭釮釤釥鈆鈐鈊鈺鉀鈼鉎鉙鉑鈹鉧銧鉷鉸鋧鋗鋙鋐﨧鋕鋠鋓錥錡鋻﨨錞鋿錝錂鍰鍗鎤鏆鏞鏸鐱鑅鑈閒隆﨩隝隯霳霻靃靍靏靑靕顗顥飯飼餧館馞驎髙"],
196
200
  ["fc40","髜魵魲鮏鮱鮻鰀鵰鵫鶴鸙黑"]
197
201
  ]),
198
- UTF8=new Unicode(2,2),
199
- UTF16LE=new Unicode(0,0),
200
- UTF16BE=new Unicode(0,1),
201
- UTF32LE=new Unicode(1,0),
202
- UTF32BE=new Unicode(1,1),
202
+ UTF8=new Singleton(UTF_8),
203
+ UTF16LE=new Singleton(UTF_16LE),
204
+ UTF16BE=new Singleton(UTF_16BE),
205
+ UTF32LE=new Singleton(UTF_32LE),
206
+ UTF32BE=new Singleton(UTF_32BE),
203
207
  encodings={US_ASCII,ISO_8859_1,ISO_8859_2,ISO_8859_3,ISO_8859_4,ISO_8859_5,ISO_8859_6,ISO_8859_7,ISO_8859_8,ISO_8859_9,ISO_8859_10,ISO_8859_11,ISO_8859_13,ISO_8859_14,ISO_8859_15,ISO_8859_16,CP037,CP424,CP500,CP875,CP1026,CP437,CP737,CP775,CP850,CP852,CP855,CP857,CP860,CP861,CP862,CP863,CP864,CP865,CP866,CP869,CP874,CP1250,CP1251,CP1252,CP1253,CP1254,CP1255,CP1256,CP1257,CP1258,MAC_CYRILLIC,MAC_GREEK,MAC_ICELAND,MAC_LATIN2,MAC_ROMAN,MAC_TURKISH,ATARIST,CP856,CP1006,KOI8_R,KOI8_U,KZ1048,NEXTSTEP,JIS_0201,SHIFT_JIS,CP932,UTF8,UTF16LE,UTF16BE,UTF32LE,UTF32BE},
204
208
  aliases="US-ASCII 646 ansix34 ascii ascii7 cp367 csascii default ibm367 iso646irv iso646us isoir6 us,ISO-8859-1 819 88591 cp819 csisolatin1 ibm819 isoir100 l1 latin1,ISO-8859-2 88592 912 cp912 csisolatin2 ibm912 isoir101 l2 latin2,ISO-8859-3 88593 913 cp913 csisolatin3 ibm913 isoir109 l3 latin3,ISO-8859-4 88594 914 cp914 csisolatin4 ibm914 isoir110 l4 latin4,ISO-8859-5 88595 915 cp915 csisolatincyrillic cyrillic ibm915 isoir144,ISO-8859-6 1089 88596 arabic asmo708 cp1089 csisolatinarabic ecma114 ibm1089 isoir127,ISO-8859-7 813 88597 cp813 csisolatingreek ecma118 elot928 greek greek8 ibm813 isoir126 suneugreek,ISO-8859-8 88598 916 cp916 csisolatinhebrew hebrew ibm916 isoir138,ISO-8859-9 88599 920 cp920 csisolatin5 ibm920 isoir148 l5 latin5,ISO-8859-10 csisolatin6 isoir157 l6 latin6,ISO-8859-11 xiso885911,ISO-8859-13 885913,ISO-8859-14 isoceltic isoir199 l8 latin8,ISO-8859-15 885915 923 cp923 csiso885915 csisolatin csisolatin9 ibm923 iso885915fdis l9 latin latin9,ISO-8859-16 csiso885916 iso8859162001 isoir226 l10 latin10,CP037 37 cpibm37 csebcdiccpca csebcdiccpnl csebcdiccpus csebcdiccpwt csibm37 ebcdiccpca ebcdiccpnl ebcdiccpus ebcdiccpwt ibm37,CP424 424 csibm424 ebcdiccphe ibm424,CP500 500 csibm500 ebcdiccpbh ebcdiccpch ibm500,CP875 875 ibm875 xibm875,CP1026 1026 ibm1026,CP437 437 cspc8codepage437 ibm437 windows437,CP737 737 ibm737 xibm737,CP775 775 ibm775,CP850 850 cspc850multilingual ibm850,CP852 852 cspcp852 ibm852,CP855 855 cspcp855 ibm855,CP857 857 csibm857 ibm857,CP860 860 csibm860 ibm860,CP861 861 cpis csibm861 ibm861,CP862 862 csibm862 cspc862latinhebrew ibm862,CP863 863 csibm863 ibm863,CP864 864 csibm864 ibm864,CP865 865 csibm865 ibm865,CP866 866 csibm866 ibm866,CP869 869 cpgr csibm869 ibm869,CP874 874 ibm874 xibm874,CP1250 cp5346 win1250 windows1250,CP1251 ansi1251 cp5347 win1251 windows1251,CP1252 cp5348 ibm1252 win1252 windows1252,CP1253 cp5349 win1253 windows1253,CP1254 cp5350 win1254 windows1254,CP1255 win1255 windows1255,CP1256 win1256 windows1256,CP1257 cp5353 win1257 windows1257,CP1258 win1258 windows1258,MAC-CYRILLIC xmaccyrillic,MAC-GREEK xmacgreek,MAC-ICELAND xmaciceland,MAC-LATIN2 maccentraleurope xmaccentraleurope,MAC-ROMAN xmacroman,MAC-TURKISH xmacturkish,ATARIST,CP856 856 ibm856 xibm856,CP1006 1006 ibm1006 xibm1006,KOI8-R cskoi8r koi8,KOI8-U cskoi8u,KZ1048 cskz1048 rk1048 strk10482002,NEXTSTEP we8nextstep,JIS-0201 cshalfwidthkatakana x201,SHIFT-JIS csshiftjis jis201 mskanji sjis xsjis,CP932 932 ms932 win932 windows31j windows932,UTF8 unicode11utf8,UTF16LE utf16,UTF16BE,UTF32LE utf32,UTF32BE";