https://github.com/r48n34/chinese-commercial-code-convertor
Simple Typescript code for convert Chinese Commercial Code.
https://github.com/r48n34/chinese-commercial-code-convertor
ccc npm
Last synced: 5 months ago
JSON representation
Simple Typescript code for convert Chinese Commercial Code.
- Host: GitHub
- URL: https://github.com/r48n34/chinese-commercial-code-convertor
- Owner: r48n34
- License: mit
- Created: 2025-02-13T09:02:36.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2026-02-13T10:13:45.000Z (5 months ago)
- Last Synced: 2026-02-13T19:13:43.248Z (5 months ago)
- Topics: ccc, npm
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/chinese-commercial-code-convertor
- Size: 361 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# π‘ Chinese Commercial Code Convertor
Simple Typescript code for convert Chinese Commercial Code.
- πͺπΌ Support both `CN` and `TW` standard
- πΌ Zero dependency
- π Tested works on `Node.js`, `React` and other web applications
## π» Install
```bash
npm i chinese-commercial-code-convertor
yarn add chinese-commercial-code-convertor
```
## π οΈ Usage
```ts
import { numberToCode, codeToNumber } from "chinese-commercial-code-convertor"
// Convert Number To Chinese Code
console.log(numberToCode(1234)); // "ε§Ή"
console.log(numberToCode(36, {lang: "tw"})); // "δΉ
", Will auto convert 36 to 0036
console.log(numberToCode("0155")); // "δ½"
console.log(numberToCode("0123 0123 0155")); // "δΌδΌδ½"
console.log(numberToCode(["0144", "0155"])); // δ½δ½"
console.log(numberToCode([144, 155])); // δ½δ½"
// Convert Chinese Code To Number
console.log(codeToNumber("ε§Ή")) // "1234"
console.log(codeToNumber("δ½δ½")) // "0144 0155"
console.log(codeToNumber(["δ½", "δ½"])) // "0144 0155"
console.log(codeToNumber(["δ½", "ε", "δ½"])) // "0144 -1 0155"
```
## Utils
### `numberToCode()`
Convert your number input to chinese string.
```ts
numberToCode(
input: string | number | number[] | string[],
inputOptions?: Options,
): string
```
### `codeToNumber()`
Convert your chinese string input to number string.
```ts
codeToNumber(
input: string | string[],
inputOptions?: Options,
): string
```
### Options
The Option input is a object which included the following items:
```ts
interface Options {
// Default: "tw"
lang?: "tw" | "cn";
// Default at numberToCode: ""
// Default at codeToNumber: "-1"
notFoundReturn?: string;
}
```
#### `lang`
The lang is refer to which `Chinese Commercial Code` standard you prefer to return.
- tw: Taiwan - ε°η£ζ¨ζΊι»ε ±η’Ό
- cn: China - ε€§ιζ εη΅ζ₯η
- Default: `"tw"`
`Code Samples`
```ts
numberToCode(1234, { lang: "cn" }) // "ε§Ή"
codeToNumber("ε₯", { lang: "cn" }) // "8134"
```
#### `notFoundReturn`
If you target code is not found in the list, the `notFoundReturn` string will be the return string. You can input your own `notFoundReturn`.
- Default at numberToCode: `""`
- Default at codeToNumber: `"-1"`
`Code Samples`
```ts
numberToCode("8260", { notFoundReturn: "*" }) // *
codeToNumber("δ½εδ½", { notFoundReturn: "?" }) // "0144 ? 0155"
```
## π» Dev logs
### - 1.1.0
1. Allow `codeToNumber()` to input split string.
### - 1.0.0
1. Project init
## π License
MIT License
## π References
https://www.njstar.com/cms/chinese-commercial-telegraph-code-lookup