前端拼音模糊搜索

前端实现拼音模糊搜索
pinyin-match
[https://github.com/xmflswood/…[1]

const PinyinMatch = require(‘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(text, ‘zengji ng cang’) // [3, 5]

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

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

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

    原文作者:weijie
    原文地址: https://segmentfault.com/a/1190000018997760
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