Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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.

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: 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 [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