# pinyin-fixed

> JavaScript拼音匹配

Latest version **1.0.1** (published 2018-07-19) · ISC license · 0 weekly downloads

## Install

```sh
npm install pinyin-fixed
pnpm add pinyin-fixed
yarn add pinyin-fixed
bun add pinyin-fixed
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2018-07-19 |
| First published | 2018-07-19 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 326.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | blossom91 |
| Maintainers | blossom91 |
| Keywords | javascript, pinyin |

## Links

- npm: https://www.npmjs.com/package/pinyin-fixed
- npm.io page: https://npm.io/package/pinyin-fixed

## Recent versions

- 1.0.1 (latest) — 2018-07-19
- 1.0.0 — 2018-07-19

## README

# pinyin-fixed(来自 pinyin-engine)

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

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

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

## 安装

```shell
npm install pinyin-fixed --save
```

## API

### new PinyinEngine(list, keys)

建立拼音索引。

参数：

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

### .query(keyword)

查询匹配拼音的数据。

参数：

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

返回：

`{[string]|{Object}}`

## 繁体中文版本

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

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

## 使用范例

列表项为字符串：

```js
const PinyinEngine = require('pinyin-fixed')

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

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

列表项为对象：

```js
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](https://github.com/aui/pinyin-engine),谢谢开源社区

---
_Source: https://npm.io/package/pinyin-fixed · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
