• Stars
    star
    458
  • Rank 92,686 (Top 2 %)
  • Language
    HTML
  • License
    MIT License
  • Created almost 7 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

JavaScript 拼音匹配引擎

pinyin-engine

这是一款简单高效的拼音匹配引擎,它能使用拼音够快速的检索列表中的数据。

  1. 使用索引以及缓存机制,从而在客户端实现毫秒级的数据检索
  2. 它的字典数据格式经过压缩处理,简体中文版本仅仅 17kb 大小(Gzip)
  3. 支持多音字、支持拼音首字母匹配
  4. 简体版本覆盖 6718 个汉字,繁体中文覆盖 20846 个汉字

在线演示:https://aui.github.io/pinyin-engine/example/

安装

npm install pinyin-engine --save

API

new PinyinEngine(list, keys)

建立拼音索引。

参数:

  1. list {[string]|[Object]} 被索引的目标
  2. keys {[string]} 可选。如果 list 为 Object,这里用来设置需要被索引的 key
  3. begin {[boolean]} 可选。如果 begin 为 true,将执行前模糊检索

.query(keyword)

查询匹配拼音的数据。

参数:

  1. keyword {string} 拼音或者关键字

返回:

{[string]|{Object}}

繁体中文版本

包含简体中文与繁体中文。

const PinyinEngine = require('pinyin-engine/tw');

使用范例

列表项为字符串:

const PinyinEngine = require('pinyin-engine');

// 建立数据索引
const pinyinEngine = new PinyinEngine([
    '清华大学',
    '北京大学',
    '中央美院'
]);

// 查询
pinyinEngine.query('daxue'); // ['清华大学', '北京大学']

列表项为对象:

const PinyinEngine = require('pinyin-engine');

// 建立数据索引
const pinyinEngine = new PinyinEngine([
    { id: 0, name: '清华大学' },
    { id: 1, name: '北京大学' },
    { id: 3, name: '中央美院' }
], ['name']);

// 查询
pinyinEngine.query('daxue'); // ['清华大学', '北京大学']

More Repositories

1

art-template

High performance JavaScript templating engine
JavaScript
9,834
star
2

font-spider

Smart webfont compression and format conversion tool
JavaScript
4,940
star
3

artDialog

经典的网页对话框组件
JavaScript
3,135
star
4

tmodjs

前端模板外置解决方案
JavaScript
668
star
5

gulp-font-spider

字蛛 gulp 插件
JavaScript
190
star
6

angular-popups

基于Angularjs的浮层组件
HTML
117
star
7

popupjs

W3C HTML5 Dialog Plus
JavaScript
112
star
8

art-template-loader

art-template loader for webpack
JavaScript
106
star
9

node2bat

基于JScript的迷你NodeJS运行时
Shell
57
star
10

angular-drag

基于Angularjs的拖拽指令
HTML
55
star
11

jsonp-sandbox

jsonp sandbox
JavaScript
49
star
12

browser-x

一个基于 NodeJS 实现的虚拟浏览器
JavaScript
48
star
13

express-art-template

art-template for express
JavaScript
43
star
14

koa-art-template

a koa view render middleware, support all feature of art-template
JavaScript
41
star
15

grunt-font-spider

字蛛 grunt 插件
JavaScript
35
star
16

include-file

HTML 静态文件局部模板批量更新工具
HTML
23
star
17

blog

18
star
18

art-template-docs

art-template document
JavaScript
12
star
19

grunt-unwrap

将 CMD 模块转换成不依赖加载器的工具
JavaScript
9
star
20

vs-code-github-markdown-theme

vs code: markdown theme
CSS
7
star
21

koa-gitlab

simple gitlab auth middleware for koa
JavaScript
4
star
22

devtools-watcher

DevTools Watcher
HTML
3
star
23

sublime-art

art-template syntax definition for Sublime Text 3
3
star
24

file-cache-webpack-plugin

Webpack plugin that persists the compiler cache to the file system
JavaScript
2
star
25

free-fonts

收录字蛛可以压缩并且免费的字体
2
star
26

amd-to-commonjs

JavaScript
1
star
27

ISPAdBlock

ISP 广告拦截器
1
star
28

hexo-renderer-art

art-template renderer for Hexo
JavaScript
1
star