Skip to content

Add inline config object support to Node API - #1412

Merged
BYVoid merged 1 commit into
masterfrom
add-node-inline-config-api
Jul 8, 2026
Merged

BYVoid merged 1 commit into
masterfrom
add-node-inline-config-api

Conversation

@BYVoid

@BYVoid BYVoid commented Jul 8, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Allow the Node.js constructor to accept OpenCC configuration objects directly.
  • Add OpenCC.fromConfig(config, options?) and TypeScript declarations for OpenCCConfig and options.configDirectory.
  • Document inline configuration usage in English and Traditional Chinese README files.
  • Add Node tests for inline objects, bundled asset lookup, relative dictionary paths, and tofu-risk filtering.

Tests

  • node --test --test-reporter=spec --test-name-pattern="inline configuration|fromConfig|bundled assets" node/test.js
  • npm test

@BYVoid
BYVoid force-pushed the add-node-inline-config-api branch from 178bddf to f8bffba Compare July 8, 2026 22:16
@BYVoid
BYVoid marked this pull request as ready for review July 8, 2026 22:17
@frankslin

frankslin commented Jul 8, 2026 •

Copy link
Copy Markdown
Collaborator

需要注意一下 tofu_risk 語義一致性的問題:

src/Config.cpp 的 ParseDict 中 type == "inline" 在 may_output_tofu 檢查之前就 return 了,所以 C++/CLI/Python 使用者即使傳 includeTofuRiskDictionaries=false, inline dict 也不會被過濾。

JSON Schema 目前禁止 includeTofuRiskDictionaries:

"inline_dict": {
"type": "object",
"required": ["type", "entries"],
"additionalProperties": false,
"properties": {
"type": { "enum": ["inline"] },
"entries": {
"type": "object",
"additionalProperties": { "type": "string", "minLength": 1 }
}
}
},

(這裡 inline_dict 是 additionalProperties: false 且只允許 type/entries;may_output_tofu 只在 file_dict/group_dict 上合法。)

Allow the JavaScript API to build converters from OpenCC config objects while preserving existing string config behavior. Document the new entry point and cover bundled assets, custom config directories, and tofu-risk filtering in Node tests.
@BYVoid
BYVoid force-pushed the add-node-inline-config-api branch from f8bffba to 2b035e6 Compare July 8, 2026 22:29
@BYVoid

BYVoid commented Jul 8, 2026

Copy link
Copy Markdown
Owner Author

好的,改了。

@BYVoid
BYVoid merged commit 9fd996d into master Jul 8, 2026
43 of 46 checks passed
@BYVoid
BYVoid deleted the add-node-inline-config-api branch July 8, 2026 22:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants