Giter Site home page Giter Site logo

afenotes / pinyin-match Goto Github PK

View Code? Open in Web Editor NEW

This project forked from xmflswood/pinyin-match

0.0 0.0 0.0 341 KB

拼音匹配,具备分词、缩写、多音字匹配能力,支持繁体版

License: Other

JavaScript 67.02% TypeScript 0.75% HTML 32.23%

pinyin-match's Introduction

如果有帮助,麻烦点个Star

具体实现文档

https://juejin.cn/post/6844904161461403661

pinyin-match

能够使用拼音快速检索目标。

  1. 简体版27KB (gzip ≈ 19KB),繁体版86KB (gzip ≈ 60KB)
  2. 支持多音字、繁体字、拼音首字母匹配,具备分词功能
  3. 返回位置信息,可用于高亮匹配字符
  4. 在长多音字串下依然有高性能

在线演示:http://laosep.top/pinyin-match;

安装

npm install pinyin-match --save

支持<script>引入

简体:<script src="pinyin-match/dist/main.js"></script>

繁体:<script src="pinyin-match/dist/traditional.js"></script>

使用方式:
PinyinMatch.match('xxx', 'x')

API

.match(input, keyword)

查询匹配拼音的数据。

参数:

  1. input {string} 目标字符串
  2. keyword {string} 输入的拼音或其他关键词

返回:

{[Array]|{Boolean}}

使用范例

引入简体版:

import PinyinMatch from 'pinyin-match';  // es  

const PinyinMatch = require('pinyin-match'); // commonjs

引入繁体版(es):

import PinyinMatch from 'pinyin-match/es/traditional.js'; // es  

const PinyinMatch = require('pinyin-match/lib/traditional.js'); // commonjs

列表项为字符串:

let test = '123曾经沧海难为水除却巫山不是云'

PinyinMatch.match(test, '23曾'); // [1, 3]

PinyinMatch.match(test, 'cjc') // [3, 5]

PinyinMatch.match(test, 'cengjingcanghai') // [3, 6]

PinyinMatch.match(test, 'cengjingcangha') // [3, 6]

PinyinMatch.match(test, 'engjingcanghai') // false

PinyinMatch.match(test, 'zengjingcang') // [3, 5]

PinyinMatch.match(test, 'sdjkelwqf') // false

PinyinMatch.match(test, 'zengji ng cang') // [3, 5]

PinyinMatch.match(test, 'zengji ng cangsdjfkl') // false

PinyinMatch.match('   我 爱你 中   国   ', 'nzg') // [6, 12]

PinyinMatch.match('   我 爱你 中   国   ', '爱你中') // [5, 8]

PinyinMatch.match('發', 'fa') // [0, 0]

许可证

pinyin-match is under The Star And Thank Author License (SATA)

本项目基于MIT协议发布,并增加了SATA协议

仓库

https://github.com/xmflswood/pinyin-match

pinyin-match's People

Contributors

dependabot[bot] avatar huskylengcb avatar lc-soft avatar michael18811380328 avatar miserylee avatar xmflswood avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.