Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
轻量级 JavaScript 拼音库,支持多音字,适合在前后端解决基于拼音的字符串匹配问题。
npm install pinyinlite
Zero dependency!
字典包含 2.4 万多个简体繁体字,覆盖 Unicode BMP 常见汉字。
体积小巧(minified ~ 80KB, gzip ~ 55 KB),适合前端使用。
内存占用低(~ 1 MB),效率高(~ 10,000,000 字/s),适合后端使用。
支持多音字。
不支持且不计划支持智能选择多音字拼音。
不支持且不计划支持音调。
var pinyinlite = require('pinyinlite');
pinyinlite('增长');
// => [ [ 'zeng' ], [ 'zhang', 'chang' ] ]
<script src="dist/pinyinlite.min.js"></script>
<script>
console.log(pinyinlite('世界你好'));
// => [ [ 'shi' ], [ 'jie' ], [ 'ni' ], [ 'hao' ]]
</script>
pinyinlite(str, options)
是否保留无法获得拼音的全角字符,默认为 false
,即不保留(相应位置是空数组)。
注意,半角字符总是会原样输出。
pinyinlite('4C,测试');
// => [ [ '4' ], [ 'C' ], [], [ 'ce' ], [ 'shi' ] ]
pinyinlite('4C,测试', {
keepUnrecognized: true
});
// => [ [ '4' ], [ 'C' ], [ ',' ], [ 'ce' ], [ 'shi' ] ]
npm run benchmark
测试项 | 字典大小 | require() 内存和耗时 | 长句耗时 | 速度 |
---|---|---|---|---|
pinyinlite | ~24000 字 | +1.2 MB, 9.1 ms | ~2.2 ms | ~10^7 字/s |
hutoo/pinyin (web) | ~3500 字 | +2.1 MB, 10.0 ms | ~17.1 ms | ~10^6 字/s |
hutoo/pinyin (node) | ~41000 字 | +32.3 MB, 123.5 ms | ~184.8 ms | ~10^5 字/s |
配置均为:标注全部多音字、不智能选择多音字,长句长度约 20000 字。
如果你需要将拼音用于呈现,即需要多音字智能识别、音调等功能,请移步:https://github.com/hotoo/pinyin/
字典源文件位于 dev/dict.txt
。
更新字典源文件后需要调用 node dev/parse_dict.txt
生成相应的 src/dict.js
。
npm test
MIT
FAQs
Lightweight and Lightning-Fast Pinyin library
The npm package pinyinlite receives a total of 72 weekly downloads. As such, pinyinlite popularity was classified as not popular.
We found that pinyinlite 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.