npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pinyin-engine

v1.2.2

Published

小巧高效的拼音匹配引擎

Downloads

403

Readme

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'); // ['清华大学', '北京大学']