I used js to create a package for converting Chinese to Pinyin. The warehouse address can be seen: pinyin-pro Features
Installnpm installation npm install pinyin-pro Yarn Installation yarn add pinyin-pro IntroductionBrowser script introduction: <!--Introduce a version, such as version 3.2.0--> <!-- <script src="https://cdn.jsdelivr.net/gh/zh-lx/[email protected]/dist/pinyin-pro.js"></script> --> <!--Introduce the latest version--> <script src="https://cdn.jsdelivr.net/gh/zh-lx/pinyin-pro@latest/dist/pinyin-pro.js"></script> <script> var { pinyin } = pinyinPro; pinyin('Hanyu Pinyin'); // 'hàn yǔ pīn yīn' </script> ESModule import: import { pinyin } from 'pinyin-pro'; pinyin('Hanyu Pinyin'); // 'hàn yǔ pīn yīn' Commonjs is introduced: const { pinyin } = require('pinyin-pro'); pinyin('Hanyu Pinyin'); // 'hàn yǔ pīn yīn' parameterpinyin(word, options) accepts two parameters word: required. String type, needs to be converted to Chinese pinyin
Usage ExamplesGet Pinyin import { pinyin } from 'pinyin-pro'; // Get the pinyin with tones pinyin('Hanyu Pinyin'); // 'hàn yǔ pīn yīn' // Get pinyin without tone pinyin('Hanyu Pinyin', { toneType: 'none' }); // 'han yu pin yin' // Get the pinyin converted to a numeric suffix pinyin('Hanyu Pinyin', { toneType: 'num' }); // 'han4 yu3 pin1 yin1' // Get the pinyin with tones in array form pinyin('Hanyu Pinyin', { type: 'array' }); // ["hàn", "yǔ", "pīn", "yīn"] // Get the pinyin without tone in array form pinyin('汉拼音', { toneType: 'none', type: 'array' }); // ["han", "yu", "pin", "yin"] // Get the array form of tone converted to numeric suffix pinyin('Hanyu Pinyin', { toneType: 'num', type: 'array' }); // ["han4", "yu3", "pin1", "yin1"] Get initial consonants import { pinyin } from 'pinyin-pro'; // Get the initial consonant pinyin('Hanyu Pinyin', { pattern: 'initial' }); // 'hypy' // Get the initial consonants in array form pinyin('Hanyu Pinyin', { pattern: 'initial', type: 'array' }); // ["h", "y", "p", "y"] Get the finals import { pinyin } from 'pinyin-pro'; // Get the finals with tones pinyin('Hanyu Pinyin', { pattern: 'final' }); // 'àn ǔ īn īn' // Get the finals without tone pinyin('Hanyu Pinyin', { pattern: 'final', toneType: 'none' }); // 'an u in in' // Get the final vowels with numeral tones pinyin('Hanyu Pinyin', { pattern: 'final', toneType: 'num' }); // 'an4 u3 in1 in1' // Get the array of tones and finals pinyin('Hanyu Pinyin', { pattern: 'final', type: 'array' }); // ["àn", "ǔ", "īn", "īn"] // Get the array of finals without tones pinyin('Hanyu Pinyin', { pattern: 'final', toneType: 'none', type: 'array' }); // ["an", "u", "in", "in"] // Get the finals of Chinese Pinyin in array format with tones as numbers pinyin('Hanyu Pinyin', { pattern: 'final', toneType: 'num', type: 'array' }); // ['an4', 'u3', 'in1', 'in1'] Get the Tone import { pinyin } from 'pinyin-pro'; // Get the tone pinyin('Hanyu Pinyin', { pattern: 'num' }); // '4 3 1 1' // Get the tones in array form pinyin('Hanyu Pinyin', { pattern: 'num', type: 'array' }); // ["4", "3", "1", "1"] Get the first letter of Pinyin import { pinyin } from 'pinyin-pro'; // Get the first letter of pinyin pinyin('赵钱孙李额', { pattern: 'first' }); // 'zqsl é' // Get the first letter of pinyin without tone pinyin('赵钱孙李额', { pattern: 'first', toneType: 'none' }); // 'zqsle' // Get the first letters of pinyin in array form pinyin('赵钱孙李额', { pattern: 'first', type: 'array' }); // ['z', 'q', 's', 'l', 'é'] // Get the first letters of pinyin without tone in array form pinyin('赵钱孙李额', { pattern: 'first', toneType: 'none', type: 'array' }); // ['z', 'q', 's', 'l', 'e'] Get multiple pronunciations of a single word Only single words can obtain polyphonic mode, words and sentences are invalid. You can also configure options to get the array form, finals and other formats import { pinyin } from 'pinyin-pro'; // Get multiple pinyin('好', { multiple: true }); // 'hǎo hào' // Get multiple sounds in array form pinyin('好', { multiple: true, type: 'array' }); // ["hǎo", "hào"] SummarizeThis is the end of this article about how to convert Chinese to Pinyin using js. For more information about how to convert Chinese to Pinyin using js, please search previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: How to enable the slow query log function in MySQL
>>: CentOS 7.5 deploys Varnish cache server function
This article example shares the specific code of ...
ContentsHyperledger fabric1.4 environment setup u...
Overview Today we will mainly share how to config...
Table of contents 1. The concept of process and t...
Today, my colleague encountered a very strange pr...
environment: MAC_OS 10.12 Python 3.6 mysql 5.7.25...
The telnet in the Alpine image has been moved to ...
This article shares the specific code of JavaScri...
This article will use Docker containers (orchestr...
Table of contents background Compile glibc 2.14 M...
Pop-up windows are often used in actual developme...
Table of contents 1. Ubuntu source change 2. Inst...
background Today, while cooperating with other pr...
1) Process 2) FSImage and Edits Nodenode is the b...
1. Today, when I was making a page, I encountered ...