New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

cn-number

Package Overview
Dependencies
Maintainers
0
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cn-number - npm Package Compare versions

Comparing version 0.0.1 to 1.0.0

README_CN.md

4

build.ts

@@ -6,3 +6,5 @@ import dts from 'bun-plugin-dts'

outdir: "./dist",
plugins: [dts()],
plugins: [dts({
output: { noBanner: true },
})],
minify: true,

@@ -9,0 +11,0 @@ target: "browser",

@@ -1,7 +0,5 @@

// Generated by dts-bundle-generator v9.5.1
export interface CnNumOptions {
traditional: boolean;
capital: boolean;
liang: number;
traditional: boolean
capital: boolean
liang: number
}

@@ -17,17 +15,17 @@ export declare enum UseLiang {

}
export declare const DigitCN: Map<number, string>;
export declare const DigitTraditionalCN: Map<number, string>;
export declare const DigitCapitalCN: Map<number, string>;
export declare const DigitCapitalTraditionalCN: Map<number, string>;
export declare const SerialDigitCN: Map<number, string>;
export declare function notNegToDigits(n: number): number[];
export declare const DigitCN: Map<number, string>
export declare const DigitTraditionalCN: Map<number, string>
export declare const DigitCapitalCN: Map<number, string>
export declare const DigitCapitalTraditionalCN: Map<number, string>
export declare const SerialDigitCN: Map<number, string>
export declare function notNegToDigits(n: number): number[]
export declare function intToDigits(n: number): {
neg: boolean;
digits: number[];
};
neg: boolean
digits: number[]
}
export declare function newCnNumConvertor(opt?: Partial<CnNumOptions> & {
absLessThan?: number;
}): (n: number) => string;
export declare function newCnSerialNumConvertor(opt?: Partial<CnNumOptions>): (n: number) => string;
absLessThan?: number
}): (n: number) => string
export declare function newCnSerialNumConvertor(opt?: Partial<CnNumOptions>): (n: number) => string
export {};
export { }
{
"name": "cn-number",
"version": "0.0.1",
"version": "1.0.0",
"author": "Wzh <wzh@uvwee.com>",
"repository": "github:wzh19960613/cn-number-js",
"repository": {
"type": "git",
"url": "git+https://github.com/wzh19960613/cn-number-js.git"
},
"main": "dist/index.js",

@@ -12,3 +15,3 @@ "module": "dist/index.js",

},
"description": "Convert integers or serial numbers to Chinese words. Support `capital` and `traditional`",
"description": "Convert integers or serial numbers to Chinese numerals. Supports `capital` and `traditional` forms",
"keywords": [

@@ -22,3 +25,7 @@ "cn",

"string",
"literal"
"literal",
"numeral",
"convertor",
"capital",
"traditional"
],

@@ -25,0 +32,0 @@ "license": "MIT",

# cn-number
Convert integers or serial numbers to Chinese words. Support `capital` and `traditional`.
English | [中文](README_CN.md)
Convert integers or serial numbers to Chinese numerals. Supports `capital` and `traditional` forms.
## Installation

@@ -29,5 +31,5 @@

## Options
## Configuration Options
Default option for `newCnNumConvertor` is:
`newCnNumConvertor` creates a function that converts integers to Chinese numerals. Default configuration:

@@ -38,8 +40,10 @@ ```javascript

`liang` is for switching between `二` and `两`. Default value is `UseLiang.QianWanYi`.
When `capital` is `true`, the result will be in capital form, and all `2` will not be converted to `两`.
When `{ capital: true }` there will be no `两` in result.
When `traditional` is `true`, the result will be in traditional form.
`UseLiang` contains `Bai`, `Qian`, `Wan`, `Yi`, `QianWanYi`, `BaiQianWanYi`. And
`liang` is used to switch between `二` and `两`. The default value is `UseLiang.QianWanYi`, which means trying to use `两` before `千`, `万`, and `亿`.
`UseLiang` includes `Bai`, `Qian`, `Wan`, `Yi`, `QianWanYi`, `BaiQianWanYi`. And:
```javascript

@@ -50,4 +54,3 @@ UseLiang.QianWanYi === UseLiang.Qian | UseLiang.Wan | UseLiang.Yi

If you can make sure the abs of inputed value will always less than `10000` or `1e8`,
you can set the `absLessThan` to optimize performance. Otherwise there's no need to set it.
If you are certain that the absolute value of the input is always less than `10000` or `1e8`, you can set `absLessThan` to optimize performance. Otherwise, no need to set it.

@@ -78,3 +81,3 @@ ```javascript

Default option for `newCnSerialNumConvertor` is:
`newCnSerialNumConvertor` creates a function that converts serial numbers to Chinese form. Default configuration:

@@ -105,4 +108,48 @@ ```javascript

