
Security News
Another Round of TEA Protocol Spam Floods npm, But It’s Not a Worm
Recent coverage mislabels the latest TEA protocol spam as a worm. Here’s what’s actually happening.
node-pinyin
Advanced tools
本工具fork自https://github.com/hotoo/pinyin,原库以MIT协议开源,本库也以MIT协议开源。
将汉字转为拼音,支持多音字。
via npm:
npm install node-pinyin
var pinyin = require("node-pinyin");
console.log(pinyin("重心")); // [ [ 'zhòng' ], [ 'xīn' ] ]
console.log(pinyin("重心", {
heteronym: true // 启用多音字模式
})); // [ [ 'zhòng', 'chóng' ], [ 'xīn' ] ]
命令行:
$ pinyin 重心
zhòng xīn
$ pinyin -h
<Array> pinyin(words[, options])将传入的中文字符串(words)转换成拼音符号串。
options 是可选的,打开多音字选项和设定返回风格。
返回二维数组,第一维每个数组项位置对应每个中文字符串位置。 第二维是各个汉字的读音列表,多音字会有多个拼音项。
<Boolean> options.heteronym是否启用多音字模式,默认关闭。
关闭多音字模式时,返回每个汉字第一个匹配的拼音。
启用多音字模式时,返回多音字的所有拼音列表。
<String> options.style指定拼音 风格。可以通过以下几种属性值进行指定。
normal普通风格,即不带音标。
如:pin yin
tone声调风格,拼音声调在韵母第一个字母上。
注:这是默认的风格。
如:pīn yīn
toneWithNumber声调风格,即拼音声调在各个拼音之后,用数字 [0-4] 进行表示。
如:pin1 yin1
initials声母风格,只返回各个拼音的声母部分。
如:中国 的拼音 zh g
例外,对于只有韵母的汉字(如『爱、啊』等),会先转成不带音标的普通风格。
firstLetter首字母风格,只返回拼音的首字母部分。
如:p y
npm test
源库由于启用了分词和词组匹配,导致内存占用极大,运算时间长,本库做了精简。
在/benchmark下可运行性能测试脚本,以short.js为例,在MacbookPro(2.5 GHz Intel Core i5 / 8 GB 1600 MHz DDR3)上:
源库输出
pinyin: 1076ms
146112512
本库输出
# 0.2.0
pinyin: 12ms
1150976
# 0.1.0
pinyin: 131ms
31199232
| 项目 | 源库 | 本库 | 百分比 |
|---|---|---|---|
| 运算时间 | 1076ms | 12ms | 1.11% |
| 内存占用 | 139.3M | 1.1M | 0.79% |
重心中的重,不会得到chong这个读音,本库去掉了这个特性FAQs
The npm package node-pinyin receives a total of 223 weekly downloads. As such, node-pinyin popularity was classified as not popular.
We found that node-pinyin demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Recent coverage mislabels the latest TEA protocol spam as a worm. Here’s what’s actually happening.

Security News
PyPI adds Trusted Publishing support for GitLab Self-Managed as adoption reaches 25% of uploads

Research
/Security News
A malicious Chrome extension posing as an Ethereum wallet steals seed phrases by encoding them into Sui transactions, enabling full wallet takeover.