前端拼音(汉字)检索,好用的插件 pinyin-match

安装插件pinyin-match

npm install pinyin-match --save

js引入

需要使用的文件位置进行引入
import PinyinMatch from ‘pinyin-match’;

能够实现的方法

let test = ‘123曾经沧海难为水除却巫山不是云’

PinyinMatch.match(test, ‘23曾’); // [1, 3]

PinyinMatch.match(test, ‘cjc’) // [3, 5]

PinyinMatch.match(test, ‘cengjingcanghai’) // [3, 6]

PinyinMatch.match(test, ‘cengjingcangha’) // [3, 6]

PinyinMatch.match(test, ‘engjingcanghai’) // false

PinyinMatch.match(test, ‘zengjingcang’) // [3, 5]

PinyinMatch.match(test, ‘sdjkelwqf’) // false

PinyinMatch.match(test, ‘zengji ng cang’) // [3, 5]

PinyinMatch.match(test, ‘zengji ng cangsdjfkl’) // false

PinyinMatch.match(’ 我 爱你 中 国 ', ‘nzg’) // [6, 12]

PinyinMatch.match(’ 我 爱你 中 国 ', ‘爱你中’) // [5, 8]

PinyinMatch.match(‘發’, ‘fa’) // [0, 0]

一些地址

pinyin-match的github 地址

https://github.com/xmflswood/pinyin-match

在线演练地址

http://laosep.top/pinyin-match;

具体实现文档

https://juejin.cn/post/6844904161461403661

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值