前端开发时,有时数据过多需要快速检索功能,常用的关键字匹配和拼音检索,发现一个不错的插件pinyin-match。
个人感觉应用场景为,数据量不是特别大,一次性加载到前端,由前端实现过滤。数据过大时还是后端完成比较好。
github地址:https://github.com/xmflswood/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]