iconv-nano 0.0.0-stage → 0.0.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/LICENSE +9 -0
- package/README.md +75 -2
- package/dist/_virtual/_rolldown/runtime.js +18 -0
- package/dist/codecs/big5.d.ts +8 -0
- package/dist/codecs/big5.js +39 -0
- package/dist/codecs/euc-kr.d.ts +8 -0
- package/dist/codecs/euc-kr.js +38 -0
- package/dist/codecs/gb18030.d.ts +8 -0
- package/dist/codecs/gb18030.js +92 -0
- package/dist/codecs/shift_jis.d.ts +8 -0
- package/dist/codecs/shift_jis.js +50 -0
- package/dist/codecs/single-byte/ibm866.d.ts +8 -0
- package/dist/codecs/single-byte/ibm866.js +23 -0
- package/dist/codecs/single-byte/iso-8859-10.d.ts +8 -0
- package/dist/codecs/single-byte/iso-8859-10.js +23 -0
- package/dist/codecs/single-byte/iso-8859-13.d.ts +8 -0
- package/dist/codecs/single-byte/iso-8859-13.js +23 -0
- package/dist/codecs/single-byte/iso-8859-14.d.ts +8 -0
- package/dist/codecs/single-byte/iso-8859-14.js +23 -0
- package/dist/codecs/single-byte/iso-8859-15.d.ts +8 -0
- package/dist/codecs/single-byte/iso-8859-15.js +23 -0
- package/dist/codecs/single-byte/iso-8859-16.d.ts +8 -0
- package/dist/codecs/single-byte/iso-8859-16.js +23 -0
- package/dist/codecs/single-byte/iso-8859-2.d.ts +8 -0
- package/dist/codecs/single-byte/iso-8859-2.js +23 -0
- package/dist/codecs/single-byte/iso-8859-3.d.ts +8 -0
- package/dist/codecs/single-byte/iso-8859-3.js +23 -0
- package/dist/codecs/single-byte/iso-8859-4.d.ts +8 -0
- package/dist/codecs/single-byte/iso-8859-4.js +23 -0
- package/dist/codecs/single-byte/iso-8859-5.d.ts +8 -0
- package/dist/codecs/single-byte/iso-8859-5.js +23 -0
- package/dist/codecs/single-byte/iso-8859-6.d.ts +8 -0
- package/dist/codecs/single-byte/iso-8859-6.js +23 -0
- package/dist/codecs/single-byte/iso-8859-7.d.ts +8 -0
- package/dist/codecs/single-byte/iso-8859-7.js +23 -0
- package/dist/codecs/single-byte/iso-8859-8-i.d.ts +8 -0
- package/dist/codecs/single-byte/iso-8859-8-i.js +23 -0
- package/dist/codecs/single-byte/iso-8859-8.d.ts +8 -0
- package/dist/codecs/single-byte/iso-8859-8.js +23 -0
- package/dist/codecs/single-byte/koi8-r.d.ts +8 -0
- package/dist/codecs/single-byte/koi8-r.js +23 -0
- package/dist/codecs/single-byte/koi8-u.d.ts +8 -0
- package/dist/codecs/single-byte/koi8-u.js +23 -0
- package/dist/codecs/single-byte/macintosh.d.ts +8 -0
- package/dist/codecs/single-byte/macintosh.js +23 -0
- package/dist/codecs/single-byte/windows-1250.d.ts +8 -0
- package/dist/codecs/single-byte/windows-1250.js +23 -0
- package/dist/codecs/single-byte/windows-1251.d.ts +8 -0
- package/dist/codecs/single-byte/windows-1251.js +23 -0
- package/dist/codecs/single-byte/windows-1252.d.ts +8 -0
- package/dist/codecs/single-byte/windows-1252.js +23 -0
- package/dist/codecs/single-byte/windows-1253.d.ts +8 -0
- package/dist/codecs/single-byte/windows-1253.js +23 -0
- package/dist/codecs/single-byte/windows-1254.d.ts +8 -0
- package/dist/codecs/single-byte/windows-1254.js +23 -0
- package/dist/codecs/single-byte/windows-1255.d.ts +8 -0
- package/dist/codecs/single-byte/windows-1255.js +23 -0
- package/dist/codecs/single-byte/windows-1256.d.ts +8 -0
- package/dist/codecs/single-byte/windows-1256.js +23 -0
- package/dist/codecs/single-byte/windows-1257.d.ts +8 -0
- package/dist/codecs/single-byte/windows-1257.js +23 -0
- package/dist/codecs/single-byte/windows-1258.d.ts +8 -0
- package/dist/codecs/single-byte/windows-1258.js +23 -0
- package/dist/codecs/single-byte/windows-874.d.ts +8 -0
- package/dist/codecs/single-byte/windows-874.js +23 -0
- package/dist/codecs/single-byte/x-mac-cyrillic.d.ts +8 -0
- package/dist/codecs/single-byte/x-mac-cyrillic.js +23 -0
- package/dist/codecs/utf-16.d.ts +12 -0
- package/dist/codecs/utf-16.js +36 -0
- package/dist/codecs/utf-16be.d.ts +8 -0
- package/dist/codecs/utf-16be.js +19 -0
- package/dist/codecs/utf-16le.d.ts +8 -0
- package/dist/codecs/utf-16le.js +19 -0
- package/dist/codecs/utf-8.d.ts +8 -0
- package/dist/codecs/utf-8.js +22 -0
- package/dist/encodings/big5.js +1 -0
- package/dist/encodings/euc-kr.js +1 -0
- package/dist/encodings/gb18030-ranges.js +1 -0
- package/dist/encodings/gb18030.js +1 -0
- package/dist/encodings/ibm866.js +1 -0
- package/dist/encodings/iso-8859-10.js +1 -0
- package/dist/encodings/iso-8859-13.js +1 -0
- package/dist/encodings/iso-8859-14.js +1 -0
- package/dist/encodings/iso-8859-15.js +1 -0
- package/dist/encodings/iso-8859-16.js +1 -0
- package/dist/encodings/iso-8859-2.js +1 -0
- package/dist/encodings/iso-8859-3.js +1 -0
- package/dist/encodings/iso-8859-4.js +1 -0
- package/dist/encodings/iso-8859-5.js +1 -0
- package/dist/encodings/iso-8859-6.js +1 -0
- package/dist/encodings/iso-8859-7.js +1 -0
- package/dist/encodings/iso-8859-8.js +1 -0
- package/dist/encodings/koi8-r.js +1 -0
- package/dist/encodings/koi8-u.js +1 -0
- package/dist/encodings/macintosh.js +1 -0
- package/dist/encodings/shift_jis.js +1 -0
- package/dist/encodings/windows-1250.js +1 -0
- package/dist/encodings/windows-1251.js +1 -0
- package/dist/encodings/windows-1252.js +1 -0
- package/dist/encodings/windows-1253.js +1 -0
- package/dist/encodings/windows-1254.js +1 -0
- package/dist/encodings/windows-1255.js +1 -0
- package/dist/encodings/windows-1256.js +1 -0
- package/dist/encodings/windows-1257.js +1 -0
- package/dist/encodings/windows-1258.js +1 -0
- package/dist/encodings/windows-874.js +1 -0
- package/dist/encodings/x-mac-cyrillic.js +1 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.js +38 -0
- package/dist/interfaces.d.ts +28 -0
- package/dist/utils/encodeSingleByteEncoding.js +16 -0
- package/dist/utils/getCachedTextDecoder.js +15 -0
- package/dist/utils/getCachedTextEncoder.js +8 -0
- package/package.json +80 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Copyright 2026 Jeremy Nguyen
|
|
2
|
+
|
|
3
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
4
|
+
|
|
5
|
+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
6
|
+
|
|
7
|
+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
8
|
+
|
|
9
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,76 @@
|
|
|
1
|
-
#
|
|
1
|
+
# iconv-nano
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[github-actions]: https://www.github.com/jeremy-code/iconv-nano/actions/workflows/ci.yml
|
|
4
|
+
[github-actions-badge]: https://www.github.com/jeremy-code/iconv-nano/actions/workflows/ci.yml/badge.svg
|
|
5
|
+
[license-badge]: https://img.shields.io/github/license/jeremy-code/iconv-nano
|
|
6
|
+
[npm-version-badge]: https://img.shields.io/npm/v/iconv-nano
|
|
7
|
+
[npm-package]: https://www.npmjs.com/package/iconv-nano
|
|
8
|
+
|
|
9
|
+
[![GitHub Actions][github-actions-badge]][github-actions] [![License][license-badge]](LICENSE) [![NPM version][npm-version-badge]][npm-package]
|
|
10
|
+
|
|
11
|
+
You probably shouldn't use this for now.
|
|
12
|
+
|
|
13
|
+
I'm waiting on ESM [namespace imports](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#namespace_import) in Rolldown ([rolldown/rolldown#7874](https://github.com/rolldown/rolldown/issues/7874)) to be supported. It looks like it will be coming on Rolldown 1.4. While tree-shaking will still work for encodings, the individual `encode`/`decode` functions cannot be treeshook until this is resolved.
|
|
14
|
+
|
|
15
|
+
Documentation is avaliable at this URL: https://npmx.dev/package-docs/iconv-nano.
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
import * as iconv from "iconv-nano";
|
|
21
|
+
|
|
22
|
+
iconv.utf8.encode("😅").toHex(); // "f09f9885"
|
|
23
|
+
iconv.utf8.decode(Uint8Array.fromHex("f09f9885")); // "😅"
|
|
24
|
+
|
|
25
|
+
iconv.ascii.encode("😅").toHex(); // "3f"
|
|
26
|
+
iconv.ascii.decode(Uint8Array.fromHex("3f")); // "?"
|
|
27
|
+
|
|
28
|
+
iconv.utf16.encode("😅", { endianness: "little-endian" }).toHex(); // "3dd805de"
|
|
29
|
+
iconv.utf16.decode(Uint8Array.fromHex("3dd805de")); // "😅"
|
|
30
|
+
|
|
31
|
+
iconv.shift_jis.encode("文字化け"); // "95b68e9a89bb82af"
|
|
32
|
+
iconv.shift_jis.decode(Uint8Array.fromHex("95b68e9a89bb82af")); // "文字化け"
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Supported encodings
|
|
36
|
+
|
|
37
|
+
- UTF-8
|
|
38
|
+
- IBM866
|
|
39
|
+
- ISO-8859-2
|
|
40
|
+
- ISO-8859-3
|
|
41
|
+
- ISO-8859-4
|
|
42
|
+
- ISO-8859-5
|
|
43
|
+
- ISO-8859-6
|
|
44
|
+
- ISO-8859-7
|
|
45
|
+
- ISO-8859-8
|
|
46
|
+
- ISO-8859-8-1
|
|
47
|
+
- ISO-8859-10
|
|
48
|
+
- ISO-8859-13
|
|
49
|
+
- ISO-8859-14
|
|
50
|
+
- ISO-8859-15
|
|
51
|
+
- ISO-8859-16
|
|
52
|
+
- KOI8-R
|
|
53
|
+
- KOI8-U
|
|
54
|
+
- macintosh
|
|
55
|
+
- windows-874
|
|
56
|
+
- windows-1250
|
|
57
|
+
- windows-1251
|
|
58
|
+
- windows-1252
|
|
59
|
+
- windows-1253
|
|
60
|
+
- windows-1254
|
|
61
|
+
- windows-1255
|
|
62
|
+
- windows-1256
|
|
63
|
+
- windows-1257
|
|
64
|
+
- windows-1258
|
|
65
|
+
- x-mac-cyrillic
|
|
66
|
+
- utf-16
|
|
67
|
+
- utf-16be
|
|
68
|
+
- utf-16le
|
|
69
|
+
- Shift_JIS
|
|
70
|
+
- EUC-KR
|
|
71
|
+
- Big5
|
|
72
|
+
- gb18030
|
|
73
|
+
|
|
74
|
+
## License
|
|
75
|
+
|
|
76
|
+
This project is licensed under the MIT license. See the [LICENSE](LICENSE) file for details.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __exportAll = (all, no_symbols) => {
|
|
4
|
+
let target = {};
|
|
5
|
+
for (var name in all) {
|
|
6
|
+
__defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: true
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
if (!no_symbols) {
|
|
12
|
+
__defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
13
|
+
}
|
|
14
|
+
return target;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
export { __exportAll };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { __exportAll } from "../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { getCachedTextDecoder } from "../utils/getCachedTextDecoder.js";
|
|
3
|
+
import big5_default from "../encodings/big5.js";
|
|
4
|
+
|
|
5
|
+
//#region src/codecs/big5.ts
|
|
6
|
+
var big5_exports = /* @__PURE__ */ __exportAll({
|
|
7
|
+
decode: () => decode,
|
|
8
|
+
encode: () => encode
|
|
9
|
+
});
|
|
10
|
+
const encode = (input) => {
|
|
11
|
+
const buf = new Uint8Array(input.length * 2);
|
|
12
|
+
let byteOffset = 0;
|
|
13
|
+
for (const char of input) {
|
|
14
|
+
let codePoint = char.codePointAt(0);
|
|
15
|
+
if (0 <= codePoint && codePoint <= 127) {
|
|
16
|
+
buf[byteOffset] = codePoint;
|
|
17
|
+
byteOffset++;
|
|
18
|
+
} else {
|
|
19
|
+
const pointer = big5_default[String.fromCodePoint(codePoint)];
|
|
20
|
+
const leading = Math.floor(pointer / 157) + 129;
|
|
21
|
+
const trailing = pointer % 157;
|
|
22
|
+
const offset = trailing < 63 ? 64 : 98;
|
|
23
|
+
buf[byteOffset] = leading;
|
|
24
|
+
buf[byteOffset + 1] = trailing + offset;
|
|
25
|
+
byteOffset += 2;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return buf.subarray(0, byteOffset);
|
|
29
|
+
};
|
|
30
|
+
const decode = (input, decodeOptions) => {
|
|
31
|
+
const stripBOM = decodeOptions?.stripBOM ?? true;
|
|
32
|
+
return getCachedTextDecoder("big5", {
|
|
33
|
+
fatal: false,
|
|
34
|
+
ignoreBOM: !stripBOM
|
|
35
|
+
}).decode(input);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
export { big5_exports, decode, encode };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { __exportAll } from "../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { getCachedTextDecoder } from "../utils/getCachedTextDecoder.js";
|
|
3
|
+
import euc_kr_default from "../encodings/euc-kr.js";
|
|
4
|
+
|
|
5
|
+
//#region src/codecs/euc-kr.ts
|
|
6
|
+
var euc_kr_exports = /* @__PURE__ */ __exportAll({
|
|
7
|
+
decode: () => decode,
|
|
8
|
+
encode: () => encode
|
|
9
|
+
});
|
|
10
|
+
const encode = (input) => {
|
|
11
|
+
const buf = new Uint8Array(input.length * 2);
|
|
12
|
+
let byteOffset = 0;
|
|
13
|
+
for (const char of input) {
|
|
14
|
+
let codePoint = char.codePointAt(0);
|
|
15
|
+
if (0 <= codePoint && codePoint <= 127) {
|
|
16
|
+
buf[byteOffset] = codePoint;
|
|
17
|
+
byteOffset++;
|
|
18
|
+
} else {
|
|
19
|
+
const pointer = euc_kr_default[String.fromCodePoint(codePoint)];
|
|
20
|
+
const leading = Math.floor(pointer / 190) + 129;
|
|
21
|
+
const trailing = pointer % 190 + 65;
|
|
22
|
+
buf[byteOffset] = leading;
|
|
23
|
+
buf[byteOffset + 1] = trailing;
|
|
24
|
+
byteOffset += 2;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return buf.subarray(0, byteOffset);
|
|
28
|
+
};
|
|
29
|
+
const decode = (input, decodeOptions) => {
|
|
30
|
+
const stripBOM = decodeOptions?.stripBOM ?? true;
|
|
31
|
+
return getCachedTextDecoder("euc-kr", {
|
|
32
|
+
fatal: false,
|
|
33
|
+
ignoreBOM: !stripBOM
|
|
34
|
+
}).decode(input);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
export { decode, encode, euc_kr_exports };
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { __exportAll } from "../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { getCachedTextDecoder } from "../utils/getCachedTextDecoder.js";
|
|
3
|
+
import gb18030_ranges_default from "../encodings/gb18030-ranges.js";
|
|
4
|
+
import gb18030_default from "../encodings/gb18030.js";
|
|
5
|
+
|
|
6
|
+
//#region src/codecs/gb18030.ts
|
|
7
|
+
var gb18030_exports = /* @__PURE__ */ __exportAll({
|
|
8
|
+
decode: () => decode,
|
|
9
|
+
encode: () => encode
|
|
10
|
+
});
|
|
11
|
+
const TABLE = {
|
|
12
|
+
59277: [166, 217],
|
|
13
|
+
59278: [166, 218],
|
|
14
|
+
59279: [166, 219],
|
|
15
|
+
59280: [166, 220],
|
|
16
|
+
59281: [166, 221],
|
|
17
|
+
59282: [166, 222],
|
|
18
|
+
59283: [166, 223],
|
|
19
|
+
59284: [166, 236],
|
|
20
|
+
59285: [166, 237],
|
|
21
|
+
59286: [166, 243],
|
|
22
|
+
59422: [254, 89],
|
|
23
|
+
59430: [254, 97],
|
|
24
|
+
59435: [254, 102],
|
|
25
|
+
59436: [254, 103],
|
|
26
|
+
59442: [254, 109],
|
|
27
|
+
59459: [254, 126],
|
|
28
|
+
59476: [254, 144],
|
|
29
|
+
59492: [254, 160]
|
|
30
|
+
};
|
|
31
|
+
const getGb18030RangesPointer = (codePoint) => {
|
|
32
|
+
if (codePoint === 59335) return 7457;
|
|
33
|
+
let rangeIndex = void 0;
|
|
34
|
+
let [left, right] = [0, gb18030_ranges_default.length - 1];
|
|
35
|
+
while (left <= right) {
|
|
36
|
+
const mid = left + right >> 1;
|
|
37
|
+
if (gb18030_ranges_default[mid][1] <= codePoint) {
|
|
38
|
+
rangeIndex = mid;
|
|
39
|
+
left = mid + 1;
|
|
40
|
+
} else right = mid - 1;
|
|
41
|
+
}
|
|
42
|
+
if (rangeIndex === void 0) throw new Error("dfsifkj");
|
|
43
|
+
const [pointerOffset, codePointOffset] = gb18030_ranges_default[rangeIndex];
|
|
44
|
+
return pointerOffset + codePoint - codePointOffset;
|
|
45
|
+
};
|
|
46
|
+
const encode = (input) => {
|
|
47
|
+
const buf = new Uint8Array(input.length * 2);
|
|
48
|
+
let byteOffset = 0;
|
|
49
|
+
for (const char of input) {
|
|
50
|
+
let codePoint = char.codePointAt(0);
|
|
51
|
+
if (0 <= codePoint && codePoint <= 127) {
|
|
52
|
+
buf[byteOffset] = codePoint;
|
|
53
|
+
byteOffset++;
|
|
54
|
+
} else if (codePoint === 58853) continue;
|
|
55
|
+
else if (codePoint in TABLE) {
|
|
56
|
+
buf.set(TABLE[codePoint], byteOffset);
|
|
57
|
+
byteOffset += 2;
|
|
58
|
+
} else {
|
|
59
|
+
let pointer = gb18030_default[String.fromCodePoint(codePoint)];
|
|
60
|
+
if (pointer !== void 0) {
|
|
61
|
+
const leading = Math.floor(pointer / 190) + 129;
|
|
62
|
+
const trailing = pointer % 190;
|
|
63
|
+
const offset = trailing < 63 ? 64 : 65;
|
|
64
|
+
buf[byteOffset] = leading;
|
|
65
|
+
buf[byteOffset + 1] = trailing + offset;
|
|
66
|
+
byteOffset += 2;
|
|
67
|
+
}
|
|
68
|
+
pointer = getGb18030RangesPointer(codePoint);
|
|
69
|
+
const byte1 = Math.floor(pointer / 12600);
|
|
70
|
+
pointer = pointer % 12600;
|
|
71
|
+
const byte2 = Math.floor(pointer / 1260);
|
|
72
|
+
pointer = pointer % 1260;
|
|
73
|
+
const byte3 = pointer / 10;
|
|
74
|
+
const byte4 = pointer % 10;
|
|
75
|
+
buf[byteOffset] = byte1 + 129;
|
|
76
|
+
buf[byteOffset + 1] = byte2 + 48;
|
|
77
|
+
buf[byteOffset + 2] = byte3 + 129;
|
|
78
|
+
buf[byteOffset + 3] = byte4 + 48;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return buf.subarray(0, byteOffset);
|
|
82
|
+
};
|
|
83
|
+
const decode = (input, decodeOptions) => {
|
|
84
|
+
const stripBOM = decodeOptions?.stripBOM ?? true;
|
|
85
|
+
return getCachedTextDecoder("gb18030", {
|
|
86
|
+
fatal: false,
|
|
87
|
+
ignoreBOM: !stripBOM
|
|
88
|
+
}).decode(input);
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
//#endregion
|
|
92
|
+
export { decode, encode, gb18030_exports };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { __exportAll } from "../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { getCachedTextDecoder } from "../utils/getCachedTextDecoder.js";
|
|
3
|
+
import shift_jis_default from "../encodings/shift_jis.js";
|
|
4
|
+
|
|
5
|
+
//#region src/codecs/shift_jis.ts
|
|
6
|
+
var shift_jis_exports = /* @__PURE__ */ __exportAll({
|
|
7
|
+
decode: () => decode,
|
|
8
|
+
encode: () => encode
|
|
9
|
+
});
|
|
10
|
+
const encode = (input) => {
|
|
11
|
+
const buf = new Uint8Array(input.length * 2);
|
|
12
|
+
let byteOffset = 0;
|
|
13
|
+
for (const char of input) {
|
|
14
|
+
let codePoint = char.codePointAt(0);
|
|
15
|
+
if (0 <= codePoint && codePoint <= 127 || codePoint === 128) {
|
|
16
|
+
buf[byteOffset] = codePoint;
|
|
17
|
+
byteOffset++;
|
|
18
|
+
} else if (codePoint === 165) {
|
|
19
|
+
buf[byteOffset] = 92;
|
|
20
|
+
byteOffset++;
|
|
21
|
+
} else if (codePoint === 8254) {
|
|
22
|
+
buf[byteOffset] = 126;
|
|
23
|
+
byteOffset++;
|
|
24
|
+
} else if (65377 <= codePoint && codePoint <= 65439) {
|
|
25
|
+
buf[byteOffset] = codePoint - 65377 + 161;
|
|
26
|
+
byteOffset++;
|
|
27
|
+
} else {
|
|
28
|
+
if (codePoint === 8722) codePoint = 65293;
|
|
29
|
+
const pointer = shift_jis_default[String.fromCodePoint(codePoint)];
|
|
30
|
+
const leading = Math.floor(pointer / 188);
|
|
31
|
+
const leadingOffset = leading < 31 ? 129 : 193;
|
|
32
|
+
const trailing = pointer % 188;
|
|
33
|
+
const offset = trailing < 63 ? 64 : 65;
|
|
34
|
+
buf[byteOffset] = leading + leadingOffset;
|
|
35
|
+
buf[byteOffset + 1] = trailing + offset;
|
|
36
|
+
byteOffset += 2;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return buf.subarray(0, byteOffset);
|
|
40
|
+
};
|
|
41
|
+
const decode = (input, decodeOptions) => {
|
|
42
|
+
const stripBOM = decodeOptions?.stripBOM ?? true;
|
|
43
|
+
return getCachedTextDecoder("shift_jis", {
|
|
44
|
+
fatal: false,
|
|
45
|
+
ignoreBOM: !stripBOM
|
|
46
|
+
}).decode(input);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
//#endregion
|
|
50
|
+
export { decode, encode, shift_jis_exports };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { __exportAll } from "../../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { getCachedTextDecoder } from "../../utils/getCachedTextDecoder.js";
|
|
3
|
+
import ibm866_default from "../../encodings/ibm866.js";
|
|
4
|
+
import { encodeSingleByteEncoding } from "../../utils/encodeSingleByteEncoding.js";
|
|
5
|
+
|
|
6
|
+
//#region src/codecs/single-byte/ibm866.ts
|
|
7
|
+
var ibm866_exports = /* @__PURE__ */ __exportAll({
|
|
8
|
+
decode: () => decode,
|
|
9
|
+
encode: () => encode
|
|
10
|
+
});
|
|
11
|
+
const encode = (input) => {
|
|
12
|
+
return encodeSingleByteEncoding(input, ibm866_default);
|
|
13
|
+
};
|
|
14
|
+
const decode = (input, decodeOptions) => {
|
|
15
|
+
const stripBOM = decodeOptions?.stripBOM ?? true;
|
|
16
|
+
return getCachedTextDecoder("ibm866", {
|
|
17
|
+
fatal: false,
|
|
18
|
+
ignoreBOM: !stripBOM
|
|
19
|
+
}).decode(input);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
export { decode, encode, ibm866_exports };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { __exportAll } from "../../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { getCachedTextDecoder } from "../../utils/getCachedTextDecoder.js";
|
|
3
|
+
import { encodeSingleByteEncoding } from "../../utils/encodeSingleByteEncoding.js";
|
|
4
|
+
import iso_8859_10_default from "../../encodings/iso-8859-10.js";
|
|
5
|
+
|
|
6
|
+
//#region src/codecs/single-byte/iso-8859-10.ts
|
|
7
|
+
var iso_8859_10_exports = /* @__PURE__ */ __exportAll({
|
|
8
|
+
decode: () => decode,
|
|
9
|
+
encode: () => encode
|
|
10
|
+
});
|
|
11
|
+
const encode = (input) => {
|
|
12
|
+
return encodeSingleByteEncoding(input, iso_8859_10_default);
|
|
13
|
+
};
|
|
14
|
+
const decode = (input, decodeOptions) => {
|
|
15
|
+
const stripBOM = decodeOptions?.stripBOM ?? true;
|
|
16
|
+
return getCachedTextDecoder("iso-8859-10", {
|
|
17
|
+
fatal: false,
|
|
18
|
+
ignoreBOM: !stripBOM
|
|
19
|
+
}).decode(input);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
export { decode, encode, iso_8859_10_exports };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { __exportAll } from "../../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { getCachedTextDecoder } from "../../utils/getCachedTextDecoder.js";
|
|
3
|
+
import { encodeSingleByteEncoding } from "../../utils/encodeSingleByteEncoding.js";
|
|
4
|
+
import iso_8859_13_default from "../../encodings/iso-8859-13.js";
|
|
5
|
+
|
|
6
|
+
//#region src/codecs/single-byte/iso-8859-13.ts
|
|
7
|
+
var iso_8859_13_exports = /* @__PURE__ */ __exportAll({
|
|
8
|
+
decode: () => decode,
|
|
9
|
+
encode: () => encode
|
|
10
|
+
});
|
|
11
|
+
const encode = (input) => {
|
|
12
|
+
return encodeSingleByteEncoding(input, iso_8859_13_default);
|
|
13
|
+
};
|
|
14
|
+
const decode = (input, decodeOptions) => {
|
|
15
|
+
const stripBOM = decodeOptions?.stripBOM ?? true;
|
|
16
|
+
return getCachedTextDecoder("iso-8859-13", {
|
|
17
|
+
fatal: false,
|
|
18
|
+
ignoreBOM: !stripBOM
|
|
19
|
+
}).decode(input);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
export { decode, encode, iso_8859_13_exports };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { __exportAll } from "../../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { getCachedTextDecoder } from "../../utils/getCachedTextDecoder.js";
|
|
3
|
+
import { encodeSingleByteEncoding } from "../../utils/encodeSingleByteEncoding.js";
|
|
4
|
+
import iso_8859_14_default from "../../encodings/iso-8859-14.js";
|
|
5
|
+
|
|
6
|
+
//#region src/codecs/single-byte/iso-8859-14.ts
|
|
7
|
+
var iso_8859_14_exports = /* @__PURE__ */ __exportAll({
|
|
8
|
+
decode: () => decode,
|
|
9
|
+
encode: () => encode
|
|
10
|
+
});
|
|
11
|
+
const encode = (input) => {
|
|
12
|
+
return encodeSingleByteEncoding(input, iso_8859_14_default);
|
|
13
|
+
};
|
|
14
|
+
const decode = (input, decodeOptions) => {
|
|
15
|
+
const stripBOM = decodeOptions?.stripBOM ?? true;
|
|
16
|
+
return getCachedTextDecoder("iso-8859-14", {
|
|
17
|
+
fatal: false,
|
|
18
|
+
ignoreBOM: !stripBOM
|
|
19
|
+
}).decode(input);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
export { decode, encode, iso_8859_14_exports };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { __exportAll } from "../../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { getCachedTextDecoder } from "../../utils/getCachedTextDecoder.js";
|
|
3
|
+
import { encodeSingleByteEncoding } from "../../utils/encodeSingleByteEncoding.js";
|
|
4
|
+
import iso_8859_15_default from "../../encodings/iso-8859-15.js";
|
|
5
|
+
|
|
6
|
+
//#region src/codecs/single-byte/iso-8859-15.ts
|
|
7
|
+
var iso_8859_15_exports = /* @__PURE__ */ __exportAll({
|
|
8
|
+
decode: () => decode,
|
|
9
|
+
encode: () => encode
|
|
10
|
+
});
|
|
11
|
+
const encode = (input) => {
|
|
12
|
+
return encodeSingleByteEncoding(input, iso_8859_15_default);
|
|
13
|
+
};
|
|
14
|
+
const decode = (input, decodeOptions) => {
|
|
15
|
+
const stripBOM = decodeOptions?.stripBOM ?? true;
|
|
16
|
+
return getCachedTextDecoder("iso-8859-15", {
|
|
17
|
+
fatal: false,
|
|
18
|
+
ignoreBOM: !stripBOM
|
|
19
|
+
}).decode(input);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
export { decode, encode, iso_8859_15_exports };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { __exportAll } from "../../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { getCachedTextDecoder } from "../../utils/getCachedTextDecoder.js";
|
|
3
|
+
import { encodeSingleByteEncoding } from "../../utils/encodeSingleByteEncoding.js";
|
|
4
|
+
import iso_8859_16_default from "../../encodings/iso-8859-16.js";
|
|
5
|
+
|
|
6
|
+
//#region src/codecs/single-byte/iso-8859-16.ts
|
|
7
|
+
var iso_8859_16_exports = /* @__PURE__ */ __exportAll({
|
|
8
|
+
decode: () => decode,
|
|
9
|
+
encode: () => encode
|
|
10
|
+
});
|
|
11
|
+
const encode = (input) => {
|
|
12
|
+
return encodeSingleByteEncoding(input, iso_8859_16_default);
|
|
13
|
+
};
|
|
14
|
+
const decode = (input, decodeOptions) => {
|
|
15
|
+
const stripBOM = decodeOptions?.stripBOM ?? true;
|
|
16
|
+
return getCachedTextDecoder("iso-8859-16", {
|
|
17
|
+
fatal: false,
|
|
18
|
+
ignoreBOM: !stripBOM
|
|
19
|
+
}).decode(input);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
export { decode, encode, iso_8859_16_exports };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { __exportAll } from "../../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { getCachedTextDecoder } from "../../utils/getCachedTextDecoder.js";
|
|
3
|
+
import { encodeSingleByteEncoding } from "../../utils/encodeSingleByteEncoding.js";
|
|
4
|
+
import iso_8859_2_default from "../../encodings/iso-8859-2.js";
|
|
5
|
+
|
|
6
|
+
//#region src/codecs/single-byte/iso-8859-2.ts
|
|
7
|
+
var iso_8859_2_exports = /* @__PURE__ */ __exportAll({
|
|
8
|
+
decode: () => decode,
|
|
9
|
+
encode: () => encode
|
|
10
|
+
});
|
|
11
|
+
const encode = (input) => {
|
|
12
|
+
return encodeSingleByteEncoding(input, iso_8859_2_default);
|
|
13
|
+
};
|
|
14
|
+
const decode = (input, decodeOptions) => {
|
|
15
|
+
const stripBOM = decodeOptions?.stripBOM ?? true;
|
|
16
|
+
return getCachedTextDecoder("iso-8859-2", {
|
|
17
|
+
fatal: false,
|
|
18
|
+
ignoreBOM: !stripBOM
|
|
19
|
+
}).decode(input);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
export { decode, encode, iso_8859_2_exports };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { __exportAll } from "../../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { getCachedTextDecoder } from "../../utils/getCachedTextDecoder.js";
|
|
3
|
+
import { encodeSingleByteEncoding } from "../../utils/encodeSingleByteEncoding.js";
|
|
4
|
+
import iso_8859_3_default from "../../encodings/iso-8859-3.js";
|
|
5
|
+
|
|
6
|
+
//#region src/codecs/single-byte/iso-8859-3.ts
|
|
7
|
+
var iso_8859_3_exports = /* @__PURE__ */ __exportAll({
|
|
8
|
+
decode: () => decode,
|
|
9
|
+
encode: () => encode
|
|
10
|
+
});
|
|
11
|
+
const encode = (input) => {
|
|
12
|
+
return encodeSingleByteEncoding(input, iso_8859_3_default);
|
|
13
|
+
};
|
|
14
|
+
const decode = (input, decodeOptions) => {
|
|
15
|
+
const stripBOM = decodeOptions?.stripBOM ?? true;
|
|
16
|
+
return getCachedTextDecoder("iso-8859-3", {
|
|
17
|
+
fatal: false,
|
|
18
|
+
ignoreBOM: !stripBOM
|
|
19
|
+
}).decode(input);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
export { decode, encode, iso_8859_3_exports };
|