-
获取拼音,更多功能请查看pinyin API
import { pinyin } from "pinyin-pro";
pinyin("汉语拼音");
pinyin("汉语拼音", { type: "array" });
pinyin("汉语拼音", { toneType: "none" });
pinyin("汉语拼音", { toneType: "none", type: "array" });
pinyin("汉语拼音", { toneType: "num" });
pinyin("睡着了");
-
使用词典,获取更准确的拼音。( pinyin-pro
内置了一些高频常用词的词典,想要保证高准确率,需要应用更完备的词典)
import { pinyin, addDict } from "pinyin-pro";
import ModernChineseDict from "@pinyin-pro/data/modern.json";
import CompleteDict from "@pinyin-pro/data/complete.json";
const result1 = pinyin(
"小明硕士毕业于中国科学院计算所,后在日本京都大学深造"
);
addDict(ModernChineseDict);
const result2 = pinyin(
"小明硕士毕业于中国科学院计算所,后在日本京都大学深造"
);
addDict(CompleteDict);
const result3 = pinyin(
"小明硕士毕业于中国科学院计算所,后在日本京都大学深造"
);
-
文本和拼音匹配,更多匹配规则请查看match API
import { match } from "pinyin-pro";
match("中文拼音", "zwp");
match("中文拼音", "zhongwenpin");
match("中文拼音", "zhongwp");
-
拼音格式转换,更多功能请查看convert API
import { convert } from "pinyin-pro";
convert("pin1 yin1");
convert("pīn yīn", { format: "symbolToNum" });
convert("pīn yīn", { format: "toneNone" });
-
获取带汉字拼音的 HTML 字符串,更多配置请查看html API
import { html } from "pinyin-pro";
html("汉语拼音");
上述结果浏览器中预览效果如下:
汉
语