siakhooi/ts-number-to-chinese-words

View on GitHub
README.md

Summary

Maintainability
Test Coverage
# number-to-chinese-words

- npm package to translate number to chinese words

![License](https://img.shields.io/github/license/siakhooi/ts-number-to-chinese-words?logo=github)
[![Code Style](https://img.shields.io/badge/code%20style-google-blueviolet.svg)](https://github.com/google/gts)
![GitHub last commit](https://img.shields.io/github/last-commit/siakhooi/ts-number-to-chinese-words?logo=github)
![GitHub tag (latest by date)](https://img.shields.io/github/v/tag/siakhooi/ts-number-to-chinese-words?logo=github)
![GitHub issues](https://img.shields.io/github/issues/siakhooi/ts-number-to-chinese-words?logo=github)
![GitHub closed issues](https://img.shields.io/github/issues-closed/siakhooi/ts-number-to-chinese-words?logo=github)
![GitHub pull requests](https://img.shields.io/github/issues-pr-raw/siakhooi/ts-number-to-chinese-words?logo=github)
![GitHub closed pull requests](https://img.shields.io/github/issues-pr-closed-raw/siakhooi/ts-number-to-chinese-words?logo=github)
![GitHub top language](https://img.shields.io/github/languages/top/siakhooi/ts-number-to-chinese-words?logo=github)

![Release](https://img.shields.io/badge/Release-npm-purple)
![npm](https://img.shields.io/npm/v/@siakhooi/number-to-chinese-words?color=0e7fc0&label=NPM%20release&logo=npm)
![npm](https://img.shields.io/npm/dt/@siakhooi/number-to-chinese-words?logo=npm)
![npm type definitions](https://img.shields.io/npm/types/@siakhooi/number-to-chinese-words?logo=npm)

![Quality-CodeClimate](https://img.shields.io/badge/Quality-CodeClimate-purple)
[![Maintainability](https://api.codeclimate.com/v1/badges/3378c5776a49c26b8362/maintainability)](https://codeclimate.com/github/siakhooi/ts-number-to-chinese-words/maintainability)
![Code Climate maintainability](https://img.shields.io/codeclimate/maintainability-percentage/siakhooi/ts-number-to-chinese-words)
![Code Climate issues](https://img.shields.io/codeclimate/issues/siakhooi/ts-number-to-chinese-words)
![Code Climate technical debt](https://img.shields.io/codeclimate/tech-debt/siakhooi/ts-number-to-chinese-words)
[![Test Coverage](https://api.codeclimate.com/v1/badges/3378c5776a49c26b8362/test_coverage)](https://codeclimate.com/github/siakhooi/ts-number-to-chinese-words/test_coverage)

![Quality-Sonar](https://img.shields.io/badge/Quality-SonarCloud-purple)
[![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=siakhooi_ts-number-to-chinese-words&metric=code_smells)](https://sonarcloud.io/summary/new_code?id=siakhooi_ts-number-to-chinese-words)
[![Duplicated Lines (%)](https://sonarcloud.io/api/project_badges/measure?project=siakhooi_ts-number-to-chinese-words&metric=duplicated_lines_density)](https://sonarcloud.io/summary/new_code?id=siakhooi_ts-number-to-chinese-words)
[![Bugs](https://sonarcloud.io/api/project_badges/measure?project=siakhooi_ts-number-to-chinese-words&metric=bugs)](https://sonarcloud.io/summary/new_code?id=siakhooi_ts-number-to-chinese-words)
[![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=siakhooi_ts-number-to-chinese-words&metric=vulnerabilities)](https://sonarcloud.io/summary/new_code?id=siakhooi_ts-number-to-chinese-words)
[![Technical Debt](https://sonarcloud.io/api/project_badges/measure?project=siakhooi_ts-number-to-chinese-words&metric=sqale_index)](https://sonarcloud.io/summary/new_code?id=siakhooi_ts-number-to-chinese-words)
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=siakhooi_ts-number-to-chinese-words&metric=sqale_rating)](https://sonarcloud.io/summary/new_code?id=siakhooi_ts-number-to-chinese-words)
[![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=siakhooi_ts-number-to-chinese-words&metric=security_rating)](https://sonarcloud.io/summary/new_code?id=siakhooi_ts-number-to-chinese-words)
[![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=siakhooi_ts-number-to-chinese-words&metric=reliability_rating)](https://sonarcloud.io/summary/new_code?id=siakhooi_ts-number-to-chinese-words)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=siakhooi_ts-number-to-chinese-words&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=siakhooi_ts-number-to-chinese-words)

[![Generic badge](https://img.shields.io/badge/Funding-BuyMeACoffee-33cb56.svg)](https://www.buymeacoffee.com/siakhooi)
[![Generic badge](https://img.shields.io/badge/Funding-Ko%20Fi-33cb56.svg)](https://ko-fi.com/siakhooi)
![count](https://hit-tztugwlsja-uc.a.run.app/?outputtype=badge&counter=ghmd-ts-number-to-chinese-words)

## Features

- Translate numbers into Chinese characters for:
  - Integer -9007,1992,5474,0991 to +9007,1992,5474,0991 (`Number.MAX_SAFE_INTEGER`)
  - support decimal points
  - Simplified Chinese or Traditional Chinese (`options: {useTraditional: true}`)
  - optionally display `正` for positive numbers. (`options:{displayPositive: true}`)
  - optionally use capital (大写). (`options: {useCapital: true}`)
  - optionally remove leading one. (`options: {removeLeadingOne: true}`)
  - optionally use contractions (`廿卅卌圩圆进枯桦皕`)
  - optionally use traditional units for floating numbers.(`分厘毫秒忽微纤沙尘埃渺漠`)

## Locations

### Demo

- <https://siakhooi.github.io/ts-number-to-chinese-words/>

### Source Code

- <https://github.com/siakhooi/ts-number-to-chinese-words>

### Distributions

- <https://www.npmjs.com/package/@siakhooi/number-to-chinese-words>
- <https://github.com/siakhooi/ts-number-to-chinese-words/pkgs/npm/number-to-chinese-words>

### Quality

- <https://sonarcloud.io/project/overview?id=siakhooi_ts-number-to-chinese-words>
- <https://codeclimate.com/github/siakhooi/ts-number-to-chinese-words>
- <https://coveralls.io/github/siakhooi/ts-number-to-chinese-words>
- <https://app.codecov.io/gh/siakhooi/ts-number-to-chinese-words>
- <https://app.codacy.com/gh/siakhooi/ts-number-to-chinese-words>
- <https://www.codefactor.io/repository/github/siakhooi/ts-number-to-chinese-words>
- <https://app.snyk.io/org/siakhooi/projects>
- <https://lgtm.com/people/siakhooi/project:1515605457625>
- <https://scan.coverity.com/projects/siakhooi-ts-number-to-chinese-words?tab=overview>

## Options and Default values

```javascript
options: {
  useTraditional: false;
  displayPositive: false;
  useCapital: false;
  removeLeadingOne: false;
  useContractionAll: false;
  useContraction20: false;
  useContraction30: false;
  useContraction40: false;
  useContraction50: false;
  useContraction60: false;
  useContraction70: false;
  useContraction80: false;
  useContraction90: false;
  useContraction200: false;
  useTraditionalFloatingUnit: false;
}
```

## Usage

```javascript
const NumberToChinese = require('@siakhooi/number-to-chinese-words');
console.log(NumberToChinese.convertNumber(7));

const NumberToChinese = require('@siakhooi/number-to-chinese-words');
console.log(NumberToChinese.convertNumber(7, {useTraditional: true}));

const NumberToChinese = require('@siakhooi/number-to-chinese-words');
console.log(NumberToChinese.convertNumber(7, {displayPositive: true}));

const NumberToChinese = require('@siakhooi/number-to-chinese-words');
console.log(NumberToChinese.convertNumber(7, {useCapital: true}));

const NumberToChinese = require('@siakhooi/number-to-chinese-words');
console.log(NumberToChinese.convertNumber(17, {removeLeadingOne: true}));

const NumberToChinese = require('@siakhooi/number-to-chinese-words');
console.log(NumberToChinese.convertNumber(70, {useContraction70: true}));
```

### Example

#### Simplified and Traditional

|           number | Simplified                                             | Traditional                                            |
| ---------------: | ------------------------------------------------------ | ------------------------------------------------------ |
|                0 | 零                                                     | 零                                                     |
|               17 | 一十七                                                 | 一十七                                                 |
|              999 | 九百九十九                                             | 九百九十九                                             |
|             9999 | 九千九百九十九                                         | 九千九百九十九                                         |
|            10101 | 一万零一百零一                                         | 一萬零一百零一                                         |
|           100001 | 一十万零一                                             | 一十萬零一                                             |
|          3004500 | 三百万四千五百                                         | 三百萬四千五百                                         |
|         10000001 | 一千万零一                                             | 一千萬零一                                             |
|         43033039 | 四千三百零三万三千零三十九                             | 四千三百零三萬三千零三十九                             |
|         12345678 | 一千二百三十四万五千六百七十八                         | 一千二百三十四萬五千六百七十八                         |
|        100000000 | 一亿                                                   | 一億                                                   |
|       1010101010 | 一十亿一千零一十万一千零一十                           | 一十億一千零一十萬一千零一十                           |
|      10101010101 | 一百零一亿零一百零一万零一百零一                       | 一百零一億零一百零一萬零一百零一                       |
|     999999999999 | 九千九百九十九亿九千九百九十九万九千九百九十九         | 九千九百九十九億九千九百九十九萬九千九百九十九         |
| 9007199254740991 | 九千零七兆一千九百九十二亿五千四百七十四万零九百九十一 | 九千零七兆一千九百九十二億五千四百七十四萬零九百九十一 |

#### display positive

| number | `displayPositive=true` | `displayPositive=false` |
| -----: | ---------------------- | ----------------------- |
|    -17 | 负一十七               | 负一十七                |
|     17 | 正一十七               | 一十七                  |

#### capital

| number | `useCapital=true` | `useCapital=true,useTraditional=true` |
| -----: | ----------------- | ------------------------------------- |
|   -107 | 负壹佰零柒        | 負壹佰零柒                            |
|   2345 | 贰仟叁佰肆拾伍    | 貳仟參佰肆拾伍                        |

#### remove Leading One

|      number | Simplified                     | Traditional                    |
| ----------: | ------------------------------ | ------------------------------ |
|          17 | 十七                           | 十七                           |
|       10101 | 万零一百零一                   | 萬零一百零一                   |
|      100001 | 十万零一                       | 十萬零一                       |
|    10000001 | 千万零一                       | 千萬零一                       |
|    12345678 | 千二百三十四万五千六百七十八   | 千二百三十四萬五千六百七十八   |
|   100000000 | 亿                             | 億                             |
|  1010101010 | 十亿一千零一十万一千零一十     | 十億一千零一十萬一千零一十     |
| 10101010101 | 百零一亿零一百零一万零一百零一 | 百零一億零一百零一萬零一百零一 |

#### Decimal Points

|          number | Simplified                     | Traditional                    |
| --------------: | ------------------------------ | ------------------------------ |
|           12.13 | 一十二点一三                   | 一十二點一三                   |
| 10.123456789012 | 一十点一二三四五六七八九零一二 | 一十點一二三四五六七八九零一二 |

#### Contraction

| number | Simplified | Traditional |
| -----: | ---------- | ----------- |
|     20 | 廿         | 廿          |
|     30 | 卅         | 卅          |
|     40 | 卌         | 卌          |
|     50 | 圩         | 圩          |
|     60 | 圆         | 圓          |
|     70 | 进         | 進          |
|     80 | 枯         | 枯          |
|     90 | 桦         | 樺          |
|    200 | 皕         | 皕          |

#### Traditional Floating Unit

|         number | Simplified                                       | Traditional                                      |
| -------------: | ------------------------------------------------ | ------------------------------------------------ |
|          12.13 | 一十二又一分三厘                                 | 一十二又一分三釐                                 |
| 0.123456789123 | 一分二厘三毫四秒五忽六微七纤八沙九尘一埃二渺三漠 | 一分二釐三毫四秒五忽六微七纖八沙九塵一埃二渺三漠 |

## Other Badges

![GitHub language count](https://img.shields.io/github/languages/count/siakhooi/ts-number-to-chinese-words?logo=github)
![Lines of code](https://img.shields.io/tokei/lines/github/siakhooi/ts-number-to-chinese-words?logo=github)
![GitHub repo size](https://img.shields.io/github/repo-size/siakhooi/ts-number-to-chinese-words?logo=github)
![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/siakhooi/ts-number-to-chinese-words?logo=github)
![Workflow](https://img.shields.io/badge/Workflow-github-purple)
![workflow](https://github.com/siakhooi/ts-number-to-chinese-words/actions/workflows/workflow-build-with-quality-checks.yml/badge.svg)
![workflow](https://github.com/siakhooi/ts-number-to-chinese-words/actions/workflows/workflow-deployments.yml/badge.svg)
![Release](https://img.shields.io/badge/Release-github-purple)
![GitHub release (latest by date)](https://img.shields.io/github/v/release/siakhooi/ts-number-to-chinese-words?label=GPR%20release&logo=github)
![GitHub all releases](https://img.shields.io/github/downloads/siakhooi/ts-number-to-chinese-words/total?color=33cb56&logo=github)
![GitHub Release Date](https://img.shields.io/github/release-date/siakhooi/ts-number-to-chinese-words?logo=github)
![Quality-npms.io](https://img.shields.io/badge/Quality-npms.io-purple)
![npms.io (final)](https://img.shields.io/npms-io/final-score/@siakhooi/number-to-chinese-words?logo=npm)
![npms.io (final)](https://img.shields.io/npms-io/maintenance-score/@siakhooi/number-to-chinese-words?logo=npm)
![npms.io (final)](https://img.shields.io/npms-io/quality-score/@siakhooi/number-to-chinese-words?logo=npm)
![npms.io (final)](https://img.shields.io/npms-io/popularity-score/@siakhooi/number-to-chinese-words?logo=npm)
![Quality-Sonar](https://img.shields.io/badge/Quality-SonarCloud-purple)
[![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=siakhooi_ts-number-to-chinese-words&metric=ncloc)](https://sonarcloud.io/summary/new_code?id=siakhooi_ts-number-to-chinese-words)
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=siakhooi_ts-number-to-chinese-words&metric=coverage)](https://sonarcloud.io/summary/new_code?id=siakhooi_ts-number-to-chinese-words)
![Sonar Violations (short format)](https://img.shields.io/sonar/violations/siakhooi_ts-number-to-chinese-words?server=https%3A%2F%2Fsonarcloud.io)
![Sonar Violations (short format)](https://img.shields.io/sonar/blocker_violations/siakhooi_ts-number-to-chinese-words?server=https%3A%2F%2Fsonarcloud.io)
![Sonar Violations (short format)](https://img.shields.io/sonar/critical_violations/siakhooi_ts-number-to-chinese-words?server=https%3A%2F%2Fsonarcloud.io)
![Sonar Violations (short format)](https://img.shields.io/sonar/major_violations/siakhooi_ts-number-to-chinese-words?server=https%3A%2F%2Fsonarcloud.io)
![Sonar Violations (short format)](https://img.shields.io/sonar/minor_violations/siakhooi_ts-number-to-chinese-words?server=https%3A%2F%2Fsonarcloud.io)
![Sonar Violations (short format)](https://img.shields.io/sonar/info_violations/siakhooi_ts-number-to-chinese-words?server=https%3A%2F%2Fsonarcloud.io)
![Sonar Violations (long format)](https://img.shields.io/sonar/violations/siakhooi_ts-number-to-chinese-words?format=long&server=http%3A%2F%2Fsonarcloud.io)
![Quality-Coveralls](https://img.shields.io/badge/Quality-Coveralls-purple)
[![Coverage Status](https://coveralls.io/repos/github/siakhooi/ts-number-to-chinese-words/badge.svg?branch=main)](https://coveralls.io/github/siakhooi/ts-number-to-chinese-words?branch=main)
![Quality-Codecov](https://img.shields.io/badge/Quality-Codecov-purple)
![Codecov](https://img.shields.io/codecov/c/github/siakhooi/ts-number-to-chinese-words?logo=codecov)
![Quality-Codacy](https://img.shields.io/badge/Quality-Codacy-purple)
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/b3f6b7b122b44e6f8f43833c05a70a71)](https://www.codacy.com/gh/siakhooi/ts-number-to-chinese-words/dashboard?utm_source=github.com&utm_medium=referral&utm_content=siakhooi/ts-number-to-chinese-words&utm_campaign=Badge_Grade)
[![Codacy Badge](https://app.codacy.com/project/badge/Coverage/b3f6b7b122b44e6f8f43833c05a70a71)](https://www.codacy.com/gh/siakhooi/ts-number-to-chinese-words/dashboard?utm_source=github.com&utm_medium=referral&utm_content=siakhooi/ts-number-to-chinese-words&utm_campaign=Badge_Coverage)
![Quality-CodeFactor](https://img.shields.io/badge/Quality-CodeFactor-purple)
[![CodeFactor](https://www.codefactor.io/repository/github/siakhooi/ts-number-to-chinese-words/badge)](https://www.codefactor.io/repository/github/siakhooi/ts-number-to-chinese-words)
![Quality-Snyk](https://img.shields.io/badge/Quality-Snyk-purple)
![Snyk Vulnerabilities for GitHub Repo](https://img.shields.io/snyk/vulnerabilities/github/siakhooi/ts-number-to-chinese-words)
![Snyk Vulnerabilities for npm package](https://img.shields.io/snyk/vulnerabilities/npm/@siakhooi/number-to-chinese-words)
![Quality-LGTM](https://img.shields.io/badge/Quality-LGTM-purple)
![LGTM Alerts](https://img.shields.io/lgtm/alerts/github/siakhooi/ts-number-to-chinese-words)
![LGTM Grade](https://img.shields.io/lgtm/grade/javascript/github/siakhooi/ts-number-to-chinese-words)
![Quality-Coverity](https://img.shields.io/badge/Quality-Coverity-purple)
![Coverity Scan](https://img.shields.io/coverity/scan/siakhooi-ts-number-to-chinese-words)