npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pinyin-pro

v3.26.0

Published

准确率和性能最优异的汉字转拼音库。获取中文拼音、韵母、声母、声调、首字母,支持拼音匹配

Downloads

118,259

Readme

NPM version GITHUB star build-passing NPM Downloads Coverage Status DeepScan grade MIT-license npm bundle size 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 在各方面都全面领先。

📠 反馈

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

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