Skip to content

๐ŸŽA utility library of simplified chinese and pinyin.

License

Notifications You must be signed in to change notification settings

zollero/simplified-chinese

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

39 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

simplified-chinese

npm npm bundle size (minified) npm bundle size (minified + gzip) npm npm npm

A tool to do something with simplified chinese and pinyin.

NPM

Installation

npm i --save simplified-chinese

Getting Started

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

Test

> git clone git@github.com:zollero/simplified-chinese.git
> cd simplified-chinese
> npm i
> npm run test

Docs

import { convert2Pinyin, getFirstLetters } from 'simplified-chinese';

convert2Pinyin(words, options)

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

getFirstLetters(words, options)

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

LICENSE

MIT

About

๐ŸŽA utility library of simplified chinese and pinyin.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published