iconv-tiny 1.2.1 → 1.2.2
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 +4 -4
- package/dist/iconv-tiny.min.mjs +11 -10
- package/dist/iconv-tiny.mjs +47 -17
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -42,7 +42,7 @@ or use CDN:
|
|
|
42
42
|
<script type="importmap">
|
|
43
43
|
{
|
|
44
44
|
"imports": {
|
|
45
|
-
"iconv-tiny": "https://unpkg.com/iconv-tiny@1.2.
|
|
45
|
+
"iconv-tiny": "https://unpkg.com/iconv-tiny@1.2.2/dist/iconv-tiny.mjs"
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
</script>
|
|
@@ -121,7 +121,7 @@ All encodings are generated automatically from http://www.unicode.org/Public/MAP
|
|
|
121
121
|
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.
|
|
122
122
|
|
|
123
123
|
```
|
|
124
|
-
operation iconv-lite@0.6.3 iconv-tiny@1.2.
|
|
124
|
+
operation iconv-lite@0.6.3 iconv-tiny@1.2.2
|
|
125
125
|
------------------------------------------------------
|
|
126
126
|
encode('win1251') ~598 Mb/s ~622 Mb/s
|
|
127
127
|
decode('win1251') ~218 Mb/s ~263 Mb/s
|
|
@@ -156,8 +156,8 @@ $ npm run coverage
|
|
|
156
156
|
----------------|---------|----------|---------|---------|-------------------
|
|
157
157
|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
|
|
158
158
|
----------------|---------|----------|---------|---------|-------------------
|
|
159
|
-
All files | 100 | 100 |
|
|
160
|
-
commons.mjs | 100 | 100 |
|
|
159
|
+
All files | 100 | 100 | 96.72 | 100 |
|
|
160
|
+
commons.mjs | 100 | 100 | 81.81 | 100 |
|
|
161
161
|
iconv-tiny.mjs | 100 | 100 | 100 | 100 |
|
|
162
162
|
sbcs.mjs | 100 | 100 | 100 | 100 |
|
|
163
163
|
unicode.mjs | 100 | 100 | 100 | 100 |
|
package/dist/iconv-tiny.min.mjs
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* iconv-tiny v1.2.
|
|
2
|
+
* iconv-tiny v1.2.2
|
|
3
3
|
* (c) 2025-present vip.delete
|
|
4
4
|
* @license MIT
|
|
5
5
|
**/
|
|
6
6
|
let ns;
|
|
7
|
-
const k=new TextDecoder("UTF-16LE",{fatal:!0});class l{constructor(a){this.
|
|
8
|
-
class p{encode(a){if(!a)return new Uint8Array(0);const b=new Uint8Array(this.g(a));({written:a}=this.encodeInto(a,b));return b.subarray(0,a)}byteLength(a){let b=0;const c=new Uint8Array(4096);do{const {read:d,written:e}=this.encodeInto(a,c);a=a.slice(d);b+=e}while(a.length);return b}};class q{constructor(a,b){this.g=a;if(typeof b!=="function"){const c=b?.length?b.charCodeAt(0):65533;b=()=>c}this.
|
|
9
|
-
class r extends p{constructor(a,b){super();this.h=a;if(typeof b!=="function"){const c=b?.length?b.charCodeAt(0):63;b=()=>c}this.
|
|
10
|
-
class t extends l{constructor(a,b){super(a);this.
|
|
11
|
-
class u{constructor(a,b,c){this.g=a;this.
|
|
12
|
-
c=56320|c&1023;a[b]=d;a[b+1]=d>>8;a[b+2]=c;a[b+3]=c>>8;return 4}a[b]=c;a[b+1]=c>>8;return 2};class C extends m{constructor(a){super(new TextDecoder("UTF-8",{ignoreBOM:a}))}}
|
|
13
|
-
class
|
|
7
|
+
const k=new TextDecoder("UTF-16LE",{fatal:!0});class l{constructor(a){this.i=a}getName(){return this.i}decode(a,b){b=this.newDecoder(b);return b.decode(a)+b.decode()}encode(a,b){return this.newEncoder(b).encode(a)}}class m{constructor(a){this.g=a}decode(a){return this.g.decode(a,{stream:!!a})}}
|
|
8
|
+
class p{encode(a){this.i();if(!a)return new Uint8Array(0);const b=new Uint8Array(this.g(a));({written:a}=this.encodeInto(a,b));return b.subarray(0,a)}byteLength(a){this.i();let b=0;const c=new Uint8Array(4096);do{const {read:d,written:e}=this.encodeInto(a,c);a=a.slice(d);b+=e}while(a.length);return b}};class q{constructor(a,b){this.g=a;if(typeof b!=="function"){const c=b?.length?b.charCodeAt(0):65533;b=()=>c}this.i=b}decode(a){if(!a)return"";var b=this.g,c=this.i;const d=a.length,e=new Uint16Array(d);for(let g=0;g<d;g++){const h=a[g],n=b[h];e[g]=n===65533?c(h,g)??n:n}if(e.length<=192)var f=String.fromCharCode(...e);else try{f=k.decode(e)}catch{a=e.length;b=[];for(c=0;c<a;c+=1024)b.push(String.fromCharCode(...e.subarray(c,c+1024)));f=b.join("")}return f}}
|
|
9
|
+
class r extends p{constructor(a,b){super();this.h=a;if(typeof b!=="function"){const c=b?.length?b.charCodeAt(0):63;b=()=>c}this.j=b}encodeInto(a,b){const c=this.h,d=this.j,e=Math.min(a.length,b.length);for(let f=0;f<e;f++){const g=a.charCodeAt(f),h=c[g];b[f]=h===65533?d(g,f)??63:h}return{read:e,written:e}}g(a){return a.length}byteLength(a){return this.g(a)}i(){}}
|
|
10
|
+
class t extends l{constructor(a,b){super(a);this.h=b;this.g=null;try{new TextDecoder(this.i),this.j=!0}catch{this.j=!1}}newDecoder(a){return this.j&&(a?.native??!1)?new m(new TextDecoder(this.i)):new q(this.h,a?.defaultCharUnicode)}newEncoder(a){if(!this.g){this.g=(new Uint16Array(65536)).fill(65533);for(let b=0;b<256;b++){const c=this.h[b];c!==65533&&(this.g[c]=b)}}return new r(this.g,a?.defaultCharByte)}}
|
|
11
|
+
class u{constructor(a,b,c){this.g=a;this.i=b;this.h=c}create(a){var b=this.i,c=this.h??"";const d=(new Uint16Array(256)).fill(65533);for(var e=0;e<256-b.length;)d[e]=e++;let f=0;for(;e<256;)d[e++]=b.charCodeAt(f++);for(b=0;b<c.length;)d[c.charCodeAt(b)]=c.charCodeAt(b+1),b+=2;a=a?.overrides??[];for(c=0;c<a.length-1;)b=a[c++],e=a[c++],d[Number(b)]=typeof e==="number"?e:e.charCodeAt(0);return new t(this.g,d)}};const v=(a,b,c,d)=>{a=a.charCodeAt(b);c[d]=a;c[d+1]=a>>8;return 0},w=(a,b,c,d)=>{a=a.charCodeAt(b);c[d]=a>>8;c[d+1]=a;return 0},x=(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},y=(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},z=(a,b)=>(a[b]|a[b+1]<<8|a[b+2]<<16|a[b+3]<<24)>>>0,A=(a,b)=>(a[b]<<24|a[b+1]<<16|a[b+2]<<8|a[b+3])>>>0,B=(a,b,c)=>{c>1114111&&(c=65533);if(c>65535){c-=65536;const d=55296|c>>10;
|
|
12
|
+
c=56320|c&1023;a[b]=d;a[b+1]=d>>8;a[b+2]=c;a[b+3]=c>>8;return 4}a[b]=c;a[b+1]=c>>8;return 2};class C extends m{constructor(a){super(new TextDecoder("UTF-8",{ignoreBOM:a}))}}
|
|
13
|
+
class D extends p{constructor(a){super();this.h=this.j=a;this.l=new TextEncoder}encodeInto(a,b){let c=0;if(this.h){if(b.length<3)return{read:0,written:0};b[0]=239;b[1]=187;b[2]=191;c+=3;this.h=!1}const {read:d,written:e}=this.l.encodeInto(a,b.subarray(c));return{read:d,written:e+c}}g(a){return(this.j?4:0)+a.length*4}i(){this.h=this.j}}
|
|
14
|
+
class E extends p{constructor(a,b,c){super();this.j=this.l=a;this.h=1<<b+1;this.m=b?c?y:x:c?w:v}encodeInto(a,b){const c=this.h,d=this.m;let e=0;if(this.j){if(b.length<c)return{read:0,written:0};d("",0,b,e);e+=c;this.j=!1}const f=Math.min(a.length,b.length-e&~(c-1));for(let g=0;g<f;g++,e+=c)g+=d(a,g,b,e);return{read:f,written:e}}g(a){return(this.l?this.h:0)+a.length*this.h}byteLength(a){return this.h===4?super.byteLength(a):this.g(a)}i(){this.j=this.l}}const F=["LE","BE",""],G=[16,32,8];
|
|
14
15
|
class H extends m{constructor(a,b){super(new TextDecoder("UTF-16"+F[b],{ignoreBOM:a}))}}
|
|
15
|
-
class I{constructor(a,b){this.j=a;this.
|
|
16
|
-
const J=[H,I,C],K=[E,E,D];class L extends l{constructor(a,b){super("UTF-"+G[a]+F[b]);this.g=a;this.
|
|
16
|
+
class I{constructor(a,b){this.j=a;this.i=new Uint8Array(4);this.g=0;this.h=b?A:z}decode(a){if(!a)return this.g?String.fromCharCode(65533):"";const b=new Uint8Array(a.length+4);let c=0,d=0;if(this.g){for(;this.g<4&&c<a.length;)this.i[this.g++]=a[c++];if(this.g<4)return"";d+=B(b,d,this.h(this.i,0))}const e=a.length-3;for(;c<e;c+=4)d+=B(b,d,this.h(a,c));(this.g=a.length-c)&&this.i.set(a.subarray(c));return(new TextDecoder("UTF-16",{ignoreBOM:this.j})).decode(b.subarray(0,d))}}
|
|
17
|
+
const J=[H,I,C],K=[E,E,D];class L extends l{constructor(a,b){super("UTF-"+G[a]+F[b]);this.g=a;this.h=b}newDecoder(a){return new J[this.g](!(a?.stripBOM??!0),this.h)}newEncoder(a){return new K[this.g](a?.addBOM??!1,this.g,this.h)}}class M{constructor(a,b){this.i=a;this.g=b}create(){return new L(this.i,this.g)}};const N=a=>a.toLowerCase().replace(/[^a-z0-9]/gu,"").replace(/(?<!\d)0+/gu,"");
|
|
17
18
|
class O{constructor(a,b){a??={};this.g=new Map;this.cache=new Map;b=(b??"").split(",").map(c=>c.split(" ").map(N));for(const c of Object.keys(a)){const d=a[c];if(d?.create){const e=N(c);this.g.set(e,d);b.filter(f=>f.includes(e)).forEach(f=>f.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=N(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`);
|
|
18
19
|
d=d.create(b);this.cache.set(c,d)}return d}};ns={canonicalize:N,IconvTiny:O,SBCS:u,Unicode:M};
|
|
19
20
|
export const {canonicalize,IconvTiny,SBCS,Unicode}=ns;
|
package/dist/iconv-tiny.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* iconv-tiny v1.2.
|
|
2
|
+
* iconv-tiny v1.2.2
|
|
3
3
|
* (c) 2025-present vip.delete
|
|
4
4
|
* @license MIT
|
|
5
5
|
**/
|
|
@@ -78,6 +78,14 @@ var DEFAULT_NATIVE_DECODE = false;
|
|
|
78
78
|
var STRING_SMALLSIZE = 192;
|
|
79
79
|
var STRING_CHUNKSIZE = 1024;
|
|
80
80
|
var UTF16 = new TextDecoder("UTF-16LE", { fatal: true });
|
|
81
|
+
var getStringFallback = (u16) => {
|
|
82
|
+
const len = u16.length;
|
|
83
|
+
const result = [];
|
|
84
|
+
for (let i = 0; i < len; i += STRING_CHUNKSIZE) {
|
|
85
|
+
result.push(String.fromCharCode(...u16.subarray(i, i + STRING_CHUNKSIZE)));
|
|
86
|
+
}
|
|
87
|
+
return result.join("");
|
|
88
|
+
};
|
|
81
89
|
var getString = (u16) => {
|
|
82
90
|
const len = u16.length;
|
|
83
91
|
if (len <= STRING_SMALLSIZE) {
|
|
@@ -86,12 +94,8 @@ var getString = (u16) => {
|
|
|
86
94
|
try {
|
|
87
95
|
return UTF16.decode(u16);
|
|
88
96
|
} catch {
|
|
97
|
+
return getStringFallback(u16);
|
|
89
98
|
}
|
|
90
|
-
const result = [];
|
|
91
|
-
for (let i = 0; i < len; i += STRING_CHUNKSIZE) {
|
|
92
|
-
result.push(String.fromCharCode(...u16.subarray(i, i + STRING_CHUNKSIZE)));
|
|
93
|
-
}
|
|
94
|
-
return result.join("");
|
|
95
99
|
};
|
|
96
100
|
var Charset = class {
|
|
97
101
|
/**
|
|
@@ -156,6 +160,7 @@ var CharsetEncoderBase = class {
|
|
|
156
160
|
*/
|
|
157
161
|
// @ts-expect-error
|
|
158
162
|
encode(text) {
|
|
163
|
+
this.reset();
|
|
159
164
|
if (!text) {
|
|
160
165
|
return new Uint8Array(0);
|
|
161
166
|
}
|
|
@@ -165,7 +170,7 @@ var CharsetEncoderBase = class {
|
|
|
165
170
|
}
|
|
166
171
|
// @ts-expect-error
|
|
167
172
|
// eslint-disable-next-line jsdoc/empty-tags
|
|
168
|
-
/** @abstract @param {string} text @returns {number}
|
|
173
|
+
/** @abstract @param {string} text @returns {number} */
|
|
169
174
|
// eslint-disable-next-line no-unused-vars, no-empty-function, class-methods-use-this
|
|
170
175
|
byteLengthMax(text) {
|
|
171
176
|
}
|
|
@@ -176,6 +181,7 @@ var CharsetEncoderBase = class {
|
|
|
176
181
|
*/
|
|
177
182
|
// @ts-expect-error
|
|
178
183
|
byteLength(text) {
|
|
184
|
+
this.reset();
|
|
179
185
|
let total = 0;
|
|
180
186
|
const buf = new Uint8Array(4096);
|
|
181
187
|
do {
|
|
@@ -185,6 +191,10 @@ var CharsetEncoderBase = class {
|
|
|
185
191
|
} while (text.length);
|
|
186
192
|
return total;
|
|
187
193
|
}
|
|
194
|
+
/** @abstract */
|
|
195
|
+
// eslint-disable-next-line no-empty-function, class-methods-use-this
|
|
196
|
+
reset() {
|
|
197
|
+
}
|
|
188
198
|
};
|
|
189
199
|
|
|
190
200
|
// src/sbcs.mjs
|
|
@@ -270,6 +280,12 @@ var SBCSEncoder = class extends CharsetEncoderBase {
|
|
|
270
280
|
byteLength(text) {
|
|
271
281
|
return this.byteLengthMax(text);
|
|
272
282
|
}
|
|
283
|
+
/**
|
|
284
|
+
* @override
|
|
285
|
+
*/
|
|
286
|
+
// eslint-disable-next-line class-methods-use-this
|
|
287
|
+
reset() {
|
|
288
|
+
}
|
|
273
289
|
};
|
|
274
290
|
var SBCSCharset = class extends Charset {
|
|
275
291
|
/**
|
|
@@ -374,8 +390,8 @@ var SBCS = class {
|
|
|
374
390
|
|
|
375
391
|
// src/unicode.mjs
|
|
376
392
|
var BOM_CHAR = "\uFEFF";
|
|
377
|
-
var STRIP_BOM_DEFAULT =
|
|
378
|
-
var ADD_BOM_DEFAULT =
|
|
393
|
+
var STRIP_BOM_DEFAULT = true;
|
|
394
|
+
var ADD_BOM_DEFAULT = false;
|
|
379
395
|
var put16LE = (src, i, dst, j) => {
|
|
380
396
|
const cp = src.charCodeAt(i);
|
|
381
397
|
dst[j] = cp;
|
|
@@ -440,11 +456,12 @@ var UTF8Decoder = class extends NativeCharsetDecoder {
|
|
|
440
456
|
};
|
|
441
457
|
var UTF8Encoder = class extends CharsetEncoderBase {
|
|
442
458
|
/**
|
|
443
|
-
* @param {
|
|
459
|
+
* @param {boolean} doBOM
|
|
444
460
|
*/
|
|
445
461
|
constructor(doBOM) {
|
|
446
462
|
super();
|
|
447
463
|
this.doBOM = doBOM;
|
|
464
|
+
this.appendBOM = doBOM;
|
|
448
465
|
this.encoder = new TextEncoder();
|
|
449
466
|
}
|
|
450
467
|
/**
|
|
@@ -455,9 +472,9 @@ var UTF8Encoder = class extends CharsetEncoderBase {
|
|
|
455
472
|
*/
|
|
456
473
|
// @ts-expect-error
|
|
457
474
|
encodeInto(src, dst) {
|
|
458
|
-
const {
|
|
475
|
+
const { appendBOM } = this;
|
|
459
476
|
let j = 0;
|
|
460
|
-
if (
|
|
477
|
+
if (appendBOM) {
|
|
461
478
|
if (dst.length < 3) {
|
|
462
479
|
return { read: 0, written: 0 };
|
|
463
480
|
}
|
|
@@ -465,7 +482,7 @@ var UTF8Encoder = class extends CharsetEncoderBase {
|
|
|
465
482
|
dst[1] = 187;
|
|
466
483
|
dst[2] = 191;
|
|
467
484
|
j += 3;
|
|
468
|
-
this.
|
|
485
|
+
this.appendBOM = false;
|
|
469
486
|
}
|
|
470
487
|
const { read, written } = this.encoder.encodeInto(src, dst.subarray(j));
|
|
471
488
|
return { read, written: written + j };
|
|
@@ -478,16 +495,23 @@ var UTF8Encoder = class extends CharsetEncoderBase {
|
|
|
478
495
|
byteLengthMax(src) {
|
|
479
496
|
return (this.doBOM ? 4 : 0) + src.length * 4;
|
|
480
497
|
}
|
|
498
|
+
/**
|
|
499
|
+
* @override
|
|
500
|
+
*/
|
|
501
|
+
reset() {
|
|
502
|
+
this.appendBOM = this.doBOM;
|
|
503
|
+
}
|
|
481
504
|
};
|
|
482
505
|
var UnicodeEncoder = class extends CharsetEncoderBase {
|
|
483
506
|
/**
|
|
484
|
-
* @param {
|
|
507
|
+
* @param {boolean} doBOM
|
|
485
508
|
* @param {number} i - 0 for UTF-16, 1 for UTF-32
|
|
486
509
|
* @param {number} bo - 0 for LE, 1 for BE
|
|
487
510
|
*/
|
|
488
511
|
constructor(doBOM, i, bo) {
|
|
489
512
|
super();
|
|
490
513
|
this.doBOM = doBOM;
|
|
514
|
+
this.appendBOM = doBOM;
|
|
491
515
|
this.sz = 1 << i + 1;
|
|
492
516
|
this.put = i ? bo ? put32BE : put32LE : bo ? put16BE : put16LE;
|
|
493
517
|
}
|
|
@@ -499,15 +523,15 @@ var UnicodeEncoder = class extends CharsetEncoderBase {
|
|
|
499
523
|
*/
|
|
500
524
|
// @ts-expect-error
|
|
501
525
|
encodeInto(src, dst) {
|
|
502
|
-
const {
|
|
526
|
+
const { appendBOM, sz, put } = this;
|
|
503
527
|
let j = 0;
|
|
504
|
-
if (
|
|
528
|
+
if (appendBOM) {
|
|
505
529
|
if (dst.length < sz) {
|
|
506
530
|
return { read: 0, written: 0 };
|
|
507
531
|
}
|
|
508
532
|
put(BOM_CHAR, 0, dst, j);
|
|
509
533
|
j += sz;
|
|
510
|
-
this.
|
|
534
|
+
this.appendBOM = false;
|
|
511
535
|
}
|
|
512
536
|
const max = Math.min(src.length, dst.length - j & ~(sz - 1));
|
|
513
537
|
for (let i = 0; i < max; i++, j += sz) {
|
|
@@ -534,6 +558,12 @@ var UnicodeEncoder = class extends CharsetEncoderBase {
|
|
|
534
558
|
}
|
|
535
559
|
return this.byteLengthMax(text);
|
|
536
560
|
}
|
|
561
|
+
/**
|
|
562
|
+
* @override
|
|
563
|
+
*/
|
|
564
|
+
reset() {
|
|
565
|
+
this.appendBOM = this.doBOM;
|
|
566
|
+
}
|
|
537
567
|
};
|
|
538
568
|
var POSTFIX = ["LE", "BE", ""];
|
|
539
569
|
var NAMES = [16, 32, 8];
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "iconv-tiny",
|
|
4
|
-
"version": "1.2.
|
|
4
|
+
"version": "1.2.2",
|
|
5
5
|
"description": "Pure JS ESM Encodings for Browser and NodeJS",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"keywords": [
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"coverage": "vitest run --coverage main.test.mjs",
|
|
39
39
|
"test": "vitest run",
|
|
40
40
|
"build": "npm run lint && npm run generate && npm run test && npm run coverage",
|
|
41
|
-
"dev": "node scripts/server.
|
|
41
|
+
"dev": "node scripts/server.mjs"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@stylistic/eslint-plugin": "^5.x",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"eslint": "^9.x",
|
|
53
53
|
"eslint-plugin-jsdoc": "^51.x",
|
|
54
54
|
"express": "^5.x",
|
|
55
|
-
"google-closure-compiler": "^
|
|
55
|
+
"google-closure-compiler": "^20250709.0.0",
|
|
56
56
|
"iconv-lite": "^0.6.3",
|
|
57
57
|
"prettier": "^3.x",
|
|
58
58
|
"serve-static": "^2.x",
|