黑白梦黑白梦

  • 文章
  • 专栏
  • 文章
  • 专栏

©2015-2026 黑白梦 粤ICP备15018165号

联系: heibaimeng@foxmail.com

全部文章

pinyin 汉字转拼音

发布于 2020-07-13更新于 2023-04-08约 1 分钟

转换中文字符为拼音。可以用于汉字注音、排序、检索。

https://github.com/hotoo/pinyin

npm install pinyin

可设置是否带声调、可只返回首字母、可考虑多音字。

支持web和node。

内置了排序规则:

const pinyin = require('pinyin');

const data = '我要排序'.split('');
const sortedData = data.sort(pinyin.compare);

本文收录于专栏

一些好用的 npm 前端开源库

收集一些好用的前端开源库,主要是 npm 包

0 篇文章更新于 2026-08-17
上一篇localForage 前端储存库下一篇前台代码高亮方案 highlight.js 应用,支持网页与微信小程序