@laisuk/opencc-fmmseg-wasm 0.2.2 → 0.2.4
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 +17 -15
- package/bin/opencc.js +12 -7
- package/opencc_fmmseg_wasm.d.ts +17 -17
- package/opencc_fmmseg_wasm.js +24 -24
- package/opencc_fmmseg_wasm_bg.wasm +0 -0
- package/package.json +36 -38
package/README.md
CHANGED
|
@@ -54,16 +54,16 @@ console.log(cc.convert("汉字", false));
|
|
|
54
54
|
## Using Config Enums
|
|
55
55
|
|
|
56
56
|
```javascript
|
|
57
|
-
import init, {
|
|
58
|
-
OpenccWasm,
|
|
59
|
-
|
|
60
|
-
} from "@laisuk/opencc-fmmseg-wasm";
|
|
61
|
-
|
|
62
|
-
await init();
|
|
63
|
-
|
|
64
|
-
const cc = OpenccWasm.newWithEnum(
|
|
65
|
-
|
|
66
|
-
);
|
|
57
|
+
import init, {
|
|
58
|
+
OpenccWasm,
|
|
59
|
+
OpenccConfigWasm
|
|
60
|
+
} from "@laisuk/opencc-fmmseg-wasm";
|
|
61
|
+
|
|
62
|
+
await init();
|
|
63
|
+
|
|
64
|
+
const cc = OpenccWasm.newWithEnum(
|
|
65
|
+
OpenccConfigWasm.S2t
|
|
66
|
+
);
|
|
67
67
|
|
|
68
68
|
console.log(cc.convert("汉字", false));
|
|
69
69
|
// 漢字
|
|
@@ -356,11 +356,13 @@ If `-o, --output` is omitted, `office` writes:
|
|
|
356
356
|
|
|
357
357
|
---
|
|
358
358
|
|
|
359
|
-
## TypeScript Support
|
|
360
|
-
|
|
361
|
-
The package includes generated TypeScript definitions from `wasm-bindgen`.
|
|
362
|
-
|
|
363
|
-
|
|
359
|
+
## TypeScript Support
|
|
360
|
+
|
|
361
|
+
The package includes generated TypeScript definitions from `wasm-bindgen`.
|
|
362
|
+
|
|
363
|
+
The WASM-facing enum is exported as `OpenccConfigWasm`, alongside `OpenccWasm`.
|
|
364
|
+
|
|
365
|
+
---
|
|
364
366
|
|
|
365
367
|
## Performance Notes
|
|
366
368
|
|
package/bin/opencc.js
CHANGED
|
@@ -41,8 +41,8 @@ function printHelp() {
|
|
|
41
41
|
opencc-fmmseg WASM CLI
|
|
42
42
|
|
|
43
43
|
Usage:
|
|
44
|
-
opencc
|
|
45
|
-
opencc
|
|
44
|
+
npx opencc-fmmseg convert [options]
|
|
45
|
+
npx opencc-fmmseg office [options]
|
|
46
46
|
|
|
47
47
|
Commands:
|
|
48
48
|
convert Convert plain text
|
|
@@ -70,12 +70,12 @@ General options:
|
|
|
70
70
|
-h, --help Show help
|
|
71
71
|
|
|
72
72
|
Examples:
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
cat a.txt |
|
|
73
|
+
npx opencc-fmmseg convert -i a.txt -o b.txt -c s2t
|
|
74
|
+
npx opencc-fmmseg convert -i a.txt -o b.txt -c s2tw -p
|
|
75
|
+
cat a.txt | npx opencc-fmmseg convert -c t2s
|
|
76
76
|
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
npx opencc-fmmseg office -i a.docx -o b.docx -c s2t -p
|
|
78
|
+
npx opencc-fmmseg office -i a.epub -c s2tw --auto-ext
|
|
79
79
|
`);
|
|
80
80
|
}
|
|
81
81
|
|
|
@@ -191,6 +191,11 @@ async function runConvert(args) {
|
|
|
191
191
|
|
|
192
192
|
const cc = new OpenccWasm(config);
|
|
193
193
|
|
|
194
|
+
// Prompt user if reading from interactive terminal
|
|
195
|
+
if (!input && process.stdin.isTTY) {
|
|
196
|
+
console.error("Input text to convert, <Ctrl+Z>/<Ctrl+D> to submit:");
|
|
197
|
+
}
|
|
198
|
+
|
|
194
199
|
const inputText = readInputText(input, inEnc);
|
|
195
200
|
const outputText = cc.convert(inputText, punct);
|
|
196
201
|
|
package/opencc_fmmseg_wasm.d.ts
CHANGED
|
@@ -1,23 +1,7 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
|
|
4
|
-
export
|
|
5
|
-
free(): void;
|
|
6
|
-
[Symbol.dispose](): void;
|
|
7
|
-
convert(text: string, punctuation: boolean): string;
|
|
8
|
-
debugPing(): string;
|
|
9
|
-
getConfig(): string;
|
|
10
|
-
getConfigId(): number;
|
|
11
|
-
static getSupportedConfigs(): string[];
|
|
12
|
-
static isValidConfig(config: string): boolean;
|
|
13
|
-
constructor(config?: string | null);
|
|
14
|
-
static newWithEnum(config?: WasmOpenccConfig | null): OpenccWasm;
|
|
15
|
-
setConfig(config: string): boolean;
|
|
16
|
-
setConfigEnum(config: WasmOpenccConfig): void;
|
|
17
|
-
zhoCheck(text: string): number;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export enum WasmOpenccConfig {
|
|
4
|
+
export enum OpenccConfigWasm {
|
|
21
5
|
S2t = 1,
|
|
22
6
|
S2tw = 2,
|
|
23
7
|
S2twp = 3,
|
|
@@ -36,6 +20,22 @@ export enum WasmOpenccConfig {
|
|
|
36
20
|
T2jp = 16,
|
|
37
21
|
}
|
|
38
22
|
|
|
23
|
+
export class OpenccWasm {
|
|
24
|
+
free(): void;
|
|
25
|
+
[Symbol.dispose](): void;
|
|
26
|
+
convert(text: string, punctuation: boolean): string;
|
|
27
|
+
debugPing(): string;
|
|
28
|
+
getConfig(): string;
|
|
29
|
+
getConfigId(): number;
|
|
30
|
+
static getSupportedConfigs(): string[];
|
|
31
|
+
static isValidConfig(config: string): boolean;
|
|
32
|
+
constructor(config?: string | null);
|
|
33
|
+
static newWithEnum(config?: OpenccConfigWasm | null): OpenccWasm;
|
|
34
|
+
setConfig(config: string): boolean;
|
|
35
|
+
setConfigEnum(config: OpenccConfigWasm): void;
|
|
36
|
+
zhoCheck(text: string): number;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
39
|
export function convert_office_bytes(input: Uint8Array, format: string, config: string, punctuation: boolean, keep_font: boolean): Uint8Array;
|
|
40
40
|
|
|
41
41
|
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
package/opencc_fmmseg_wasm.js
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
/* @ts-self-types="./opencc_fmmseg_wasm.d.ts" */
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* @enum {1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16}
|
|
5
|
+
*/
|
|
6
|
+
export const OpenccConfigWasm = Object.freeze({
|
|
7
|
+
S2t: 1, "1": "S2t",
|
|
8
|
+
S2tw: 2, "2": "S2tw",
|
|
9
|
+
S2twp: 3, "3": "S2twp",
|
|
10
|
+
S2hk: 4, "4": "S2hk",
|
|
11
|
+
T2s: 5, "5": "T2s",
|
|
12
|
+
T2tw: 6, "6": "T2tw",
|
|
13
|
+
T2twp: 7, "7": "T2twp",
|
|
14
|
+
T2hk: 8, "8": "T2hk",
|
|
15
|
+
Tw2s: 9, "9": "Tw2s",
|
|
16
|
+
Tw2sp: 10, "10": "Tw2sp",
|
|
17
|
+
Tw2t: 11, "11": "Tw2t",
|
|
18
|
+
Tw2tp: 12, "12": "Tw2tp",
|
|
19
|
+
Hk2s: 13, "13": "Hk2s",
|
|
20
|
+
Hk2t: 14, "14": "Hk2t",
|
|
21
|
+
Jp2t: 15, "15": "Jp2t",
|
|
22
|
+
T2jp: 16, "16": "T2jp",
|
|
23
|
+
});
|
|
24
|
+
|
|
3
25
|
export class OpenccWasm {
|
|
4
26
|
static __wrap(ptr) {
|
|
5
27
|
const obj = Object.create(OpenccWasm.prototype);
|
|
@@ -107,7 +129,7 @@ export class OpenccWasm {
|
|
|
107
129
|
return this;
|
|
108
130
|
}
|
|
109
131
|
/**
|
|
110
|
-
* @param {
|
|
132
|
+
* @param {OpenccConfigWasm | null} [config]
|
|
111
133
|
* @returns {OpenccWasm}
|
|
112
134
|
*/
|
|
113
135
|
static newWithEnum(config) {
|
|
@@ -128,7 +150,7 @@ export class OpenccWasm {
|
|
|
128
150
|
return ret !== 0;
|
|
129
151
|
}
|
|
130
152
|
/**
|
|
131
|
-
* @param {
|
|
153
|
+
* @param {OpenccConfigWasm} config
|
|
132
154
|
*/
|
|
133
155
|
setConfigEnum(config) {
|
|
134
156
|
wasm.openccwasm_setConfigEnum(this.__wbg_ptr, config);
|
|
@@ -146,28 +168,6 @@ export class OpenccWasm {
|
|
|
146
168
|
}
|
|
147
169
|
if (Symbol.dispose) OpenccWasm.prototype[Symbol.dispose] = OpenccWasm.prototype.free;
|
|
148
170
|
|
|
149
|
-
/**
|
|
150
|
-
* @enum {1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16}
|
|
151
|
-
*/
|
|
152
|
-
export const WasmOpenccConfig = Object.freeze({
|
|
153
|
-
S2t: 1, "1": "S2t",
|
|
154
|
-
S2tw: 2, "2": "S2tw",
|
|
155
|
-
S2twp: 3, "3": "S2twp",
|
|
156
|
-
S2hk: 4, "4": "S2hk",
|
|
157
|
-
T2s: 5, "5": "T2s",
|
|
158
|
-
T2tw: 6, "6": "T2tw",
|
|
159
|
-
T2twp: 7, "7": "T2twp",
|
|
160
|
-
T2hk: 8, "8": "T2hk",
|
|
161
|
-
Tw2s: 9, "9": "Tw2s",
|
|
162
|
-
Tw2sp: 10, "10": "Tw2sp",
|
|
163
|
-
Tw2t: 11, "11": "Tw2t",
|
|
164
|
-
Tw2tp: 12, "12": "Tw2tp",
|
|
165
|
-
Hk2s: 13, "13": "Hk2s",
|
|
166
|
-
Hk2t: 14, "14": "Hk2t",
|
|
167
|
-
Jp2t: 15, "15": "Jp2t",
|
|
168
|
-
T2jp: 16, "16": "T2jp",
|
|
169
|
-
});
|
|
170
|
-
|
|
171
171
|
/**
|
|
172
172
|
* @param {Uint8Array} input
|
|
173
173
|
* @param {string} format
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,38 +1,36 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@laisuk/opencc-fmmseg-wasm",
|
|
3
|
-
"type": "module",
|
|
4
|
-
"description": "WebAssembly bindings for opencc-fmmseg, a high-performance OpenCC-compatible Simplified/Traditional Chinese converter.",
|
|
5
|
-
"version": "0.2.
|
|
6
|
-
"license": "MIT",
|
|
7
|
-
"repository": {
|
|
8
|
-
"type": "git",
|
|
9
|
-
"url": "git+https://github.com/laisuk/opencc-fmmseg-wasm.git"
|
|
10
|
-
},
|
|
11
|
-
"
|
|
12
|
-
"opencc"
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
"
|
|
16
|
-
"wasm",
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
]
|
|
38
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@laisuk/opencc-fmmseg-wasm",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"description": "WebAssembly bindings for opencc-fmmseg, a high-performance OpenCC-compatible Simplified/Traditional Chinese converter.",
|
|
5
|
+
"version": "0.2.4",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/laisuk/opencc-fmmseg-wasm.git"
|
|
10
|
+
},
|
|
11
|
+
"bin": {
|
|
12
|
+
"opencc-fmmseg": "bin/opencc.js"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"bin/",
|
|
16
|
+
"opencc_fmmseg_wasm_bg.wasm",
|
|
17
|
+
"opencc_fmmseg_wasm.js",
|
|
18
|
+
"opencc_fmmseg_wasm.d.ts"
|
|
19
|
+
],
|
|
20
|
+
"main": "opencc_fmmseg_wasm.js",
|
|
21
|
+
"types": "opencc_fmmseg_wasm.d.ts",
|
|
22
|
+
"sideEffects": [
|
|
23
|
+
"./snippets/*"
|
|
24
|
+
],
|
|
25
|
+
"keywords": [
|
|
26
|
+
"opencc",
|
|
27
|
+
"chinese",
|
|
28
|
+
"simplified-chinese",
|
|
29
|
+
"traditional-chinese",
|
|
30
|
+
"wasm",
|
|
31
|
+
"webassembly",
|
|
32
|
+
"opencc-fmmseg",
|
|
33
|
+
"text-conversion",
|
|
34
|
+
"cjk"
|
|
35
|
+
]
|
|
36
|
+
}
|