安装
npm install js-pinyin
引入
import pinyin from 'js-pinyin'
使用示例
let pinyin = require("js-pinyin");
pinyin.setOptions({ checkPolyphone: false, charCase: 1 });
pinyin.getFullChars('管理员'); // 全拼 guanliyuan
pinyin.getCamelChars('管理员');// 文字首字母 gly
pinyin.setOptions({ checkPolyphone: false, charCase: 0 });
pinyin.getFullChars('管理员'); // 全拼 GuanLiYuan
pinyin.getCamelChars('管理员');// 文字首字母 GLY
最后 我们阔以 使用 .charAt(0)获取首字母