New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

pinyin-fixed

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pinyin-fixed

JavaScript拼音匹配

latest
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

pinyin-fixed(来自 pinyin-engine)

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

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

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

安装

npm install pinyin-fixed --save

API

new PinyinEngine(list, keys)

建立拼音索引。

参数:

  • list {[string]|[Object]} 被索引的目标
  • keys {[string]} 可选。如果 list 为 Object,这里用来设置需要被索引的 key

.query(keyword)

查询匹配拼音的数据。

参数:

  • keyword {string} 拼音或者关键字

返回:

{[string]|{Object}}

繁体中文版本

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

const PinyinEngine = require('pinyin-fixed/tw')

使用范例

列表项为字符串:

const PinyinEngine = require('pinyin-fixed')

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

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

列表项为对象:

const PinyinEngine = require('pinyin-fixed')

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

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

##重要

这个包是搬运来自 pinyin-engine

因为有一个首字母如果大写不匹配的 bug 和繁体版本引入 bug,所以做了一点微小的更正,原则上只是方面自己使用的版本,请大家支持原作者aui,谢谢开源社区

Keywords

javascript

FAQs

Package last updated on 19 Jul 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts