diff --git a/CHANGELOG.md b/CHANGELOG.md index e396ed9..48769cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ ---- +## 3.0.0-alpha.6 (2022-09-21) + +- feat: support [Intl.Segmenter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter) for segment. +- dict: 雪茄 + ## 3.0.0-alpha.5 (2022-07-12) - fix: npm publish 中没有保护 esm 目录。 diff --git a/README.en-US.md b/README.en-US.md index f90bb3d..1305f48 100644 --- a/README.en-US.md +++ b/README.en-US.md @@ -135,11 +135,11 @@ export type IPinyinMode = The segment method. - Default is disable segment: `false`, -- If set `true`, use "segmentit" module for segment in Web, use "nodejieba" for segment in Node. -- Also specify follow string for segment (bug just "segmentit" in web): +- If set `true`, use "Intl.Segmenter" module default for segment on Web and Node. +- Also specify follow string for segment (bug just "Intl.Segmenter", "segmentit" is support on web): ```typescript -export type IPinyinSegment = "nodejieba" | "segmentit" | "@node-rs/jieba"; +export type IPinyinSegment = "Intl.Segmenter" | "nodejieba" | "segmentit" | "@node-rs/jieba"; ``` @@ -247,23 +247,6 @@ npm test ## Q&A -### What's the different Node version and Web version? - -`pinyin` support Node and Web browser now, the API and usage is complete same. - -But the Web version is simple than Node version. Just frequently-used dict, -without segmentation, and the dict is compress for web. - -Because of Traditional and Segmentation, the convert result will be not complete same. -and the test case have some different too. - -| Feature | Web version | Node version | -|--------------|---------------------------------|----------------------------------| -| Dict | Frequently-used Dict, Compress. | Complete Dict, without Compress. | -| Segmentation | NO | Segmentation options. | -| Traditional | NO | Full Traditional support. | - - ### How to sort by pinyin? This module provide default compare implementation: diff --git a/README.md b/README.md index 1e09c9d..2d6ce6e 100644 --- a/README.md +++ b/README.md @@ -65,11 +65,11 @@ console.log(pinyin("中心", { console.log(pinyin("中心", { heteronym: true, // 启用多音字模式 - segment: true, // 启用分词,以解决多音字问题。默认不开启,使用 true 开启使用 nodejieba 分词库。 + segment: true, // 启用分词,以解决多音字问题。默认不开启,使用 true 开启使用 Intl.Segmenter 分词库。 })); // [ [ 'zhōng' ], [ 'xīn' ] ] console.log(pinyin("中心", { - segment: "@node-rs/jieba", // 指定分词库,可以是 "nodejieba"、"segmentit"、"@node-rs/jieba"。 + segment: "@node-rs/jieba", // 指定分词库,可以是 "Intl.Segmenter", "nodejieba"、"segmentit"、"@node-rs/jieba"。 })); // [ [ 'zhōng' ], [ 'xīn' ] ] console.log(pinyin("我喜欢你", { @@ -144,11 +144,11 @@ export type IPinyinMode = 分词方式。 - 默认关闭 `false`, -- 也可以设置为 `true` 开启,Web 版中使用 "segmentit" 分词,Node 版中使用 "nodejieba" 分词。 -- 也可以声明以下字符串来指定分词算法。但目前 Web 版只支持 "segmentit" 分词。 +- 也可以设置为 `true` 开启,Web 和 Node 版中均使用 "Intl.Segmenter" 分词。 +- 也可以声明以下字符串来指定分词算法。但目前 Web 版只支持 "Intl.Segmenter" 和 "segmentit" 分词。 ```typescript -export type IPinyinSegment = "nodejieba" | "segmentit" | "@node-rs/jieba"; +export type IPinyinSegment = "Intl.Segmenter" | "nodejieba" | "segmentit" | "@node-rs/jieba"; ``` ## API @@ -178,8 +178,8 @@ options 是可选的,可以设定拼音风格,或打开多音字选项。 但性能会极大的下降,内存也会使用更多。 - 默认不启用分词。 -- 如果 `segemnt = true`,默认使用 nodejieba 分词。 -- 可以指定 "nodejieba"、"segmentit"、"@node-rs/jieba" 进行分词。 +- 如果 `segemnt = true`,默认使用 Intl.Segmenter 分词。 +- 可以指定 "Intl.Segmenter"、"nodejieba"、"segmentit"、"@node-rs/jieba" 进行分词。 ### ` options.heteronym` diff --git a/bin/pinyin b/bin/pinyin index 12d8963..36543b7 100755 --- a/bin/pinyin +++ b/bin/pinyin @@ -8,7 +8,7 @@ commander. option('-v, --version', 'output the version number'). option('-s, --style