MCPcopy Index your code
hub / github.com/zh-lx/pinyin-pro

github.com/zh-lx/pinyin-pro @3.28.0 sqlite

repository ↗ · DeepWiki ↗ · release 3.28.0 ↗
175 symbols 435 edges 93 files 10 documented · 6% 6 cross-repo links
README

logo

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>

💡 使用示例

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

```js 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

```js import { match } from "pinyin-pro";

// 支持首字母匹配 match("中文拼音", "zwp"); // [0, 1, 2]

// 支持全拼匹配 match("中文拼音", "zhongwenpin"); // [0, 1, 2]

// 支持混合匹配 match("中文拼音", "zhongwp"); // [0, 1, 2] ```

  • 拼音格式转换,更多功能请查看convert API

```js 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

```js import { html } from "pinyin-pro";

// 带拼音汉字的 HTML 字符串 html("汉语拼音"); / ( hàn ) ( ) / ```

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

🏆 竞品对比

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

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

📠 反馈

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

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

Extension points exported contracts — how you extend this code

MatchOptions (Interface)
(no doc)
types/core/match/index.d.ts
SingleWordResult (Interface)
(no doc)
types/common/type.d.ts
MatchOptions (Interface)
(no doc)
lib/core/match/index.ts
SingleWordResult (Interface)
(no doc)
lib/common/type.ts
BasicOptions (Interface)
(no doc)
types/core/pinyin/index.d.ts
Pattern (Interface)
(no doc)
types/common/ac.d.ts
BasicOptions (Interface)
(no doc)
lib/core/pinyin/index.ts
Pattern (Interface)
(no doc)
lib/common/segmentit/index.ts

Core symbols most depended-on inside this repo

pinyin
called by 223
lib/core/pinyin/index.ts
match
called by 32
lib/core/match/index.ts
get
called by 31
lib/common/utils.ts
customPinyin
called by 22
lib/core/custom/index.ts
stringLength
called by 17
lib/common/utils.ts
segment
called by 15
lib/core/segment/index.ts
html
called by 15
lib/core/html/index.ts
addDict
called by 14
lib/core/dict/index.ts

Shape

Function 74
Interface 64
Class 16
Method 15
Enum 6

Languages

TypeScript100%

Modules by API surface

lib/common/segmentit/index.ts18 symbols
lib/core/segment/index.ts11 symbols
lib/core/pinyin/handle.ts11 symbols
types/core/segment/index.d.ts10 symbols
lib/core/polyphonic/index.ts10 symbols
lib/core/pinyin/middlewares.ts9 symbols
lib/common/utils.ts8 symbols
types/common/segmentit/index.d.ts7 symbols
lib/core/pinyin/index.ts7 symbols
benchmark/compare.js7 symbols
types/core/polyphonic/index.d.ts6 symbols
types/core/pinyin/index.d.ts6 symbols

Dependencies from manifests, versioned

@commitlint/cli11.0.0 · 1×
@commitlint/config-conventional11.0.0 · 1×
@napi-rs/pinyin1.7.1 · 1×
@pinyin-pro/data1.3.0 · 1×
@rollup/plugin-commonjs17.1.0 · 1×
@rollup/plugin-json4.1.0 · 1×
@rollup/plugin-node-resolve11.2.0 · 1×
@types/jest26.0.20 · 1×
@typescript-eslint/eslint-plugin4.26.0 · 1×
@vitest/coverage-v81.5.0 · 1×
babel-eslint10.1.0 · 1×

For agents

$ claude mcp add pinyin-pro \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact