npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ts-pinyin-lxc

v1.0.1

Published

ts模块化的轻量拼音库

Downloads

1

Readme

本项目为sxei/pinyinjs项目修改而成

本项目仅支持TS(模块化)

安装

npm i ts-pinyin-lxc

使用

为了优化大小,字典可按需导入:

有以下字典(大小从小到大):

  • pinyin_dict_firstletter -> 仅使用汉字转拼音首字母
  • pinyin_dict_notone -> 没有声调、不支持多音字的字典
  • pinyin_dict_withtone -> 含有声调、支持多音字的字典
  • pinyin_dict_polyphone -> 词库(带多音字的词语更精确) 词典巨大, 不推荐

获取没有声调的拼音

// 导入工具和字典
import {pinyinUtil} from 'ts-pinyin-lxc'
import {pinyin_dict_notone} from 'ts-pinyin-lxc/dict'

// 添加字典
pinyinUtil.addDict(pinyin_dict_notone)

/**
 * 根据汉字获取拼音,如果不是汉字直接返回原字符
 * @param chinese 要转换的汉字
 * @param splitter 分隔字符,默认用空格分隔
 * @param withtone 返回结果是否包含声调(需要withtone字典),默认为false
 * @param polyphone 是否支持多音字(需要withtone字典),默认false,如果为true,会返回所有可能的组合数组, 导入pinyin_dict_polyphone词库后设为true才启用词库匹配(此时返回string)
 * @return 如果polyphone为false则返回string, 如果polyphone为true但没有导入pinyin_dict_polyphone词库则返回string[] (各个音的所有可能字符串数组), 导入了则返回string
 */
const result = pinyinUtil.getPinyin('你好世界')

console.log(result);

获取含有声调的拼音

// 导入工具和字典
import {pinyinUtil} from 'ts-pinyin-lxc'
import {pinyin_dict_withtone} from 'ts-pinyin-lxc/dict'

// 添加字典
pinyinUtil.addDict(pinyin_dict_withtone)

/**
 * 根据汉字获取拼音,如果不是汉字直接返回原字符
 * @param chinese 要转换的汉字
 * @param splitter 分隔字符,默认用空格分隔
 * @param withtone 返回结果是否包含声调(需要withtone字典),默认为false
 * @param polyphone 是否支持多音字(需要withtone字典),默认false,如果为true,会返回所有可能的组合数组, 导入pinyin_dict_polyphone词库后设为true才启用词库匹配(此时返回string)
 * @return 如果polyphone为false则返回string, 如果polyphone为true但没有导入pinyin_dict_polyphone词库则返回string[] (各个音的所有可能字符串数组), 导入了则返回string
 */
const result = pinyinUtil.getPinyin('你好世界', ' ', true)

console.log(result);

要获取拼音首字母

// 导入工具和字典
import {pinyinUtil} from 'ts-pinyin-lxc'
import {pinyin_dict_firstletter} from 'ts-pinyin-lxc/dict'

// 添加字典
pinyinUtil.addDict(pinyin_dict_firstletter)

/**
 * 获取汉字的拼音首字母
 * @param str 汉字字符串,如果遇到非汉字则原样返回
 * @param polyphone 是否支持多音字(需要withtone字典),默认false,如果为true,会返回所有可能的组合数组, 导入pinyin_dict_polyphone词库后设为true才启用词库匹配(此时返回string)
 * @return 如果polyphone为false则返回string, 如果polyphone为true但没有导入pinyin_dict_polyphone词库则返回string[] (各个音的所有可能字符串数组), 导入了则返回string
 */
const result = pinyinUtil.getFirstLetter('你好世界')

console.log(result);

从拼音获取汉字

// 导入工具和字典
import {pinyinUtil} from 'ts-pinyin-lxc'
import {pinyin_dict_withtone} from 'ts-pinyin-lxc/dict'

// 添加字典
pinyinUtil.addDict(pinyin_dict_withtone)

/**
 * 拼音转汉字,只支持单个汉字,返回所有匹配的汉字组合
 * @param pinyin 单个汉字的拼音
 */
const result = pinyinUtil.getHanzi('hao')

console.log(result);

更多详细介绍

更多介绍请前往原项目查看: https://github.com/sxei/pinyinjs