npm i -s pinyin-test
const Pinyin = require('pinyin-test');
const dict = require('./dict.json');
p = new Pinyin(dict);
r = p.test('拼音', 'pinyin');
字典需要手动加载,可以根据实际情况选择合适的字典。 demo:https://github.com/roughwin/pinyin-filter/blob/master/test/word.json
p.test('合作项目', 'hezuoxiangmu') // output: 4
p.test('合作项目', 'hzxm') // output: 4
p.test('合作项目', 'hxm') // output: 3
p.test('合作项目', '合作xm') // output: 4
p.test('合作项目abc', 'hzxmabc') // output: 7
p.test('银行', yinhang) // output: 2
p.test('银行', yinxing) // output: 2