Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pinyin-pro

Package Overview
Dependencies
Maintainers
1
Versions
147
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pinyin-pro

专业的、功能最丰富的中文汉字与拼音的转化库

  • 1.0.2
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

pinyin-pro

专业的、功能最丰富的中文汉字与拼音的转化库

安装

npm install pinyin-pro

引入

import { pinyin } from 'pinyin-pro'

基本用法

pinyin(word, options) 接收两个参数

  • word:string 类型,需要转化为拼音的词语
  • options:object 类型,用于配置各种输出形式

获取各种格式的拼音

import { pinyin } from 'pinyin-pro'

// 获取带音调拼音
pinyin('汉语拼音') // 'hàn yǔ pīn yīn'

// 将声调转换为数字后缀
pinyin('汉语拼音', { pattern: 'pinyinNum' }) // 'han4 yu3 pin1 yin1'

// 获取声母
pinyin('汉语拼音', { pattern: 'initial' }) // 'h y p y'

// 获取韵母
pinyin('汉语拼音', { pattern: 'final' }) // 'àn ǔ īn īn'

// 获取音调
pinyin('汉语拼音', { pattern: 'num' }) // '4 3 1 1'

获取不带声调的拼音

pinyin('汉语拼音', { tone: false }) // 'han yu pin yin'

结果输出为数组格式

pinyin('汉语拼音', { type: 'array' }) // [ 'hàn', 'yǔ', 'pīn', 'yīn' ]

获取单个字的多音

pinyin('好', { multitone: true }) // 'hǎo hào'

混用

pinyin('汉语拼音', { type: 'array', pattern: 'pinyinNum' }) // [ 'han4', 'yu3', 'pin1', 'yin1' ]

options 配置

参数说明类型可选值默认值
pattern输出的结果的信息(带音调全拼/音调为数字后缀的全拼/声母/韵母/音调)stringpinyin/pinyinNum/initial/final/numpinyin
tone是否开启音调(为 true 时会覆盖 pattern 中的音调)booleantrue/falsetrue
type输出结果类型(字符串/数组)stringstring/arraystring
multitone输出多音字全部拼音(仅在词 word 长度为 1 时生效)booleantrue/falsefalse

交流与反馈

有问题或者功能需求支持欢迎提 issue,紧急可联系微信:zhoulx1688888

Keywords

FAQs

Package last updated on 31 Oct 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc