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
Today we analyzed another typical problem about d...
This article introduces and shares the responsive...
Table of contents 1. Overview 2. Parameters for c...
Method 1: Use Google advanced search, for example...
Maybe you are using include files here, which is u...
Table of contents Preface 1. Installation 1. Down...
The PHP base image used in this article is: php:7...
As shown in the figure: Check port usage: sudo ne...
This article example shares the specific code of ...
Adding the rel="nofollow" attribute to ...
I have encountered the problem that MySQL can con...
Recently, I received a requirement for function ex...
What is vuex vuex: is a state manager developed s...
Table of contents What is MySQL NDB Cluster Preli...
Why do I want to organize the content in this area...