物管理前端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
2.3 KiB

  1. # 如果有帮助,麻烦点个Star
  2. # 具体实现文档
  3. https://juejin.cn/post/6844904161461403661
  4. # pinyin-match
  5. 能够使用拼音快速检索目标。
  6. 1. 简体版27KB (gzip ≈ 19KB),繁体版86KB (gzip ≈ 60KB)
  7. 2. 支持多音字、繁体字、拼音首字母匹配,具备分词功能
  8. 3. 返回位置信息,可用于高亮匹配字符
  9. 4. 在长多音字串下依然有高性能
  10. 在线演示:<https://xmflswood.github.io/pinyin-match/>;
  11. ## 安装
  12. ```shell
  13. npm install pinyin-match --save
  14. ```
  15. 支持`<script>`
  16. 简体:`<script src="pinyin-match/dist/main.js"></script>`
  17. 繁体:`<script src="pinyin-match/dist/traditional.js"></script>`
  18. 使用方式:
  19. `PinyinMatch.match('xxx', 'x')`
  20. ## API
  21. ### .match(input, keyword)
  22. 查询匹配拼音的数据。
  23. 参数:
  24. 1. input `{string}` 目标字符串
  25. 2. keyword `{string}` 输入的拼音或其他关键词
  26. 返回:
  27. `{[Array]|{Boolean}}`
  28. ## 使用范例
  29. 引入简体版:
  30. ```
  31. import PinyinMatch from 'pinyin-match'; // es
  32. const PinyinMatch = require('pinyin-match'); // commonjs
  33. ```
  34. 引入繁体版(es):
  35. ```
  36. import PinyinMatch from 'pinyin-match/es/traditional.js'; // es
  37. const PinyinMatch = require('pinyin-match/lib/traditional.js'); // commonjs
  38. ```
  39. 列表项为字符串:
  40. ```js
  41. let test = '123曾经沧海难为水除却巫山不是云'
  42. PinyinMatch.match(test, '23曾'); // [1, 3]
  43. PinyinMatch.match(test, 'cjc') // [3, 5]
  44. PinyinMatch.match(test, 'cengjingcanghai') // [3, 6]
  45. PinyinMatch.match(test, 'cengjingcangha') // [3, 6]
  46. PinyinMatch.match(test, 'engjingcanghai') // false
  47. PinyinMatch.match(test, 'zengjingcang') // [3, 5]
  48. PinyinMatch.match(test, 'sdjkelwqf') // false
  49. PinyinMatch.match(test, 'zengji ng cang') // [3, 5]
  50. PinyinMatch.match(test, 'zengji ng cangsdjfkl') // false
  51. PinyinMatch.match(' 我 爱你 中 国 ', 'nzg') // [6, 12]
  52. PinyinMatch.match(' 我 爱你 中 国 ', '爱你中') // [5, 8]
  53. PinyinMatch.match('發', 'fa') // [0, 0]
  54. ```
  55. ## 许可证
  56. pinyin-match is under The Star And Thank Author License (SATA)
  57. 本项目基于MIT协议发布,并增加了SATA协议
  58. ## 其他语言版本
  59. 欢迎其他语言开发者增加对应版本(标明来自本项目即可)
  60. ### GO
  61. https://github.com/limawanyan/go-pinyin-match
  62. ## 仓库
  63. https://github.com/xmflswood/pinyin-match