Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zollero/simplified-chinese
πA utility library of simplified chinese and pinyin.
https://github.com/zollero/simplified-chinese
chinese pinyin simplified-chinese util
Last synced: about 1 month ago
JSON representation
πA utility library of simplified chinese and pinyin.
- Host: GitHub
- URL: https://github.com/zollero/simplified-chinese
- Owner: zollero
- License: mit
- Created: 2018-07-26T02:57:30.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-08-08T13:13:06.000Z (over 6 years ago)
- Last Synced: 2024-09-14T21:58:15.714Z (2 months ago)
- Topics: chinese, pinyin, simplified-chinese, util
- Language: TypeScript
- Homepage:
- Size: 161 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# simplified-chinese
![npm](https://img.shields.io/npm/v/simplified-chinese.svg)
![npm bundle size (minified)](https://img.shields.io/bundlephobia/min/simplified-chinese.svg)
![npm bundle size (minified + gzip)](https://img.shields.io/bundlephobia/minzip/simplified-chinese.svg)
![npm](https://img.shields.io/npm/dw/simplified-chinese.svg?style=popout)
![npm](https://img.shields.io/npm/dm/simplified-chinese.svg?style=popout)
![npm](https://img.shields.io/npm/l/simplified-chinese.svg)> A tool to do something with simplified chinese and pinyin.
[![NPM](https://nodei.co/npm/simplified-chinese.png)](https://nodei.co/npm/simplified-chinese/)
## 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: MoLiHuaconst 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-Huaconst 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 [email protected]: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