## Dictionaries
`DigitCN`, `DigitTraditionalCN`, `DigitCapitalCN`, `DigitCapitalTraditionalCN` are used for converting numbers.
`SerialDigitCN` is used for converting serial numbers.
These five dictionaries can be imported directly, defined as follows:
```javascript
const DigitCN = new Map([
[-2, '两'], [-1, '负'],
[0, '零'], [1, '一'], [2, '二'], [3, '三'], [4, '四'],
[5, '五'], [6, '六'], [7, '七'], [8, '八'], [9, '九'],
[10, '十'], [100, '百'], [1000, '千'], [1e4, '万'], [1e8, '亿']
])
const DigitTraditionalCN = new Map([
[-2, '兩'], [-1, '負'],
[0, '零'], [1, '一'], [2, '二'], [3, '三'], [4, '四'],
[5, '五'], [6, '六'], [7, '七'], [8, '八'], [9, '九'],
[10, '十'], [100, '百'], [1000, '千'], [1e4, '萬'], [1e8, '億']
])
const DigitCapitalCN = new Map([
[-2, '贰'], [-1, '负'],
[0, '零'], [1, '壹'], [2, '贰'], [3, '叁'], [4, '肆'],
[5, '伍'], [6, '陆'], [7, '柒'], [8, '捌'], [9, '玖'],
[10, '拾'], [100, '佰'], [1000, '仟'], [1e4, '万'], [1e8, '亿']
])
const DigitCapitalTraditionalCN = new Map([
[-2, '貳'], [-1, '負'],
[0, '零'], [1, '壹'], [2, '貳'], [3, '參'], [4, '肆'],
[5, '伍'], [6, '陸'], [7, '柒'], [8, '捌'], [9, '玖'],
[10, '拾'], [100, '佰'], [1000, '仟'], [1e4, '萬'], [1e8, '億']
])
const SerialDigitCN = new Map([
[0, '〇'], [1, '一'], [2, '二'], [3, '三'], [4, '四'],
[5, '五'], [6, '六'], [7, '七'], [8, '八'], [9, '九'],
])
```
## Attention
In JavaScript, numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as integers. So the value input should be greater than `-9007199254740992` and less than `9007199254740992`.
In JavaScript, numbers with absolute values equal to or greater than 2^53 are too large to be represented accurately as integers. Therefore, input values should be greater than `-9007199254740992` and less than `9007199254740992`.

@@ -1,2 +0,4 @@

import { DigitCapitalCN, DigitCapitalTraditionalCN, DigitTraditionalCN, DigitCN, SerialDigitCN } from './dicts'
import {
DigitCapitalCN, DigitCapitalTraditionalCN, DigitTraditionalCN, DigitCN, SerialDigitCN
} from './dicts'

@@ -3,0 +5,0 @@ export interface CnNumOptFinal {

export const DigitCN = new Map([
[-2, '两'], [-1, '负'],
[0, '零'],
[1, '一'],
[2, '二'],
[3, '三'],
[4, '四'],
[5, '五'],
[6, '六'],
[7, '七'],
[8, '八'],
[9, '九'],
[0, '零'], [1, '一'], [2, '二'], [3, '三'], [4, '四'],
[5, '五'], [6, '六'], [7, '七'], [8, '八'], [9, '九'],
[10, '十'], [100, '百'], [1000, '千'], [1e4, '万'], [1e8, '亿']

@@ -18,12 +10,4 @@ ])

[-2, '兩'], [-1, '負'],
[0, '零'],
[1, '一'],
[2, '二'],
[3, '三'],
[4, '四'],
[5, '五'],
[6, '六'],
[7, '七'],
[8, '八'],
[9, '九'],
[0, '零'], [1, '一'], [2, '二'], [3, '三'], [4, '四'],
[5, '五'], [6, '六'], [7, '七'], [8, '八'], [9, '九'],
[10, '十'], [100, '百'], [1000, '千'], [1e4, '萬'], [1e8, '億']

@@ -34,12 +18,4 @@ ])

[-2, '贰'], [-1, '负'],
[0, '零'],
[1, '壹'],
[2, '贰'],
[3, '叁'],
[4, '肆'],
[5, '伍'],
[6, '陆'],
[7, '柒'],
[8, '捌'],
[9, '玖'],
[0, '零'], [1, '壹'], [2, '贰'], [3, '叁'], [4, '肆'],
[5, '伍'], [6, '陆'], [7, '柒'], [8, '捌'], [9, '玖'],
[10, '拾'], [100, '佰'], [1000, '仟'], [1e4, '万'], [1e8, '亿']

@@ -50,12 +26,4 @@ ])

[-2, '貳'], [-1, '負'],
[0, '零'],
[1, '壹'],
[2, '貳'],
[3, '參'],
[4, '肆'],
[5, '伍'],
[6, '陸'],
[7, '柒'],
[8, '捌'],
[9, '玖'],
[0, '零'], [1, '壹'], [2, '貳'], [3, '參'], [4, '肆'],
[5, '伍'], [6, '陸'], [7, '柒'], [8, '捌'], [9, '玖'],
[10, '拾'], [100, '佰'], [1000, '仟'], [1e4, '萬'], [1e8, '億']

@@ -62,0 +30,0 @@ ])

@@ -132,3 +132,5 @@ import type { CnNumOptFinal, CnNumOptions } from './config'

const dict = getSerialDict(opt)
return function (n: number) { return notNegToDigits(n).reverse().map(d => dict.get(d)!).join('') }
return function (n: number) {
return notNegToDigits(n).reverse().map(d => dict.get(d)!).join('')
}
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc