@laisuk/opencc-fmmseg-wasm 0.4.1 → 0.4.3
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/bin/opencc.js +74 -5
- package/opencc_fmmseg_wasm.js +26 -26
- package/opencc_fmmseg_wasm_bg.wasm +0 -0
- package/package.json +1 -1
package/bin/opencc.js
CHANGED
|
@@ -69,13 +69,25 @@ Convert options:
|
|
|
69
69
|
--in-enc <encoding> Input encoding (default: utf8)
|
|
70
70
|
--out-enc <encoding> Output encoding (default: utf8)
|
|
71
71
|
|
|
72
|
-
Supported encodings:
|
|
72
|
+
Supported input encodings:
|
|
73
73
|
utf8
|
|
74
74
|
utf16le
|
|
75
75
|
latin1
|
|
76
76
|
ascii
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
gb18030
|
|
78
|
+
gbk (decoded as gb18030)
|
|
79
|
+
gb2312 (decoded as gb18030)
|
|
80
|
+
big5
|
|
81
|
+
shift_jis
|
|
82
|
+
shift-jis (alias of shift_jis)
|
|
83
|
+
|
|
84
|
+
Supported output encodings:
|
|
85
|
+
utf8
|
|
86
|
+
utf16le
|
|
87
|
+
latin1
|
|
88
|
+
ascii
|
|
89
|
+
|
|
90
|
+
Note: utf8 and utf16le are recommended for output and general-purpose CJK text.
|
|
79
91
|
|
|
80
92
|
Supported configs:
|
|
81
93
|
s2t, s2tw, s2twp, s2hk, s2hkp, t2s, t2tw, t2twp, t2hk, t2hkp,
|
|
@@ -168,6 +180,30 @@ function getArgs(args, shortName, longName) {
|
|
|
168
180
|
function validateEncoding(value, optionName) {
|
|
169
181
|
const encoding = String(value).trim().toLowerCase();
|
|
170
182
|
|
|
183
|
+
if (optionName === "--in-enc") {
|
|
184
|
+
const supported = new Set([
|
|
185
|
+
"utf8",
|
|
186
|
+
"utf16le",
|
|
187
|
+
"latin1",
|
|
188
|
+
"ascii",
|
|
189
|
+
"gb18030",
|
|
190
|
+
"gbk",
|
|
191
|
+
"gb2312",
|
|
192
|
+
"big5",
|
|
193
|
+
"shift_jis",
|
|
194
|
+
"shift-jis"
|
|
195
|
+
]);
|
|
196
|
+
|
|
197
|
+
if (!supported.has(encoding)) {
|
|
198
|
+
throw new Error(
|
|
199
|
+
`Unsupported encoding for ${optionName}: ${value}. ` +
|
|
200
|
+
`Supported values: ${Array.from(supported).join(", ")}`
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
return encoding;
|
|
205
|
+
}
|
|
206
|
+
|
|
171
207
|
if (!Buffer.isEncoding(encoding)) {
|
|
172
208
|
throw new Error(
|
|
173
209
|
`Unsupported encoding for ${optionName}: ${value}. ` +
|
|
@@ -347,13 +383,30 @@ function hasFlag(args, shortName, longName) {
|
|
|
347
383
|
);
|
|
348
384
|
}
|
|
349
385
|
|
|
386
|
+
const TEXT_DECODER_ENCODINGS = new Set([
|
|
387
|
+
"big5",
|
|
388
|
+
"gb18030",
|
|
389
|
+
"shift_jis"
|
|
390
|
+
]);
|
|
391
|
+
|
|
350
392
|
function readInputText(filePath, encoding) {
|
|
393
|
+
const enc = normalizeInputEncoding(encoding);
|
|
394
|
+
|
|
395
|
+
const read = (path) => {
|
|
396
|
+
if (TEXT_DECODER_ENCODINGS.has(enc)) {
|
|
397
|
+
const buffer = fs.readFileSync(path);
|
|
398
|
+
return new TextDecoder(enc, {fatal: true}).decode(buffer);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
return fs.readFileSync(path, enc);
|
|
402
|
+
};
|
|
403
|
+
|
|
351
404
|
if (!filePath) {
|
|
352
|
-
return
|
|
405
|
+
return read(0);
|
|
353
406
|
}
|
|
354
407
|
|
|
355
408
|
try {
|
|
356
|
-
return
|
|
409
|
+
return read(filePath);
|
|
357
410
|
} catch (err) {
|
|
358
411
|
if (err?.code === "ENOENT") {
|
|
359
412
|
throw new Error(`Input file not found: ${filePath}`);
|
|
@@ -369,6 +422,22 @@ function readInputText(filePath, encoding) {
|
|
|
369
422
|
}
|
|
370
423
|
}
|
|
371
424
|
|
|
425
|
+
function normalizeInputEncoding(encoding) {
|
|
426
|
+
const enc = encoding.toLowerCase();
|
|
427
|
+
|
|
428
|
+
switch (enc) {
|
|
429
|
+
case "gb2312":
|
|
430
|
+
case "gbk":
|
|
431
|
+
return "gb18030";
|
|
432
|
+
|
|
433
|
+
case "shift-jis":
|
|
434
|
+
return "shift_jis";
|
|
435
|
+
|
|
436
|
+
default:
|
|
437
|
+
return enc;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
|
|
372
441
|
function writeOutputText(filePath, text, encoding) {
|
|
373
442
|
if (!filePath) {
|
|
374
443
|
process.stdout.write(text);
|
package/opencc_fmmseg_wasm.js
CHANGED
|
@@ -619,7 +619,7 @@ export function convert_office_bytes_pipeline(input, format, config, punctuation
|
|
|
619
619
|
function __wbg_get_imports() {
|
|
620
620
|
const import0 = {
|
|
621
621
|
__proto__: null,
|
|
622
|
-
|
|
622
|
+
__wbg_Error_30c8987f7c2ed4e2: function(arg0, arg1) {
|
|
623
623
|
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
624
624
|
return ret;
|
|
625
625
|
},
|
|
@@ -630,46 +630,46 @@ function __wbg_get_imports() {
|
|
|
630
630
|
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
631
631
|
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
632
632
|
},
|
|
633
|
-
|
|
633
|
+
__wbg___wbindgen_boolean_get_5b446f51afd21013: function(arg0) {
|
|
634
634
|
const v = arg0;
|
|
635
635
|
const ret = typeof(v) === 'boolean' ? v : undefined;
|
|
636
636
|
return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
|
|
637
637
|
},
|
|
638
|
-
|
|
638
|
+
__wbg___wbindgen_debug_string_4687d8d8c2017d52: function(arg0, arg1) {
|
|
639
639
|
const ret = debugString(arg1);
|
|
640
640
|
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
641
641
|
const len1 = WASM_VECTOR_LEN;
|
|
642
642
|
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
643
643
|
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
644
644
|
},
|
|
645
|
-
|
|
645
|
+
__wbg___wbindgen_in_92f62ee1427d9e49: function(arg0, arg1) {
|
|
646
646
|
const ret = arg0 in arg1;
|
|
647
647
|
return ret;
|
|
648
648
|
},
|
|
649
|
-
|
|
649
|
+
__wbg___wbindgen_is_function_1f9d30630b8b1d3d: function(arg0) {
|
|
650
650
|
const ret = typeof(arg0) === 'function';
|
|
651
651
|
return ret;
|
|
652
652
|
},
|
|
653
|
-
|
|
653
|
+
__wbg___wbindgen_is_object_3c45d4f2dde4e749: function(arg0) {
|
|
654
654
|
const val = arg0;
|
|
655
655
|
const ret = typeof(val) === 'object' && val !== null;
|
|
656
656
|
return ret;
|
|
657
657
|
},
|
|
658
|
-
|
|
658
|
+
__wbg___wbindgen_is_undefined_8865fb403f8fe9d8: function(arg0) {
|
|
659
659
|
const ret = arg0 === undefined;
|
|
660
660
|
return ret;
|
|
661
661
|
},
|
|
662
|
-
|
|
662
|
+
__wbg___wbindgen_jsval_loose_eq_677f21e468d6b461: function(arg0, arg1) {
|
|
663
663
|
const ret = arg0 == arg1;
|
|
664
664
|
return ret;
|
|
665
665
|
},
|
|
666
|
-
|
|
666
|
+
__wbg___wbindgen_number_get_2e0e7dee9f701a71: function(arg0, arg1) {
|
|
667
667
|
const obj = arg1;
|
|
668
668
|
const ret = typeof(obj) === 'number' ? obj : undefined;
|
|
669
669
|
getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
|
|
670
670
|
getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
|
|
671
671
|
},
|
|
672
|
-
|
|
672
|
+
__wbg___wbindgen_string_get_0380ccaa2f57f0d9: function(arg0, arg1) {
|
|
673
673
|
const obj = arg1;
|
|
674
674
|
const ret = typeof(obj) === 'string' ? obj : undefined;
|
|
675
675
|
var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
@@ -677,22 +677,22 @@ function __wbg_get_imports() {
|
|
|
677
677
|
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
678
678
|
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
679
679
|
},
|
|
680
|
-
|
|
680
|
+
__wbg___wbindgen_throw_41e9ee4f547fc59a: function(arg0, arg1) {
|
|
681
681
|
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
682
682
|
},
|
|
683
|
-
|
|
683
|
+
__wbg_call_6137034ef55c9d0f: function() { return handleError(function (arg0, arg1) {
|
|
684
684
|
const ret = arg0.call(arg1);
|
|
685
685
|
return ret;
|
|
686
686
|
}, arguments); },
|
|
687
|
-
|
|
687
|
+
__wbg_done_b41a1d26cdb37fb6: function(arg0) {
|
|
688
688
|
const ret = arg0.done;
|
|
689
689
|
return ret;
|
|
690
690
|
},
|
|
691
|
-
|
|
691
|
+
__wbg_get_658f6698067d9515: function() { return handleError(function (arg0, arg1) {
|
|
692
692
|
const ret = Reflect.get(arg0, arg1);
|
|
693
693
|
return ret;
|
|
694
694
|
}, arguments); },
|
|
695
|
-
|
|
695
|
+
__wbg_get_unchecked_288889d017702237: function(arg0, arg1) {
|
|
696
696
|
const ret = arg0[arg1 >>> 0];
|
|
697
697
|
return ret;
|
|
698
698
|
},
|
|
@@ -700,7 +700,7 @@ function __wbg_get_imports() {
|
|
|
700
700
|
const ret = arg0[arg1];
|
|
701
701
|
return ret;
|
|
702
702
|
},
|
|
703
|
-
|
|
703
|
+
__wbg_instanceof_ArrayBuffer_a99f175873e5d9b8: function(arg0) {
|
|
704
704
|
let result;
|
|
705
705
|
try {
|
|
706
706
|
result = arg0 instanceof ArrayBuffer;
|
|
@@ -710,7 +710,7 @@ function __wbg_get_imports() {
|
|
|
710
710
|
const ret = result;
|
|
711
711
|
return ret;
|
|
712
712
|
},
|
|
713
|
-
|
|
713
|
+
__wbg_instanceof_Uint8Array_828cef2aaacafc31: function(arg0) {
|
|
714
714
|
let result;
|
|
715
715
|
try {
|
|
716
716
|
result = arg0 instanceof Uint8Array;
|
|
@@ -720,38 +720,38 @@ function __wbg_get_imports() {
|
|
|
720
720
|
const ret = result;
|
|
721
721
|
return ret;
|
|
722
722
|
},
|
|
723
|
-
|
|
723
|
+
__wbg_isArray_e15a2ff68ffdbef2: function(arg0) {
|
|
724
724
|
const ret = Array.isArray(arg0);
|
|
725
725
|
return ret;
|
|
726
726
|
},
|
|
727
|
-
|
|
727
|
+
__wbg_iterator_e3c31c892080e444: function() {
|
|
728
728
|
const ret = Symbol.iterator;
|
|
729
729
|
return ret;
|
|
730
730
|
},
|
|
731
|
-
|
|
731
|
+
__wbg_length_7f3c00c40364105e: function(arg0) {
|
|
732
732
|
const ret = arg0.length;
|
|
733
733
|
return ret;
|
|
734
734
|
},
|
|
735
|
-
|
|
735
|
+
__wbg_length_d4bdea10311bd9cf: function(arg0) {
|
|
736
736
|
const ret = arg0.length;
|
|
737
737
|
return ret;
|
|
738
738
|
},
|
|
739
|
-
|
|
739
|
+
__wbg_new_1dbf7428bba60a42: function(arg0) {
|
|
740
740
|
const ret = new Uint8Array(arg0);
|
|
741
741
|
return ret;
|
|
742
742
|
},
|
|
743
|
-
|
|
743
|
+
__wbg_next_33784799010f1bbe: function(arg0) {
|
|
744
744
|
const ret = arg0.next;
|
|
745
745
|
return ret;
|
|
746
746
|
},
|
|
747
|
-
|
|
747
|
+
__wbg_next_f4aac29c42af995c: function() { return handleError(function (arg0) {
|
|
748
748
|
const ret = arg0.next();
|
|
749
749
|
return ret;
|
|
750
750
|
}, arguments); },
|
|
751
|
-
|
|
751
|
+
__wbg_prototypesetcall_bc27214492979395: function(arg0, arg1, arg2) {
|
|
752
752
|
Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
|
|
753
753
|
},
|
|
754
|
-
|
|
754
|
+
__wbg_value_f3c585ee8f5ba40c: function(arg0) {
|
|
755
755
|
const ret = arg0.value;
|
|
756
756
|
return ret;
|
|
757
757
|
},
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@laisuk/opencc-fmmseg-wasm",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"description": "WebAssembly bindings for opencc-fmmseg, a high-performance OpenCC-compatible Simplified/Traditional Chinese converter.",
|
|
5
|
-
"version": "0.4.
|
|
5
|
+
"version": "0.4.3",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|