Skip to content

Rewrite Node demo examples - #1415

Merged
BYVoid merged 1 commit into
masterfrom
rewrite-node-demos
Jul 9, 2026
Merged

BYVoid merged 1 commit into
masterfrom
rewrite-node-demos

Conversation

@BYVoid

@BYVoid BYVoid commented Jul 9, 2026

Copy link
Copy Markdown
Owner

Summary

  • Rewrite the Node.js JavaScript demo to cover sync, callback, Promise, and inline fromConfig usage.
  • Rename the TypeScript demo from ts-demo.ts to demo.ts and keep it functionally aligned with demo.js.
  • Add a short fromConfig example to the README Node.js section.

Tests

  • node node/demo.js
  • npx -p typescript tsc --noEmit --strict --module node16 --moduleResolution node16 --target es2022 node/demo.ts
  • npm test

@BYVoid
BYVoid force-pushed the rewrite-node-demos branch from 7b2e8af to 7927470 Compare July 9, 2026 00:42
Comment thread node/demo.js Outdated
console.log(converted);
main().catch((err) => {
console.error(err);
throw err;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在 .catch 裏重新 throw 會變成 unhandled rejection,Node 會再次輸出錯誤並以非零 exit code 結束。既然這是給用戶抄用的 demo,建議改成:

console.error(err);
process.exitCode = 1;

demo.ts 也有此問題。

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修正,demo.js 和 demo.ts 都改成 console.error(err); process.exitCode = 1;,避免在 catch 裏重新 throw。demo.ts 補了最小的 process 型別宣告,讓不安裝 @types/node 時仍可通過型別檢查。

@BYVoid
BYVoid marked this pull request as ready for review July 9, 2026 00:58
Comment thread node/demo.ts Outdated
Comment on lines +54 to +55
鼠标: '滑鼠',
软件: '軟體',

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

這裡雖然 JSON key 可以是 Unicode,但與 README.md 中所寫的風格不一致,建議統一改用單引號作為 key。

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修正,README.md、demo.js 和 demo.ts 裏 inline config 的 Unicode entries key 都統一改成單引號形式。

@BYVoid
BYVoid force-pushed the rewrite-node-demos branch from 7927470 to 20cd39b Compare July 9, 2026 00:58
@frankslin

Copy link
Copy Markdown
Collaborator

後續是否考慮可將 node streaming API 也完善一下?在 node/cli.js 裡有一個可用的實現,但沒有封裝成公共 API。

@BYVoid

BYVoid commented Jul 9, 2026

Copy link
Copy Markdown
Owner Author

後續是否考慮可將 node streaming API 也完善一下?在 node/cli.js 裡有一個可用的實現,但沒有封裝成公共 API。

你可以考慮實現,目前應該還沒有緊迫性,因爲OpenCC轉換已經夠快了。

Update the JavaScript and TypeScript demos to cover the same API surface, including fromConfig inline configuration. Rename the TypeScript demo to node/demo.ts and update the README references.
@BYVoid
BYVoid force-pushed the rewrite-node-demos branch from 20cd39b to 215e396 Compare July 9, 2026 01:05
@BYVoid
BYVoid merged commit 6b382c6 into master Jul 9, 2026
43 checks passed
@BYVoid
BYVoid deleted the rewrite-node-demos branch July 9, 2026 01:40
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