Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,5 +298,14 @@ npm install
npm test
```

The `OpenCCConfig` TypeScript declarations in `opencc.d.ts`,
`opencc.d.cts`, and `opencc.d.mts` are generated from
`data/config/opencc_config.schema.json`. Regenerate them after changing the
schema:

```bash
npm run generate:node-config-types
```

To build prebuilt native addons for publishing, see
[`node/PUBLISHING.md`](./PUBLISHING.md).
39 changes: 38 additions & 1 deletion node/opencc.d.cts
Original file line number Diff line number Diff line change
@@ -1,4 +1,41 @@
type OpenCCConfig = Record<string, unknown>;
type OpenCCDict = OpenCCFileDict | OpenCCInlineDict | OpenCCGroupDict;
type OpenCCSegmentation = OpenCCMmsegSegmentation | OpenCCPluginSegmentation;
type OpenCCPluginSegmentation = {
type: string;
resources?: Record<string, string>;
[key: string]: string | Record<string, string> | undefined;
};

interface OpenCCConfig {
name: string;
normalization?: [OpenCCConversion, ...OpenCCConversion[]];
segmentation?: OpenCCSegmentation;
conversion_chain: [OpenCCConversion, ...OpenCCConversion[]];
}
interface OpenCCConversion {
dict: OpenCCDict;
}
interface OpenCCFileDict {
type: "text" | "ocd" | "ocd2";
file: string;
may_output_tofu?: boolean;
}
interface OpenCCInlineDict {
type: "inline";
entries: {
[k: string]: string;
};
}
interface OpenCCGroupDict {
type: "group";
match_policy: "short_circuit" | "union";
dicts: [OpenCCDict, ...OpenCCDict[]];
may_output_tofu?: boolean;
}
interface OpenCCMmsegSegmentation {
type: "mmseg";
dict: OpenCCDict;
}

interface OpenCCOptions {
includeTofuRiskDictionaries?: boolean;
Expand Down
39 changes: 38 additions & 1 deletion node/opencc.d.mts
Original file line number Diff line number Diff line change
@@ -1,4 +1,41 @@
type OpenCCConfig = Record<string, unknown>;
type OpenCCDict = OpenCCFileDict | OpenCCInlineDict | OpenCCGroupDict;
type OpenCCSegmentation = OpenCCMmsegSegmentation | OpenCCPluginSegmentation;
type OpenCCPluginSegmentation = {
type: string;
resources?: Record<string, string>;
[key: string]: string | Record<string, string> | undefined;
};

interface OpenCCConfig {
name: string;
normalization?: [OpenCCConversion, ...OpenCCConversion[]];
segmentation?: OpenCCSegmentation;
conversion_chain: [OpenCCConversion, ...OpenCCConversion[]];
}
interface OpenCCConversion {
dict: OpenCCDict;
}
interface OpenCCFileDict {
type: "text" | "ocd" | "ocd2";
file: string;
may_output_tofu?: boolean;
}
interface OpenCCInlineDict {
type: "inline";
entries: {
[k: string]: string;
};
}
interface OpenCCGroupDict {
type: "group";
match_policy: "short_circuit" | "union";
dicts: [OpenCCDict, ...OpenCCDict[]];
may_output_tofu?: boolean;
}
interface OpenCCMmsegSegmentation {
type: "mmseg";
dict: OpenCCDict;
}

interface OpenCCOptions {
includeTofuRiskDictionaries?: boolean;
Expand Down
39 changes: 38 additions & 1 deletion node/opencc.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,41 @@
type OpenCCConfig = Record<string, unknown>;
type OpenCCDict = OpenCCFileDict | OpenCCInlineDict | OpenCCGroupDict;
type OpenCCSegmentation = OpenCCMmsegSegmentation | OpenCCPluginSegmentation;
type OpenCCPluginSegmentation = {
type: string;
resources?: Record<string, string>;
[key: string]: string | Record<string, string> | undefined;
};

interface OpenCCConfig {
name: string;
normalization?: [OpenCCConversion, ...OpenCCConversion[]];
segmentation?: OpenCCSegmentation;
conversion_chain: [OpenCCConversion, ...OpenCCConversion[]];
}
interface OpenCCConversion {
dict: OpenCCDict;
}
interface OpenCCFileDict {
type: "text" | "ocd" | "ocd2";
file: string;
may_output_tofu?: boolean;
}
interface OpenCCInlineDict {
type: "inline";
entries: {
[k: string]: string;
};
}
interface OpenCCGroupDict {
type: "group";
match_policy: "short_circuit" | "union";
dicts: [OpenCCDict, ...OpenCCDict[]];
may_output_tofu?: boolean;
}
interface OpenCCMmsegSegmentation {
type: "mmseg";
dict: OpenCCDict;
}

interface OpenCCOptions {
includeTofuRiskDictionaries?: boolean;
Expand Down
140 changes: 140 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
},
"scripts": {
"test": "node --test --test-reporter=spec node/test.js && node node/esm-test.mjs",
"generate:node-config-types": "node scripts/generate-node-opencc-config-types.js",
"prebuild": "prebuildify --napi --strip --postinstall \"node scripts/prepare-node-prebuild-artifacts.js\"",
"prepare:scoped-packages": "node scripts/prepare-node-scoped-packages.js",
"prepack": "node scripts/verify-node-main-package.js",
Expand Down Expand Up @@ -63,6 +64,7 @@
"prebuilds/assets/*.ocd2",
"scripts/prepare-node-prebuild-artifacts.js",
"scripts/install.js",
"scripts/generate-node-opencc-config-types.js",
"scripts/prepare-node-scoped-packages.js",
"scripts/verify-node-main-package.js",
"scripts/verify-node-scoped-packages-published.js",
Expand Down Expand Up @@ -148,6 +150,7 @@
"Traditional Chinese"
],
"devDependencies": {
"json-schema-to-typescript": "^15.0.4",
"prebuildify": "^6.0.1"
},
"dependencies": {
Expand Down
Loading
Loading