工具包 pinyin-pro
npm install pinyin-pro
官方地址
pinyin-pro | pinyin-pro性能优异、转换准确的 js 中文转拼音工具https://pinyin-pro.cn/示例代码(获取每个汉字的拼音首字母)
import {pinyin} from 'pinyin-pro';function getPinyinInitial(name){if (name) {let py = pinyin(name, {pattern: 'initial', type: 'array'})if (py.length) {return py.map(x => x.length ? x[0] : x).join('')}}return ''
}