Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pinyinlite

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pinyinlite

Lightweight Pinyin library

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
82
decreased by-15.46%
Maintainers
1
Weekly downloads
 
Created
Source

pinyinlite

Build Status Coverage Status Dependency Status npm version MIT license

NPM

轻量级 JavaScript 拼音库,支持多音字,适合在前后端解决基于拼音的字符串匹配问题。

npm install pinyinlite

特点

  • Zero dependency!

  • 字典包含 2.4 万多个简体繁体字,覆盖 Unicode BMP 常见汉字。

  • 体积小巧(minified ~ 80KB, gzip ~ 55 KB),适合前端使用。

  • 内存占用低(~ 1 MB),效率高(~ 10,000,000 字/s),适合后端使用。

  • 支持多音字。

  • 不支持且不计划支持智能选择多音字拼音。

  • 不支持且不计划支持音调。

使用方法

Node.js

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)

options.keepUnrecognized

是否保留无法获得拼音的全角字符,默认为 false,即不保留(相应位置是空数组)。

注意,半角字符总是会原样输出。

pinyinlite('4C,测试');
// => [ [ '4' ], [ 'C' ], [], [ 'ce' ], [ 'shi' ] ]

pinyinlite('4C,测试', {
  keepUnrecognized: true
});
// => [ [ '4' ], [ 'C' ], [ ',' ], [ 'ce' ], [ 'shi' ] ]

Benchmark

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

License

MIT

Keywords

FAQs

Package last updated on 06 Feb 2016

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc