A tool to do something with simplified chinese and pinyin.
npm i --save simplified-chinese
import { convert2Pinyin, getFirstLetters } from 'simplified-chinese';
const pinyin = convert2Pinyin('่่่ฑ');
console.log('The pinyin of ่่่ฑ is: ', pinyin);
// The pinyin of ่่่ฑ is: MoLiHua
const firstLetters = getFirstLetters('ๅฅฝไธๆต็พไธฝ็่่่ฑ');
console.log('The first letters of ๅฅฝไธๆต็พไธฝ็่่่ฑ is: ', firstLetters);
// The first letters of ๅฅฝไธๆต็พไธฝ็่่่ฑ is: HYDMLDMLH
Or you can custorm the value of convert2Pinyin
and getFirstLetters
:
import { convert2Pinyin, getFirstLetters } from 'simplified-chinese';
const pinyin = convert2Pinyin('่่่ฑ', { separator: '-' });
console.log('The pinyin of ่่่ฑ is: ', pinyin);
// The pinyin of ่่่ฑ is: Mo-Li-Hua
const firstLetters = getFirstLetters('ๅฅฝไธๆต็พไธฝ็่่่ฑ', { separator: '>'});
console.log('The first letters of ๅฅฝไธๆต็พไธฝ็่่่ฑ is: ', firstLetters);
// The first letters of ๅฅฝไธๆต็พไธฝ็่่่ฑ is: H>Y>D>M>L>D>M>L>H
> git clone git@github.com:zollero/simplified-chinese.git
> cd simplified-chinese
> npm i
> npm run test
import { convert2Pinyin, getFirstLetters } from 'simplified-chinese';
Return pinyin of the chinese words using the given words
and options
. The words
is a string of chinese words, and the options can cunstorm the return value.
Arguments | Type | Required | Default | Description |
---|---|---|---|---|
words | string | true | - | A string of chinese words |
options.separator | string | false | '' | The separator to join the pinyin of words |
options.capitalizeFirstLetter | boolean | false | true | whether to capitalize the first letter of every word's pinyin |
options.escapeText | string | false | - | Replace with this text of which is not chinese |
Return the first letter of every word of words
and options
. The words
is a string of chinese words, and the options can cunstorm the return value.
Arguments | Type | Required | Default | Description |
---|---|---|---|---|
words | string | true | - | A string of chinese words |
options.separator | string | false | '' | The separator to join the first letters |
options.uppercase | boolean | false | true | Whether to capitalize the letters |
MIT