Giter Site home page Giter Site logo

kendrickcheung007 / pinyin-pro Goto Github PK

View Code? Open in Web Editor NEW

This project forked from zh-lx/pinyin-pro

0.0 0.0 0.0 8.85 MB

中文转拼音、拼音音调、拼音声母、拼音韵母、多音字拼音、姓氏拼音、拼音匹配

Home Page: https://pinyin-pro.cn

License: MIT License

JavaScript 5.00% TypeScript 95.00%

pinyin-pro's Introduction

pinyin-pro Logo

NPM version GITHUB star travis-build NPM Downloads Coverage Status MIT-license GITHUB-language

📖 介绍

pinyin-pro 是一个专业的 js 汉字拼音转换库,功能丰富、准确率高、性能优异。

中文文档 | English Docs | 在线运行

🎨 特色功能

  • 支持拼音/声母/韵母/首字母/音调/全部信息
  • 支持人名姓氏模式
  • 支持文本和拼音匹配
  • 支持自定义拼音
  • 支持获取带拼音汉字的 HTML 字符串
  • 支持获取汉字的所有拼音
  • 支持拼音输入转换
  • 极致的性能和极高的拼音识别准确率

🔨 安装

npm 安装

npm install pinyin-pro

浏览器引入

<script src="https://unpkg.com/pinyin-pro"></script>

💡 使用示例

全部功能的使用说明文档请查看在线文档

  • 获取拼音,更多功能请查看pinyin API

    import { pinyin } from 'pinyin-pro';
    
    // 获取字符串格式拼音
    pinyin('汉语拼音'); // 'hàn yǔ pīn yīn'
    
    // 获取数组格式拼音
    pinyin('汉语拼音', { type: 'array' }); // ["hàn", "yǔ", "pīn", "yīn"]
    
    // 获取不带音调数组格式拼音
    pinyin('汉语拼音', { toneType: 'none' }); // "han yu pin yin"
    
    // 获取不带音调数组格式拼音
    pinyin('汉语拼音', { toneType: 'none', type: 'array' }); // ["han", "yu", "pin", "yin"]
    
    // 音调以数组形式显示
    pinyin('汉语拼音', { toneType: 'num' }); // "han4 yu3 pin1 yin1"
    
    // 自动识别多音字
    pinyin('睡着了'); // "shuì zháo le"
  • 文本和拼音匹配,更多匹配规则请查看match API

    import { match } from 'pinyin-pro';
    
    // 支持首字母匹配
    match('中文拼音', 'zwp'); // [0, 1, 2]
    
    // 支持全拼匹配
    match('中文拼音', 'zhongwenpin'); // [0, 1, 2]
    
    // 支持混合匹配
    match('中文拼音', 'zhongwp'); // [0, 1, 2]
  • 拼音格式转换,更多功能请查看convert API

    import { convert } from 'pinyin-pro';
    
    // 数组转符号
    convert('pin1 yin1'); // 'pīn yīn'
    
    // 符号转数字
    convert('pīn yīn', { format: 'symbolToNum' }); // 'pin1 yin1'
    
    // 消除符号
    convert('pīn yīn', { format: 'toneNone' }); // 'pin yin'
  • 获取带汉字拼音的 HTML 字符串,更多配置请查看html API

    import { html } from 'pinyin-pro';
    
    // 带拼音汉字的 HTML 字符串
    html('汉语拼音');
    /*
    <span class="py-result-item">
    <ruby>
        <span class="py-chinese-item">汉</span>
        <rp>(</rp>
        <rt class="py-pinyin-item">hàn</rt>
        <rp>)</rp>
    </ruby>
    </span>
    <span class="py-result-item">
    <ruby>
        <span class="py-chinese-item">语</span>
        <rp>(</rp>
        <rt class="py-pinyin-item">yǔ</rt>
        <rp>)</rp>
    </ruby>
    </span>
    */

    上述结果浏览器中预览效果如下: ( hàn ) ( )

🏆 竞品对比

以下是 pinyin-propinyin@napi-rs/pinyin 包对于汉字转换的速度及准确率对比,可以看到 pinyin-pro 在各方面都全面领先。

对比项 pinyin @napi-rs/pinyin pinyin-pro
准确率 😕 Node 版: 97.844% 😕 97.433% 🤩 99.744%
😕 Web 版: 94.507%
性能 5k字转换耗时 🐢 749.111ms 🚲 200.877ms 🚀 5.958ms
1w字转换耗时 🐢 795.904ms 🚲 206.5ms 🚀 15.260ms
100w字转换耗时 ⛔ 内存溢出转换失败 🚀 638.888ms 🚀 607.131ms
兼容性 Web 环境 ✔️ 支持 ❌ 不支持 ✔️ 支持
Node 环境 ✔️ 支持 ✔️ 支持 ✔️ 支持

📠 反馈

使用遇到问题或者需要功能支持欢迎提 issue。

技术交流欢迎加 pinyin-pro 用户群 或者微信:

pinyin-pro's People

Contributors

zh-lx avatar maryue avatar tonyrl avatar lxxiaoxin1 avatar baboon-king avatar vhly avatar bangbang93 avatar niuhaorong avatar zhennann avatar tsuk1ko avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.