JS实现拼音搜索汉字(支持首字母匹配)
2020-03-06 16:21
4119 查看
JS 拼音匹配
如果对你项目有帮助麻烦在github上点个star
仓库: https://github.com/xmflswood/pinyin-match
介绍
能够使用拼音快速检索目标。
- 28.5KB (gzip => 20.3KB)
- 支持多音字、拼音首字母匹配,具备分词功能
- 覆盖 6763 个汉字
- 返回位置信息,可用于高亮匹配字符
- 在长多音字串下依然有高性能
在线演示:http://139.199.181.200:8686;
安装
npm install pinyin-match --save
也支持
<script>引入
<script src="pinyin-match/dist/main.js"></script>
PinyinMatch.match('xxx', 'x')
API
.match(input, keyword)
查询匹配拼音的数据。
参数:
- input
{string}
目标字符串 - keyword
{string}
输入的拼音或其他关键词
返回:
{[Array]|{Boolean}}
使用范例
列表项为字符串:
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]
- 点赞 3
- 收藏
- 分享
- 文章举报
相关文章推荐
- AutoCompleteTextView实现拼音汉字匹配且支持首字母
- 一个简单的汉字搜索匹配示例(支持拼音、首字母简写)
- Android 实现ListView的A-Z字母排序和过滤搜索功能,实现汉字转成拼音
- Android 实现ListView的A-Z字母排序和过滤搜索功能,实现汉字转成拼音
- Android 实现ListView的A-Z字母排序和过滤搜索功能,实现汉字转成拼音
- Android 实现ListView的A-Z字母排序和过滤搜索功能,实现汉字转成拼音
- Android 实现ListView的A-Z字母排序和过滤搜索功能,实现汉字转成拼音
- Android 实现ListView的A-Z字母排序和过滤搜索功能,实现汉字转成拼音
- Android实现ListView的A-Z字母排序和过滤搜索功能,实现汉字转成拼音
- Android 实现ListView的A-Z字母排序和过滤搜索功能,实现汉字转成拼音
- Android 实现ListView的A-Z字母排序和过滤搜索功能,实现汉字转成拼音
- AutoCompleteTextView输入汉字拼音首字母实现过滤提示(支持多音字,Filterable的使用)
- Android 实现ListView的A-Z字母排序和过滤搜索功能,实现汉字转成拼音
- JS实现获取汉字首字母拼音、全拼音及混拼音的方法
- ios 模糊搜索支持首字母搜索、拼音搜索、汉字搜索
- Android 利用AutoCompleteTextView实现模糊搜索功能,搜索结果自动提示,识别拼音首字母并转汉字提示
- Android 实现ListView的A-Z字母排序和过滤搜索功能,实现汉字转成拼音
- Android实现ListView的A-Z字母排序和过滤搜索功能,实现汉字转成拼音
- ios搜索(可实现模糊搜索 支持拼音检索 首字母等)
- Android 实现ListView的A-Z字母排序和过滤搜索功能,实现汉字转成拼音