前言
pinyin-pro 是一个专业的 js 汉字拼音转换库,功能丰富、准确率高、性能优异。
https://gitcode.com/zh-lx/pinyin-pro/overview?utm_source=csdn_github_accelerator
安装
npm 安装
浏览器引入
1
| <script src="https://unpkg.com/pinyin-pro"></script>
|
使用
获取拼音
详细文档
https://pinyin-pro.cn/use/pinyin
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| import { pinyin } from 'pinyin-pro';
pinyin('汉语拼音');
pinyin('汉语拼音', { type: 'array' });
pinyin('汉语拼音', { toneType: 'none' });
pinyin("姓名 Hello", { toneType: "none", separator: "" }) .replaceAll(" ", "") .toLowerCase()
pinyin('汉语拼音', { toneType: 'none', type: 'array' });
pinyin('汉语拼音', { toneType: 'num' });
pinyin('睡着了');
|
文本和拼音匹配
1 2 3 4 5 6 7 8 9 10
| import { match } from 'pinyin-pro';
match('中文拼音', 'zwp');
match('中文拼音', 'zhongwenpin');
match('中文拼音', 'zhongwp');
|
拼音格式转换
1 2 3 4 5 6 7 8 9 10
| import { convert } from 'pinyin-pro';
convert('pin1 yin1');
convert('pīn yīn', { format: 'symbolToNum' });
convert('pīn yīn', { format: 'toneNone' });
|
获取带汉字拼音的 HTML 字符串
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| import { html } from 'pinyin-pro';
html('汉语');
|