pinyin-util
汉字拼音转换工具
字符范围:Unicode字符中4E00(19968)-9FA5(40869)
共计20902
Install with npm:
npm install --save-dev pinyin-util
Install with yarn:
yarn add pinyin-util --dev
ES6 module:
import pinyinUtil from 'pinyin-util';
pinyinUtil.getPinyin('小明'); // xiaoming
Script:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>pinyin-util</title>
<script src="pinyin-util.min.js"></script>
</head>
<body>
<script type="text/javascript">
pinyinUtil.getPinyin('小明'); // xiaoming
</script>
</body>
</html>
根据汉字获取拼音
getPinyin('小明', ' '); // xiao ming
getPinyin('小明', ' ', true); // xiǎo míng
getPinyin('小明plus', ' '); // xiao ming plus
获取城市拼音【城市多音字已处理】
getCityPinyin('重庆市'); // chongqingshi
getCityPinyin('西藏', ' ', true); // xī zhàng
单个拼音转汉字
getHanzi('diu'); // 丟丢銩铥