Pinyin Quick Find

installation

npm install pinyin-engine --save

API

new PinyinEngine(list, keys)

Establish pinyin index.

parameter:

  1. list  {[string]|[Object]} is indexed goal
  2. keys  {[string]} optional. If the list is  Objecthere used to set the key to be indexed

.query(keyword)

Query data matching alphabet.

parameter:

  1. keyword  {string} spelling or keyword

return:

{[string]|{Object}}

Traditional Chinese version

It contains Simplified Chinese and Traditional Chinese.

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

Examples of use

List item as a string:

const PinyinEngine require('pinyin-engine');
 
// Create Data Index
const pinyinEngine new PinyinEngine([
    'Tsinghua University ' ,
    'Peking ' ,
    'Center beauty salon '
]);
 
// Inquire
pinyinEngine . Query ( 'Daxue ' ) // [ 'Tsinghua', 'Peking']

List item as an object:

const PinyinEngine require('pinyin-engine');
 
// Create Data Index
const pinyinEngine new PinyinEngine([
    ID { 0 , name 'Tsinghua University } ,
    ID { . 1 , name "Peking } ,
    ID { . 3 , name 'CAFA }
]['name']);
 
// Inquire
pinyinEngine . Query ( 'Daxue ' ) // [ 'Tsinghua', 'Peking']
 
https://www.npmjs.com/package/pinyin-engine

Guess you like

Origin www.cnblogs.com/hellofangfang/p/10935174.html