1.0.1 • Published 6 years ago

simplified-chinese v1.0.1

Weekly downloads
4
License
MIT
Repository
github
Last release
6 years ago

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.

ArgumentsTypeRequiredDefaultDescription
wordsstringtrue-A string of chinese words
options.separatorstringfalse''The separator to join the pinyin of words
options.capitalizeFirstLetterbooleanfalsetruewhether to capitalize the first letter of every word's pinyin
options.escapeTextstringfalse-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.

ArgumentsTypeRequiredDefaultDescription
wordsstringtrue-A string of chinese words
options.separatorstringfalse''The separator to join the first letters
options.uppercasebooleanfalsetrueWhether to capitalize the letters

LICENSE

MIT