New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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.2.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
34K
increased by4.93%
Maintainers
1
Weekly downloads
 
Created
Source

pinyin-pro 中文转换拼音库(支持获取汉字、词语、句子的拼音、音调、声母、韵母多种形式)

中文转换拼音库,支持获取汉字、词语、句子等多种内容的拼音、音调、声母、韵母等。通过高效的算法和丰富的字词库,保证体积轻量的同时识别准确率很高。

安装

npm 安装

npm install pinyin-pro

yarn 安装

yarn add pinyin-pro

使用

浏览器端:

import { pinyin } from 'pinyin-pro';

node 端:

const { pinyin } = require('pinyin-pro');

参数

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

  • word:必填。String 类型,需要转化为拼音的中文
  • options:可选。Object 类型,用于配置各种输出形式,相关配置在后面有所介绍

基本用法

import { pinyin } from 'pinyin-pro'; // 若为node环境请用require形式引入

// 获取带音调拼音
pinyin('汉语拼音'); // 'hàn yǔ pīn yīn'
// 获取不带声调的拼音
pinyin('汉语拼音', { tone: false }); // 'han yu pin yin'
// 获取声调转换为数字后缀的拼音
pinyin('汉语拼音', { pattern: 'pinyinNum' }); // 'han4 yu3 pin1 yin1'
// 获取声母
pinyin('汉语拼音', { pattern: 'initial' }); // 'h y p y'
// 获取带音调韵母
pinyin('汉语拼音', { pattern: 'final' }); // 'àn ǔ īn īn'
// 获取不带音调韵母
pinyin('汉语拼音', { pattern: 'final', tone: false }); // 'an u in in'
// 获取音调
pinyin('汉语拼音', { pattern: 'num' }); // '4 3 1 1'

结果输出为数组格式

通过在 options 参数中加入type: 'array',可以以数组形式输出基本用法中的示例:

// 获取带音调拼音
pinyin('汉语拼音', { type: 'array' }); // ["hàn", "yǔ", "pīn", "yīn"]
// 获取不带声调的拼音
pinyin('汉语拼音', { tone: false, type: 'array' }); // ["han", "yu", "pin", "yin"]
// 获取声调转换为数字后缀的拼音
pinyin('汉语拼音', { pattern: 'pinyinNum', type: 'array' }); // ["han4", "yu3", "pin1", "yin1"]
// 获取声母
pinyin('汉语拼音', { pattern: 'initial', type: 'array' }); // ["h", "y", "p", "y"]
// 获取带音调韵母
pinyin('汉语拼音', { pattern: 'final', type: 'array' }); // ["àn", "ǔ", "īn", "īn"]
// 获取不带音调韵母
pinyin('汉语拼音', { pattern: 'final', tone: false, type: 'array' }); // ["an", "u", "in", "in"]
// 获取音调
pinyin('汉语拼音', { pattern: 'num', type: 'array' }); // ["4", "3", "1", "1"]

获取单个字的多音

只有单字可以获取到多音模式, 词语、句子无效。同样可以通过配置 options 选项获取数组形式、韵母等格式

pinyin('好', { multiple: true }); // 'hǎo hào'
pinyin('好', { multiple: true, type: 'array' }); // ["hǎo", "hào"]

options 配置

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

交流与反馈

有问题或者功能需求支持欢迎提 issue

Keywords

FAQs

Package last updated on 26 Dec 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