cjk-number 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +65 -22
- package/dist/constants.d.ts +1 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +15 -3
- package/dist/index.d.ts +523 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +231 -24
- package/dist/types.d.ts +63 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -39,20 +39,31 @@ import {
|
|
|
39
39
|
hiragana
|
|
40
40
|
} from "cjk-number";
|
|
41
41
|
|
|
42
|
-
// parse string -> number/bigint
|
|
42
|
+
// parse string -> number / bigint / string
|
|
43
43
|
number.parse("一千零二十三"); // 1023
|
|
44
44
|
number.parse("壹仟零貳拾參"); // 1023
|
|
45
45
|
number.parse("負一百零二"); // -102
|
|
46
46
|
number.parse("一點二三"); // 1.23
|
|
47
|
-
number.parse("一無量大數", {
|
|
47
|
+
number.parse("一無量大數", { mode: "preferBigInt" }); // 10n ** 68n
|
|
48
|
+
number.parse("一京點一", { mode: "exactDecimal" }); // "10000000000000000.1" (lossless)
|
|
48
49
|
|
|
49
|
-
// format number/bigint ->
|
|
50
|
+
// format number/bigint/string -> CJK
|
|
50
51
|
cjkIdeographic.parse(1023); // "一千零二十三"
|
|
51
52
|
tradChineseFormal.parse(1023); // "壹仟零貳拾參"
|
|
52
53
|
simpChineseFormal.parse(1023); // "壹仟零贰拾叁"
|
|
53
54
|
koreanHangulFormal.parse(10n ** 68n); // "일무량대수"
|
|
54
55
|
japaneseFormal.parse(10n ** 68n); // "壱無量大数"
|
|
55
56
|
|
|
57
|
+
// arithmetic on CJK strings (exact BigFloat engine)
|
|
58
|
+
tradChineseInformal.add(["一兆", "一點五"]); // "一兆零一點五"
|
|
59
|
+
tradChineseInformal.subtract(["一京", "一兆"]); // "九千九百九十九兆"
|
|
60
|
+
tradChineseInformal.multiply(["一億", "一億"]); // "一京"
|
|
61
|
+
tradChineseInformal.divide(["五", "二"]); // "二點五"
|
|
62
|
+
tradChineseInformal.modulo("五", "二"); // "一"
|
|
63
|
+
tradChineseInformal.pow("二", "十"); // "一千零二十四"
|
|
64
|
+
tradChineseInformal.abs("負一兆"); // "一兆"
|
|
65
|
+
["三十", "二", "十一"].sort(tradChineseInformal.compare); // ["二", "十一", "三十"]
|
|
66
|
+
|
|
56
67
|
// stem/branch
|
|
57
68
|
cjkHeavenlyStem.parse(10); // "癸"
|
|
58
69
|
cjkEarthlyBranch.parse(12); // "亥"
|
|
@@ -66,35 +77,66 @@ hiragana.parse(46); // "ん"
|
|
|
66
77
|
|
|
67
78
|
### number.parse(input, options?)
|
|
68
79
|
|
|
69
|
-
Parses CJK text into number or
|
|
80
|
+
Parses CJK text into a `number`, `bigint`, or exact decimal `string`.
|
|
70
81
|
|
|
71
82
|
Options:
|
|
72
83
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
84
|
+
| Option | Type | Default | Description |
|
|
85
|
+
|---|---|---|---|
|
|
86
|
+
| `mode` | `"number" \| "preferBigInt" \| "exactDecimal"` | `"number"` | Controls the output numeric type |
|
|
87
|
+
| `strict` | `boolean` | `false` | Rejects unsupported characters early |
|
|
88
|
+
| `heavenlyStemMode` | `"fixed" \| "cyclic"` | `"fixed"` | How to handle out-of-range stem values |
|
|
89
|
+
| `earthlyBranchMode` | `"fixed" \| "cyclic"` | `"fixed"` | How to handle out-of-range branch values |
|
|
90
|
+
| `explicitTyping` | `ExplicitTyping` | `undefined` | Forces a specific CJK system for parsing |
|
|
91
|
+
|
|
92
|
+
**`mode` values:**
|
|
93
|
+
|
|
94
|
+
- `"number"` (default) — returns `number`; auto-promotes to `bigint` if the integer exceeds `Number.MAX_SAFE_INTEGER`.
|
|
95
|
+
- `"preferBigInt"` — always returns `bigint` for integer parse paths.
|
|
96
|
+
- `"exactDecimal"` — returns a lossless decimal `string` (e.g. `"10000000000000000.1"`), bypassing the `MAX_SAFE_INTEGER` restriction for mixed large+decimal values.
|
|
77
97
|
|
|
78
|
-
|
|
98
|
+
**`explicitTyping` values:**
|
|
79
99
|
|
|
80
|
-
-
|
|
81
|
-
- If out of Number safe range, returns bigint automatically.
|
|
82
|
-
- If preferBigInt is true, always returns bigint for integer parse paths.
|
|
83
|
-
- Decimal parse returns number.
|
|
100
|
+
- Choose from any of the available system names (e.g., `"hiraganaIroha"`, `"tradChineseFormal"`, `"koreanHangulFormal"`) to force the parser to use that system's mapping specifically. This is useful for resolving conflicts between systems that share the same symbols (like Hiragana Gojuon vs Iroha).
|
|
84
101
|
|
|
85
102
|
Examples:
|
|
86
103
|
|
|
87
104
|
```js
|
|
88
|
-
number.parse("九千零七兆一", {
|
|
105
|
+
number.parse("九千零七兆一", { mode: "preferBigInt" }); // 9007000000000001n
|
|
89
106
|
number.parse("癸"); // 10
|
|
90
107
|
number.parse("亥"); // 12
|
|
91
|
-
number.parse("壱京", {
|
|
92
|
-
number.parse("ぬ"); // 10
|
|
108
|
+
number.parse("壱京", { mode: "preferBigInt" }); // 10n ** 16n
|
|
109
|
+
number.parse("ぬ", { explicitTyping: "hiraganaIroha" }); // 10
|
|
110
|
+
number.parse("ぬ"); // 23 (default gojuon sequence)
|
|
111
|
+
number.parse("一京點一", { mode: "exactDecimal" }); // "10000000000000000.1"
|
|
93
112
|
```
|
|
94
113
|
|
|
95
114
|
### Formatters
|
|
96
115
|
|
|
97
|
-
All formatters expose
|
|
116
|
+
All formatters expose the following methods:
|
|
117
|
+
|
|
118
|
+
#### `parse(value)`
|
|
119
|
+
|
|
120
|
+
Formats a `number`, `bigint`, or exact decimal `string` into a CJK numeral string.
|
|
121
|
+
|
|
122
|
+
#### Arithmetic methods
|
|
123
|
+
|
|
124
|
+
All numeric formatters (not cyclic/sequence ones) also expose arithmetic methods that accept CJK strings and return a CJK string in the same numeral system:
|
|
125
|
+
|
|
126
|
+
```js
|
|
127
|
+
tradChineseInformal.add(["一千", "二十三"]); // "一千零二十三"
|
|
128
|
+
tradChineseInformal.subtract(["一京", "一兆"]); // "九千九百九十九兆"
|
|
129
|
+
tradChineseInformal.multiply(["一億", "一億"]); // "一京"
|
|
130
|
+
tradChineseInformal.divide(["五", "二"]); // "二點五"
|
|
131
|
+
tradChineseInformal.modulo("五", "二"); // "一"
|
|
132
|
+
tradChineseInformal.pow("二", "三"); // "八"
|
|
133
|
+
tradChineseInformal.pow("二", 3); // "八" (exponent can be a number)
|
|
134
|
+
tradChineseInformal.abs("負五十"); // "五十"
|
|
135
|
+
tradChineseInformal.compare("三十", "二"); // 1
|
|
136
|
+
["三十", "二", "十一"].sort(tradChineseInformal.compare); // ["二", "十一", "三十"]
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
All arithmetic uses a **zero-dependency BigFloat engine**: decimal points are scaled out to `BigInt` before any operation, so results like `"一兆" + "一點五"` are exact with no floating-point drift.
|
|
98
140
|
|
|
99
141
|
Available formatters:
|
|
100
142
|
|
|
@@ -119,7 +161,7 @@ Examples:
|
|
|
119
161
|
|
|
120
162
|
```js
|
|
121
163
|
tradChineseInformal.parse(-320); // "負三百二十"
|
|
122
|
-
simpChineseInformal.parse(12.34); // "
|
|
164
|
+
simpChineseInformal.parse(12.34); // "十二点三四"
|
|
123
165
|
tradChineseFormal.parse(10n ** 68n); // "壹無量大數"
|
|
124
166
|
simpChineseFormal.parse(10n ** 64n); // "壹不可思议"
|
|
125
167
|
|
|
@@ -197,10 +239,11 @@ number.parse("abc", { strict: true }); // throws SyntaxError
|
|
|
197
239
|
|
|
198
240
|
Common thrown errors:
|
|
199
241
|
|
|
200
|
-
- SyntaxError
|
|
201
|
-
- RangeError
|
|
202
|
-
- RangeError
|
|
203
|
-
- RangeError
|
|
242
|
+
- `SyntaxError`: unsupported or invalid text shape
|
|
243
|
+
- `RangeError`: invalid formatter range in fixed sequence mode
|
|
244
|
+
- `RangeError`: non-integer passed to integer-only paths
|
|
245
|
+
- `RangeError`: decimal parse integer part exceeds `Number.MAX_SAFE_INTEGER` — use `{ mode: "exactDecimal" }` to bypass
|
|
246
|
+
- `RangeError`: division by zero in `divide` or `modulo`
|
|
204
247
|
|
|
205
248
|
## Development
|
|
206
249
|
|
package/dist/constants.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export declare const BRANCHES: readonly ["子", "丑", "寅", "卯", "辰", "巳
|
|
|
4
4
|
export declare const KOREAN_HANGUL_DIGITS: readonly ["일", "이", "삼", "사", "오", "육", "칠", "팔", "구"];
|
|
5
5
|
export declare const KOREAN_HANJA_FORMAL_DIGITS: readonly ["壹", "貳", "參", "四", "五", "六", "七", "八", "九"];
|
|
6
6
|
export declare const KOREAN_HANJA_INFORMAL_DIGITS: readonly ["一", "二", "三", "四", "五", "六", "七", "八", "九"];
|
|
7
|
-
export declare const JAPANESE_FORMAL_DIGITS: readonly ["壱", "
|
|
7
|
+
export declare const JAPANESE_FORMAL_DIGITS: readonly ["壱", "弍", "参", "四", "伍", "六", "七", "八", "九"];
|
|
8
8
|
export declare const JAPANESE_INFORMAL_DIGITS: readonly ["一", "二", "三", "四", "五", "六", "七", "八", "九"];
|
|
9
9
|
export declare const HIRAGANA: readonly ["あ", "い", "う", "え", "お", "か", "き", "く", "け", "こ", "さ", "し", "す", "せ", "そ", "た", "ち", "つ", "て", "と", "な", "に", "ぬ", "ね", "の", "は", "ひ", "ふ", "へ", "ほ", "ま", "み", "む", "め", "も", "や", "ゆ", "よ", "ら", "り", "る", "れ", "ろ", "わ", "を", "ん"];
|
|
10
10
|
export declare const HIRAGANA_IROHA: readonly ["い", "ろ", "は", "に", "ほ", "へ", "と", "ち", "り", "ぬ", "る", "を", "わ", "か", "よ", "た", "れ", "そ", "つ", "ね", "な", "ら", "む", "う", "ゐ", "の", "お", "く", "や", "ま", "け", "ふ", "こ", "え", "て", "あ", "さ", "き", "ゆ", "め", "み", "し", "ゑ", "ひ", "も", "せ", "す"];
|
package/dist/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,eAAO,MAAM,KAAK,6DAWR,CAAC;AACX,eAAO,MAAM,QAAQ,uEAaX,CAAC;AACX,eAAO,MAAM,oBAAoB,wDAUvB,CAAC;AACX,eAAO,MAAM,0BAA0B,wDAU7B,CAAC;AACX,eAAO,MAAM,4BAA4B,wDAU/B,CAAC;AACX,eAAO,MAAM,sBAAsB,wDAUzB,CAAC;AACX,eAAO,MAAM,wBAAwB,wDAU3B,CAAC;AACX,eAAO,MAAM,QAAQ,iPA+CX,CAAC;AACX,eAAO,MAAM,cAAc,sPAgDjB,CAAC;AACX,eAAO,MAAM,QAAQ,iPA+CX,CAAC;AACX,eAAO,MAAM,cAAc,sPAgDjB,CAAC;AAEX,eAAO,MAAM,gBAAgB,4GAkBnB,CAAC;AAEX,eAAO,MAAM,kBAAkB,4GAkBrB,CAAC;AAEX,eAAO,MAAM,yBAAyB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,eAAO,MAAM,KAAK,6DAWR,CAAC;AACX,eAAO,MAAM,QAAQ,uEAaX,CAAC;AACX,eAAO,MAAM,oBAAoB,wDAUvB,CAAC;AACX,eAAO,MAAM,0BAA0B,wDAU7B,CAAC;AACX,eAAO,MAAM,4BAA4B,wDAU/B,CAAC;AACX,eAAO,MAAM,sBAAsB,wDAUzB,CAAC;AACX,eAAO,MAAM,wBAAwB,wDAU3B,CAAC;AACX,eAAO,MAAM,QAAQ,iPA+CX,CAAC;AACX,eAAO,MAAM,cAAc,sPAgDjB,CAAC;AACX,eAAO,MAAM,QAAQ,iPA+CX,CAAC;AACX,eAAO,MAAM,cAAc,sPAgDjB,CAAC;AAEX,eAAO,MAAM,gBAAgB,4GAkBnB,CAAC;AAEX,eAAO,MAAM,kBAAkB,4GAkBrB,CAAC;AAEX,eAAO,MAAM,yBAAyB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAmBzD,CAAC;AAEL,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CA6BnD,CAAC;AAEF,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAO9C,CAAC;AAEF,eAAO,MAAM,cAAc,4GAkBjB,CAAC;AAEX,eAAO,MAAM,cAAc,4GAkBjB,CAAC;AAWX,eAAO,MAAM,iBAAiB,EAAE,QAO/B,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,QAO7B,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,QAO/B,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,QAO7B,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,QAO/B,CAAC;AAEF,eAAO,MAAM,uBAAuB,EAAE,QAOrC,CAAC;AAEF,eAAO,MAAM,yBAAyB,EAAE,QAOvC,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,QAOjC,CAAC;AAEF,eAAO,MAAM,qBAAqB,EAAE,QAOnC,CAAC;AAEF,eAAO,MAAM,cAAc,oBAAqC,CAAC"}
|
package/dist/constants.js
CHANGED
|
@@ -59,10 +59,10 @@ export const KOREAN_HANJA_INFORMAL_DIGITS = [
|
|
|
59
59
|
];
|
|
60
60
|
export const JAPANESE_FORMAL_DIGITS = [
|
|
61
61
|
"壱",
|
|
62
|
-
"
|
|
62
|
+
"弍",
|
|
63
63
|
"参",
|
|
64
64
|
"四",
|
|
65
|
-
"
|
|
65
|
+
"伍",
|
|
66
66
|
"六",
|
|
67
67
|
"七",
|
|
68
68
|
"八",
|
|
@@ -315,7 +315,10 @@ export const SEQUENCE_SYMBOL_TO_NUMBER = (() => {
|
|
|
315
315
|
const map = {};
|
|
316
316
|
const put = (chars) => {
|
|
317
317
|
chars.forEach((char, index) => {
|
|
318
|
-
|
|
318
|
+
// Prioritize the first mapping we encounter (e.g. Gojuon over Iroha)
|
|
319
|
+
if (map[char] === undefined) {
|
|
320
|
+
map[char] = index + 1;
|
|
321
|
+
}
|
|
319
322
|
});
|
|
320
323
|
};
|
|
321
324
|
put(STEMS);
|
|
@@ -413,6 +416,7 @@ export const TRAD_INFORMAL_SET = {
|
|
|
413
416
|
digits: ["一", "二", "三", "四", "五", "六", "七", "八", "九"],
|
|
414
417
|
smallUnits: ["十", "百", "千"],
|
|
415
418
|
bigUnits: [...TRAD_BIG_UNITS],
|
|
419
|
+
dropTenOne: true,
|
|
416
420
|
};
|
|
417
421
|
export const TRAD_FORMAL_SET = {
|
|
418
422
|
zero: "零",
|
|
@@ -420,6 +424,7 @@ export const TRAD_FORMAL_SET = {
|
|
|
420
424
|
digits: ["壹", "貳", "參", "肆", "伍", "陸", "柒", "捌", "玖"],
|
|
421
425
|
smallUnits: ["拾", "佰", "仟"],
|
|
422
426
|
bigUnits: [...TRAD_BIG_UNITS],
|
|
427
|
+
dropTenOne: false,
|
|
423
428
|
};
|
|
424
429
|
export const SIMP_INFORMAL_SET = {
|
|
425
430
|
zero: "零",
|
|
@@ -427,6 +432,7 @@ export const SIMP_INFORMAL_SET = {
|
|
|
427
432
|
digits: ["一", "二", "三", "四", "五", "六", "七", "八", "九"],
|
|
428
433
|
smallUnits: ["十", "百", "千"],
|
|
429
434
|
bigUnits: [...SIMP_BIG_UNITS],
|
|
435
|
+
dropTenOne: true,
|
|
430
436
|
};
|
|
431
437
|
export const SIMP_FORMAL_SET = {
|
|
432
438
|
zero: "零",
|
|
@@ -434,6 +440,7 @@ export const SIMP_FORMAL_SET = {
|
|
|
434
440
|
digits: ["壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"],
|
|
435
441
|
smallUnits: ["拾", "佰", "仟"],
|
|
436
442
|
bigUnits: [...SIMP_BIG_UNITS],
|
|
443
|
+
dropTenOne: false,
|
|
437
444
|
};
|
|
438
445
|
export const KOREAN_HANGUL_SET = {
|
|
439
446
|
zero: "영",
|
|
@@ -441,6 +448,7 @@ export const KOREAN_HANGUL_SET = {
|
|
|
441
448
|
digits: [...KOREAN_HANGUL_DIGITS],
|
|
442
449
|
smallUnits: ["십", "백", "천"],
|
|
443
450
|
bigUnits: [...KOREAN_BIG_UNITS],
|
|
451
|
+
dropTenOne: false,
|
|
444
452
|
};
|
|
445
453
|
export const KOREAN_HANJA_FORMAL_SET = {
|
|
446
454
|
zero: "零",
|
|
@@ -448,6 +456,7 @@ export const KOREAN_HANJA_FORMAL_SET = {
|
|
|
448
456
|
digits: [...KOREAN_HANJA_FORMAL_DIGITS],
|
|
449
457
|
smallUnits: ["拾", "佰", "仟"],
|
|
450
458
|
bigUnits: [...TRAD_BIG_UNITS],
|
|
459
|
+
dropTenOne: false,
|
|
451
460
|
};
|
|
452
461
|
export const KOREAN_HANJA_INFORMAL_SET = {
|
|
453
462
|
zero: "零",
|
|
@@ -455,6 +464,7 @@ export const KOREAN_HANJA_INFORMAL_SET = {
|
|
|
455
464
|
digits: [...KOREAN_HANJA_INFORMAL_DIGITS],
|
|
456
465
|
smallUnits: ["十", "百", "千"],
|
|
457
466
|
bigUnits: [...TRAD_BIG_UNITS],
|
|
467
|
+
dropTenOne: true,
|
|
458
468
|
};
|
|
459
469
|
export const JAPANESE_FORMAL_SET = {
|
|
460
470
|
zero: "零",
|
|
@@ -462,6 +472,7 @@ export const JAPANESE_FORMAL_SET = {
|
|
|
462
472
|
digits: [...JAPANESE_FORMAL_DIGITS],
|
|
463
473
|
smallUnits: ["拾", "百", "千"],
|
|
464
474
|
bigUnits: [...JAPANESE_BIG_UNITS],
|
|
475
|
+
dropTenOne: false,
|
|
465
476
|
};
|
|
466
477
|
export const JAPANESE_INFORMAL_SET = {
|
|
467
478
|
zero: "零",
|
|
@@ -469,5 +480,6 @@ export const JAPANESE_INFORMAL_SET = {
|
|
|
469
480
|
digits: [...JAPANESE_INFORMAL_DIGITS],
|
|
470
481
|
smallUnits: ["十", "百", "千"],
|
|
471
482
|
bigUnits: [...JAPANESE_BIG_UNITS],
|
|
483
|
+
dropTenOne: true,
|
|
472
484
|
};
|
|
473
485
|
export const BIG_UNIT_ORDER = createBigUnitOrder(SIMP_BIG_UNITS);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,54 +1,575 @@
|
|
|
1
1
|
import { SystemParseOptions, NumberParseOptions, NumberLike } from "./types.js";
|
|
2
2
|
export * from "./types.js";
|
|
3
3
|
export declare const number: {
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Parses a CJK numeric string into a number, bigint, or exact decimal string.
|
|
6
|
+
*
|
|
7
|
+
* @param input The CJK numeric string to parse.
|
|
8
|
+
* @param options Options defining how to handle the parse.
|
|
9
|
+
* - `mode: "preferBigInt"` – return `bigint` for integers.
|
|
10
|
+
* - `mode: "exactDecimal"` – return decimals as lossless strings, bypassing float limits.
|
|
11
|
+
* @returns The parsed number, bigint, or exact decimal string.
|
|
12
|
+
*/
|
|
13
|
+
parse(input: string, options?: NumberParseOptions): number | bigint | string;
|
|
5
14
|
};
|
|
6
15
|
export declare const cjkIdeographic: {
|
|
16
|
+
/**
|
|
17
|
+
* Formats a numeric value into the specific CJK numeral system.
|
|
18
|
+
*
|
|
19
|
+
* @param value The number or bigint to format.
|
|
20
|
+
* @returns The formatted string representation in the respective CJK system.
|
|
21
|
+
*/
|
|
7
22
|
parse(value: NumberLike): string;
|
|
23
|
+
/**
|
|
24
|
+
* Adds multiple CJK numeric strings together.
|
|
25
|
+
* @param values The CJK numeric strings to add.
|
|
26
|
+
* @returns The sum of the CJK numeric strings.
|
|
27
|
+
*/
|
|
28
|
+
add(values: string[]): string;
|
|
29
|
+
/**
|
|
30
|
+
* Subtracts multiple CJK numeric strings from the first one.
|
|
31
|
+
* @param values The CJK numeric strings to subtract.
|
|
32
|
+
* @returns The difference of the CJK numeric strings.
|
|
33
|
+
*/
|
|
34
|
+
subtract(values: string[]): string;
|
|
35
|
+
/**
|
|
36
|
+
* Multiplies multiple CJK numeric strings together.
|
|
37
|
+
* @param values The CJK numeric strings to multiply.
|
|
38
|
+
* @returns The product of the CJK numeric strings.
|
|
39
|
+
*/
|
|
40
|
+
multiply(values: string[]): string;
|
|
41
|
+
/**
|
|
42
|
+
* Divides multiple CJK numeric strings from the first one.
|
|
43
|
+
* @param values The CJK numeric strings to divide.
|
|
44
|
+
* @returns The quotient of the CJK numeric strings.
|
|
45
|
+
*/
|
|
46
|
+
divide(values: string[]): string;
|
|
47
|
+
/**
|
|
48
|
+
* Calculates the remainder of the first string divided by the second.
|
|
49
|
+
*/
|
|
50
|
+
modulo(a: string, b: string): string;
|
|
51
|
+
/**
|
|
52
|
+
* Raises the first string to the power of the second string or a number.
|
|
53
|
+
*/
|
|
54
|
+
pow(base: string, exponent: string | number): string;
|
|
55
|
+
/**
|
|
56
|
+
* Returns the absolute value of the string.
|
|
57
|
+
*/
|
|
58
|
+
abs(value: string): string;
|
|
59
|
+
/**
|
|
60
|
+
* Compares two strings. Useful for Array.prototype.sort().
|
|
61
|
+
* @returns 1 if a > b, -1 if a < b, 0 if equal.
|
|
62
|
+
*/
|
|
63
|
+
compare(a: string, b: string): number;
|
|
8
64
|
};
|
|
9
65
|
export declare const tradChineseInformal: {
|
|
66
|
+
/**
|
|
67
|
+
* Formats a numeric value into the specific CJK numeral system.
|
|
68
|
+
*
|
|
69
|
+
* @param value The number or bigint to format.
|
|
70
|
+
* @returns The formatted string representation in the respective CJK system.
|
|
71
|
+
*/
|
|
10
72
|
parse(value: NumberLike): string;
|
|
73
|
+
/**
|
|
74
|
+
* Adds multiple CJK numeric strings together.
|
|
75
|
+
* @param values The CJK numeric strings to add.
|
|
76
|
+
* @returns The sum of the CJK numeric strings.
|
|
77
|
+
*/
|
|
78
|
+
add(values: string[]): string;
|
|
79
|
+
/**
|
|
80
|
+
* Subtracts multiple CJK numeric strings from the first one.
|
|
81
|
+
* @param values The CJK numeric strings to subtract.
|
|
82
|
+
* @returns The difference of the CJK numeric strings.
|
|
83
|
+
*/
|
|
84
|
+
subtract(values: string[]): string;
|
|
85
|
+
/**
|
|
86
|
+
* Multiplies multiple CJK numeric strings together.
|
|
87
|
+
* @param values The CJK numeric strings to multiply.
|
|
88
|
+
* @returns The product of the CJK numeric strings.
|
|
89
|
+
*/
|
|
90
|
+
multiply(values: string[]): string;
|
|
91
|
+
/**
|
|
92
|
+
* Divides multiple CJK numeric strings from the first one.
|
|
93
|
+
* @param values The CJK numeric strings to divide.
|
|
94
|
+
* @returns The quotient of the CJK numeric strings.
|
|
95
|
+
*/
|
|
96
|
+
divide(values: string[]): string;
|
|
97
|
+
/**
|
|
98
|
+
* Calculates the remainder of the first string divided by the second.
|
|
99
|
+
*/
|
|
100
|
+
modulo(a: string, b: string): string;
|
|
101
|
+
/**
|
|
102
|
+
* Raises the first string to the power of the second string or a number.
|
|
103
|
+
*/
|
|
104
|
+
pow(base: string, exponent: string | number): string;
|
|
105
|
+
/**
|
|
106
|
+
* Returns the absolute value of the string.
|
|
107
|
+
*/
|
|
108
|
+
abs(value: string): string;
|
|
109
|
+
/**
|
|
110
|
+
* Compares two strings. Useful for Array.prototype.sort().
|
|
111
|
+
* @returns 1 if a > b, -1 if a < b, 0 if equal.
|
|
112
|
+
*/
|
|
113
|
+
compare(a: string, b: string): number;
|
|
11
114
|
};
|
|
12
115
|
export declare const tradChineseFormal: {
|
|
116
|
+
/**
|
|
117
|
+
* Formats a numeric value into the specific CJK numeral system.
|
|
118
|
+
*
|
|
119
|
+
* @param value The number or bigint to format.
|
|
120
|
+
* @returns The formatted string representation in the respective CJK system.
|
|
121
|
+
*/
|
|
13
122
|
parse(value: NumberLike): string;
|
|
123
|
+
/**
|
|
124
|
+
* Adds multiple CJK numeric strings together.
|
|
125
|
+
* @param values The CJK numeric strings to add.
|
|
126
|
+
* @returns The sum of the CJK numeric strings.
|
|
127
|
+
*/
|
|
128
|
+
add(values: string[]): string;
|
|
129
|
+
/**
|
|
130
|
+
* Subtracts multiple CJK numeric strings from the first one.
|
|
131
|
+
* @param values The CJK numeric strings to subtract.
|
|
132
|
+
* @returns The difference of the CJK numeric strings.
|
|
133
|
+
*/
|
|
134
|
+
subtract(values: string[]): string;
|
|
135
|
+
/**
|
|
136
|
+
* Multiplies multiple CJK numeric strings together.
|
|
137
|
+
* @param values The CJK numeric strings to multiply.
|
|
138
|
+
* @returns The product of the CJK numeric strings.
|
|
139
|
+
*/
|
|
140
|
+
multiply(values: string[]): string;
|
|
141
|
+
/**
|
|
142
|
+
* Divides multiple CJK numeric strings from the first one.
|
|
143
|
+
* @param values The CJK numeric strings to divide.
|
|
144
|
+
* @returns The quotient of the CJK numeric strings.
|
|
145
|
+
*/
|
|
146
|
+
divide(values: string[]): string;
|
|
147
|
+
/**
|
|
148
|
+
* Calculates the remainder of the first string divided by the second.
|
|
149
|
+
*/
|
|
150
|
+
modulo(a: string, b: string): string;
|
|
151
|
+
/**
|
|
152
|
+
* Raises the first string to the power of the second string or a number.
|
|
153
|
+
*/
|
|
154
|
+
pow(base: string, exponent: string | number): string;
|
|
155
|
+
/**
|
|
156
|
+
* Returns the absolute value of the string.
|
|
157
|
+
*/
|
|
158
|
+
abs(value: string): string;
|
|
159
|
+
/**
|
|
160
|
+
* Compares two strings. Useful for Array.prototype.sort().
|
|
161
|
+
* @returns 1 if a > b, -1 if a < b, 0 if equal.
|
|
162
|
+
*/
|
|
163
|
+
compare(a: string, b: string): number;
|
|
14
164
|
};
|
|
15
165
|
export declare const simpChineseInformal: {
|
|
166
|
+
/**
|
|
167
|
+
* Formats a numeric value into the specific CJK numeral system.
|
|
168
|
+
*
|
|
169
|
+
* @param value The number or bigint to format.
|
|
170
|
+
* @returns The formatted string representation in the respective CJK system.
|
|
171
|
+
*/
|
|
16
172
|
parse(value: NumberLike): string;
|
|
173
|
+
/**
|
|
174
|
+
* Adds multiple CJK numeric strings together.
|
|
175
|
+
* @param values The CJK numeric strings to add.
|
|
176
|
+
* @returns The sum of the CJK numeric strings.
|
|
177
|
+
*/
|
|
178
|
+
add(values: string[]): string;
|
|
179
|
+
/**
|
|
180
|
+
* Subtracts multiple CJK numeric strings from the first one.
|
|
181
|
+
* @param values The CJK numeric strings to subtract.
|
|
182
|
+
* @returns The difference of the CJK numeric strings.
|
|
183
|
+
*/
|
|
184
|
+
subtract(values: string[]): string;
|
|
185
|
+
/**
|
|
186
|
+
* Multiplies multiple CJK numeric strings together.
|
|
187
|
+
* @param values The CJK numeric strings to multiply.
|
|
188
|
+
* @returns The product of the CJK numeric strings.
|
|
189
|
+
*/
|
|
190
|
+
multiply(values: string[]): string;
|
|
191
|
+
/**
|
|
192
|
+
* Divides multiple CJK numeric strings from the first one.
|
|
193
|
+
* @param values The CJK numeric strings to divide.
|
|
194
|
+
* @returns The quotient of the CJK numeric strings.
|
|
195
|
+
*/
|
|
196
|
+
divide(values: string[]): string;
|
|
197
|
+
/**
|
|
198
|
+
* Calculates the remainder of the first string divided by the second.
|
|
199
|
+
*/
|
|
200
|
+
modulo(a: string, b: string): string;
|
|
201
|
+
/**
|
|
202
|
+
* Raises the first string to the power of the second string or a number.
|
|
203
|
+
*/
|
|
204
|
+
pow(base: string, exponent: string | number): string;
|
|
205
|
+
/**
|
|
206
|
+
* Returns the absolute value of the string.
|
|
207
|
+
*/
|
|
208
|
+
abs(value: string): string;
|
|
209
|
+
/**
|
|
210
|
+
* Compares two strings. Useful for Array.prototype.sort().
|
|
211
|
+
* @returns 1 if a > b, -1 if a < b, 0 if equal.
|
|
212
|
+
*/
|
|
213
|
+
compare(a: string, b: string): number;
|
|
17
214
|
};
|
|
18
215
|
export declare const simpChineseFormal: {
|
|
216
|
+
/**
|
|
217
|
+
* Formats a numeric value into the specific CJK numeral system.
|
|
218
|
+
*
|
|
219
|
+
* @param value The number or bigint to format.
|
|
220
|
+
* @returns The formatted string representation in the respective CJK system.
|
|
221
|
+
*/
|
|
19
222
|
parse(value: NumberLike): string;
|
|
223
|
+
/**
|
|
224
|
+
* Adds multiple CJK numeric strings together.
|
|
225
|
+
* @param values The CJK numeric strings to add.
|
|
226
|
+
* @returns The sum of the CJK numeric strings.
|
|
227
|
+
*/
|
|
228
|
+
add(values: string[]): string;
|
|
229
|
+
/**
|
|
230
|
+
* Subtracts multiple CJK numeric strings from the first one.
|
|
231
|
+
* @param values The CJK numeric strings to subtract.
|
|
232
|
+
* @returns The difference of the CJK numeric strings.
|
|
233
|
+
*/
|
|
234
|
+
subtract(values: string[]): string;
|
|
235
|
+
/**
|
|
236
|
+
* Multiplies multiple CJK numeric strings together.
|
|
237
|
+
* @param values The CJK numeric strings to multiply.
|
|
238
|
+
* @returns The product of the CJK numeric strings.
|
|
239
|
+
*/
|
|
240
|
+
multiply(values: string[]): string;
|
|
241
|
+
/**
|
|
242
|
+
* Divides multiple CJK numeric strings from the first one.
|
|
243
|
+
* @param values The CJK numeric strings to divide.
|
|
244
|
+
* @returns The quotient of the CJK numeric strings.
|
|
245
|
+
*/
|
|
246
|
+
divide(values: string[]): string;
|
|
247
|
+
/**
|
|
248
|
+
* Calculates the remainder of the first string divided by the second.
|
|
249
|
+
*/
|
|
250
|
+
modulo(a: string, b: string): string;
|
|
251
|
+
/**
|
|
252
|
+
* Raises the first string to the power of the second string or a number.
|
|
253
|
+
*/
|
|
254
|
+
pow(base: string, exponent: string | number): string;
|
|
255
|
+
/**
|
|
256
|
+
* Returns the absolute value of the string.
|
|
257
|
+
*/
|
|
258
|
+
abs(value: string): string;
|
|
259
|
+
/**
|
|
260
|
+
* Compares two strings. Useful for Array.prototype.sort().
|
|
261
|
+
* @returns 1 if a > b, -1 if a < b, 0 if equal.
|
|
262
|
+
*/
|
|
263
|
+
compare(a: string, b: string): number;
|
|
20
264
|
};
|
|
21
265
|
export declare const koreanHangulFormal: {
|
|
266
|
+
/**
|
|
267
|
+
* Formats a numeric value into the specific CJK numeral system.
|
|
268
|
+
*
|
|
269
|
+
* @param value The number or bigint to format.
|
|
270
|
+
* @returns The formatted string representation in the respective CJK system.
|
|
271
|
+
*/
|
|
22
272
|
parse(value: NumberLike): string;
|
|
273
|
+
/**
|
|
274
|
+
* Adds multiple CJK numeric strings together.
|
|
275
|
+
* @param values The CJK numeric strings to add.
|
|
276
|
+
* @returns The sum of the CJK numeric strings.
|
|
277
|
+
*/
|
|
278
|
+
add(values: string[]): string;
|
|
279
|
+
/**
|
|
280
|
+
* Subtracts multiple CJK numeric strings from the first one.
|
|
281
|
+
* @param values The CJK numeric strings to subtract.
|
|
282
|
+
* @returns The difference of the CJK numeric strings.
|
|
283
|
+
*/
|
|
284
|
+
subtract(values: string[]): string;
|
|
285
|
+
/**
|
|
286
|
+
* Multiplies multiple CJK numeric strings together.
|
|
287
|
+
* @param values The CJK numeric strings to multiply.
|
|
288
|
+
* @returns The product of the CJK numeric strings.
|
|
289
|
+
*/
|
|
290
|
+
multiply(values: string[]): string;
|
|
291
|
+
/**
|
|
292
|
+
* Divides multiple CJK numeric strings from the first one.
|
|
293
|
+
* @param values The CJK numeric strings to divide.
|
|
294
|
+
* @returns The quotient of the CJK numeric strings.
|
|
295
|
+
*/
|
|
296
|
+
divide(values: string[]): string;
|
|
297
|
+
/**
|
|
298
|
+
* Calculates the remainder of the first string divided by the second.
|
|
299
|
+
*/
|
|
300
|
+
modulo(a: string, b: string): string;
|
|
301
|
+
/**
|
|
302
|
+
* Raises the first string to the power of the second string or a number.
|
|
303
|
+
*/
|
|
304
|
+
pow(base: string, exponent: string | number): string;
|
|
305
|
+
/**
|
|
306
|
+
* Returns the absolute value of the string.
|
|
307
|
+
*/
|
|
308
|
+
abs(value: string): string;
|
|
309
|
+
/**
|
|
310
|
+
* Compares two strings. Useful for Array.prototype.sort().
|
|
311
|
+
* @returns 1 if a > b, -1 if a < b, 0 if equal.
|
|
312
|
+
*/
|
|
313
|
+
compare(a: string, b: string): number;
|
|
23
314
|
};
|
|
24
315
|
export declare const koreanHanjaFormal: {
|
|
316
|
+
/**
|
|
317
|
+
* Formats a numeric value into the specific CJK numeral system.
|
|
318
|
+
*
|
|
319
|
+
* @param value The number or bigint to format.
|
|
320
|
+
* @returns The formatted string representation in the respective CJK system.
|
|
321
|
+
*/
|
|
25
322
|
parse(value: NumberLike): string;
|
|
323
|
+
/**
|
|
324
|
+
* Adds multiple CJK numeric strings together.
|
|
325
|
+
* @param values The CJK numeric strings to add.
|
|
326
|
+
* @returns The sum of the CJK numeric strings.
|
|
327
|
+
*/
|
|
328
|
+
add(values: string[]): string;
|
|
329
|
+
/**
|
|
330
|
+
* Subtracts multiple CJK numeric strings from the first one.
|
|
331
|
+
* @param values The CJK numeric strings to subtract.
|
|
332
|
+
* @returns The difference of the CJK numeric strings.
|
|
333
|
+
*/
|
|
334
|
+
subtract(values: string[]): string;
|
|
335
|
+
/**
|
|
336
|
+
* Multiplies multiple CJK numeric strings together.
|
|
337
|
+
* @param values The CJK numeric strings to multiply.
|
|
338
|
+
* @returns The product of the CJK numeric strings.
|
|
339
|
+
*/
|
|
340
|
+
multiply(values: string[]): string;
|
|
341
|
+
/**
|
|
342
|
+
* Divides multiple CJK numeric strings from the first one.
|
|
343
|
+
* @param values The CJK numeric strings to divide.
|
|
344
|
+
* @returns The quotient of the CJK numeric strings.
|
|
345
|
+
*/
|
|
346
|
+
divide(values: string[]): string;
|
|
347
|
+
/**
|
|
348
|
+
* Calculates the remainder of the first string divided by the second.
|
|
349
|
+
*/
|
|
350
|
+
modulo(a: string, b: string): string;
|
|
351
|
+
/**
|
|
352
|
+
* Raises the first string to the power of the second string or a number.
|
|
353
|
+
*/
|
|
354
|
+
pow(base: string, exponent: string | number): string;
|
|
355
|
+
/**
|
|
356
|
+
* Returns the absolute value of the string.
|
|
357
|
+
*/
|
|
358
|
+
abs(value: string): string;
|
|
359
|
+
/**
|
|
360
|
+
* Compares two strings. Useful for Array.prototype.sort().
|
|
361
|
+
* @returns 1 if a > b, -1 if a < b, 0 if equal.
|
|
362
|
+
*/
|
|
363
|
+
compare(a: string, b: string): number;
|
|
26
364
|
};
|
|
27
365
|
export declare const koreanHanjaInformal: {
|
|
366
|
+
/**
|
|
367
|
+
* Formats a numeric value into the specific CJK numeral system.
|
|
368
|
+
*
|
|
369
|
+
* @param value The number or bigint to format.
|
|
370
|
+
* @returns The formatted string representation in the respective CJK system.
|
|
371
|
+
*/
|
|
28
372
|
parse(value: NumberLike): string;
|
|
373
|
+
/**
|
|
374
|
+
* Adds multiple CJK numeric strings together.
|
|
375
|
+
* @param values The CJK numeric strings to add.
|
|
376
|
+
* @returns The sum of the CJK numeric strings.
|
|
377
|
+
*/
|
|
378
|
+
add(values: string[]): string;
|
|
379
|
+
/**
|
|
380
|
+
* Subtracts multiple CJK numeric strings from the first one.
|
|
381
|
+
* @param values The CJK numeric strings to subtract.
|
|
382
|
+
* @returns The difference of the CJK numeric strings.
|
|
383
|
+
*/
|
|
384
|
+
subtract(values: string[]): string;
|
|
385
|
+
/**
|
|
386
|
+
* Multiplies multiple CJK numeric strings together.
|
|
387
|
+
* @param values The CJK numeric strings to multiply.
|
|
388
|
+
* @returns The product of the CJK numeric strings.
|
|
389
|
+
*/
|
|
390
|
+
multiply(values: string[]): string;
|
|
391
|
+
/**
|
|
392
|
+
* Divides multiple CJK numeric strings from the first one.
|
|
393
|
+
* @param values The CJK numeric strings to divide.
|
|
394
|
+
* @returns The quotient of the CJK numeric strings.
|
|
395
|
+
*/
|
|
396
|
+
divide(values: string[]): string;
|
|
397
|
+
/**
|
|
398
|
+
* Calculates the remainder of the first string divided by the second.
|
|
399
|
+
*/
|
|
400
|
+
modulo(a: string, b: string): string;
|
|
401
|
+
/**
|
|
402
|
+
* Raises the first string to the power of the second string or a number.
|
|
403
|
+
*/
|
|
404
|
+
pow(base: string, exponent: string | number): string;
|
|
405
|
+
/**
|
|
406
|
+
* Returns the absolute value of the string.
|
|
407
|
+
*/
|
|
408
|
+
abs(value: string): string;
|
|
409
|
+
/**
|
|
410
|
+
* Compares two strings. Useful for Array.prototype.sort().
|
|
411
|
+
* @returns 1 if a > b, -1 if a < b, 0 if equal.
|
|
412
|
+
*/
|
|
413
|
+
compare(a: string, b: string): number;
|
|
29
414
|
};
|
|
30
415
|
export declare const japaneseFormal: {
|
|
416
|
+
/**
|
|
417
|
+
* Formats a numeric value into the specific CJK numeral system.
|
|
418
|
+
*
|
|
419
|
+
* @param value The number or bigint to format.
|
|
420
|
+
* @returns The formatted string representation in the respective CJK system.
|
|
421
|
+
*/
|
|
31
422
|
parse(value: NumberLike): string;
|
|
423
|
+
/**
|
|
424
|
+
* Adds multiple CJK numeric strings together.
|
|
425
|
+
* @param values The CJK numeric strings to add.
|
|
426
|
+
* @returns The sum of the CJK numeric strings.
|
|
427
|
+
*/
|
|
428
|
+
add(values: string[]): string;
|
|
429
|
+
/**
|
|
430
|
+
* Subtracts multiple CJK numeric strings from the first one.
|
|
431
|
+
* @param values The CJK numeric strings to subtract.
|
|
432
|
+
* @returns The difference of the CJK numeric strings.
|
|
433
|
+
*/
|
|
434
|
+
subtract(values: string[]): string;
|
|
435
|
+
/**
|
|
436
|
+
* Multiplies multiple CJK numeric strings together.
|
|
437
|
+
* @param values The CJK numeric strings to multiply.
|
|
438
|
+
* @returns The product of the CJK numeric strings.
|
|
439
|
+
*/
|
|
440
|
+
multiply(values: string[]): string;
|
|
441
|
+
/**
|
|
442
|
+
* Divides multiple CJK numeric strings from the first one.
|
|
443
|
+
* @param values The CJK numeric strings to divide.
|
|
444
|
+
* @returns The quotient of the CJK numeric strings.
|
|
445
|
+
*/
|
|
446
|
+
divide(values: string[]): string;
|
|
447
|
+
/**
|
|
448
|
+
* Calculates the remainder of the first string divided by the second.
|
|
449
|
+
*/
|
|
450
|
+
modulo(a: string, b: string): string;
|
|
451
|
+
/**
|
|
452
|
+
* Raises the first string to the power of the second string or a number.
|
|
453
|
+
*/
|
|
454
|
+
pow(base: string, exponent: string | number): string;
|
|
455
|
+
/**
|
|
456
|
+
* Returns the absolute value of the string.
|
|
457
|
+
*/
|
|
458
|
+
abs(value: string): string;
|
|
459
|
+
/**
|
|
460
|
+
* Compares two strings. Useful for Array.prototype.sort().
|
|
461
|
+
* @returns 1 if a > b, -1 if a < b, 0 if equal.
|
|
462
|
+
*/
|
|
463
|
+
compare(a: string, b: string): number;
|
|
32
464
|
};
|
|
33
465
|
export declare const japaneseInformal: {
|
|
466
|
+
/**
|
|
467
|
+
* Formats a numeric value into the specific CJK numeral system.
|
|
468
|
+
*
|
|
469
|
+
* @param value The number or bigint to format.
|
|
470
|
+
* @returns The formatted string representation in the respective CJK system.
|
|
471
|
+
*/
|
|
34
472
|
parse(value: NumberLike): string;
|
|
473
|
+
/**
|
|
474
|
+
* Adds multiple CJK numeric strings together.
|
|
475
|
+
* @param values The CJK numeric strings to add.
|
|
476
|
+
* @returns The sum of the CJK numeric strings.
|
|
477
|
+
*/
|
|
478
|
+
add(values: string[]): string;
|
|
479
|
+
/**
|
|
480
|
+
* Subtracts multiple CJK numeric strings from the first one.
|
|
481
|
+
* @param values The CJK numeric strings to subtract.
|
|
482
|
+
* @returns The difference of the CJK numeric strings.
|
|
483
|
+
*/
|
|
484
|
+
subtract(values: string[]): string;
|
|
485
|
+
/**
|
|
486
|
+
* Multiplies multiple CJK numeric strings together.
|
|
487
|
+
* @param values The CJK numeric strings to multiply.
|
|
488
|
+
* @returns The product of the CJK numeric strings.
|
|
489
|
+
*/
|
|
490
|
+
multiply(values: string[]): string;
|
|
491
|
+
/**
|
|
492
|
+
* Divides multiple CJK numeric strings from the first one.
|
|
493
|
+
* @param values The CJK numeric strings to divide.
|
|
494
|
+
* @returns The quotient of the CJK numeric strings.
|
|
495
|
+
*/
|
|
496
|
+
divide(values: string[]): string;
|
|
497
|
+
/**
|
|
498
|
+
* Calculates the remainder of the first string divided by the second.
|
|
499
|
+
*/
|
|
500
|
+
modulo(a: string, b: string): string;
|
|
501
|
+
/**
|
|
502
|
+
* Raises the first string to the power of the second string or a number.
|
|
503
|
+
*/
|
|
504
|
+
pow(base: string, exponent: string | number): string;
|
|
505
|
+
/**
|
|
506
|
+
* Returns the absolute value of the string.
|
|
507
|
+
*/
|
|
508
|
+
abs(value: string): string;
|
|
509
|
+
/**
|
|
510
|
+
* Compares two strings. Useful for Array.prototype.sort().
|
|
511
|
+
* @returns 1 if a > b, -1 if a < b, 0 if equal.
|
|
512
|
+
*/
|
|
513
|
+
compare(a: string, b: string): number;
|
|
35
514
|
};
|
|
36
515
|
export declare const cjkHeavenlyStem: {
|
|
516
|
+
/**
|
|
517
|
+
* Formats a numeric value into the corresponding character of the cyclic sequence.
|
|
518
|
+
*
|
|
519
|
+
* @param value The number or bigint to format.
|
|
520
|
+
* @param options Options defining how to handle sequence boundaries (e.g., 'fixed' or 'cyclic' mode).
|
|
521
|
+
* @returns The character mapped to the specific sequence position.
|
|
522
|
+
*/
|
|
37
523
|
parse(value: NumberLike, options?: SystemParseOptions): string;
|
|
38
524
|
};
|
|
39
525
|
export declare const cjkEarthlyBranch: {
|
|
526
|
+
/**
|
|
527
|
+
* Formats a numeric value into the corresponding character of the cyclic sequence.
|
|
528
|
+
*
|
|
529
|
+
* @param value The number or bigint to format.
|
|
530
|
+
* @param options Options defining how to handle sequence boundaries (e.g., 'fixed' or 'cyclic' mode).
|
|
531
|
+
* @returns The character mapped to the specific sequence position.
|
|
532
|
+
*/
|
|
40
533
|
parse(value: NumberLike, options?: SystemParseOptions): string;
|
|
41
534
|
};
|
|
42
535
|
export declare const hiragana: {
|
|
536
|
+
/**
|
|
537
|
+
* Formats a numeric value into the corresponding character of the cyclic sequence.
|
|
538
|
+
*
|
|
539
|
+
* @param value The number or bigint to format.
|
|
540
|
+
* @param options Options defining how to handle sequence boundaries (e.g., 'fixed' or 'cyclic' mode).
|
|
541
|
+
* @returns The character mapped to the specific sequence position.
|
|
542
|
+
*/
|
|
43
543
|
parse(value: NumberLike, options?: SystemParseOptions): string;
|
|
44
544
|
};
|
|
45
545
|
export declare const hiraganaIroha: {
|
|
546
|
+
/**
|
|
547
|
+
* Formats a numeric value into the corresponding character of the cyclic sequence.
|
|
548
|
+
*
|
|
549
|
+
* @param value The number or bigint to format.
|
|
550
|
+
* @param options Options defining how to handle sequence boundaries (e.g., 'fixed' or 'cyclic' mode).
|
|
551
|
+
* @returns The character mapped to the specific sequence position.
|
|
552
|
+
*/
|
|
46
553
|
parse(value: NumberLike, options?: SystemParseOptions): string;
|
|
47
554
|
};
|
|
48
555
|
export declare const katakana: {
|
|
556
|
+
/**
|
|
557
|
+
* Formats a numeric value into the corresponding character of the cyclic sequence.
|
|
558
|
+
*
|
|
559
|
+
* @param value The number or bigint to format.
|
|
560
|
+
* @param options Options defining how to handle sequence boundaries (e.g., 'fixed' or 'cyclic' mode).
|
|
561
|
+
* @returns The character mapped to the specific sequence position.
|
|
562
|
+
*/
|
|
49
563
|
parse(value: NumberLike, options?: SystemParseOptions): string;
|
|
50
564
|
};
|
|
51
565
|
export declare const katakanaIroha: {
|
|
566
|
+
/**
|
|
567
|
+
* Formats a numeric value into the corresponding character of the cyclic sequence.
|
|
568
|
+
*
|
|
569
|
+
* @param value The number or bigint to format.
|
|
570
|
+
* @param options Options defining how to handle sequence boundaries (e.g., 'fixed' or 'cyclic' mode).
|
|
571
|
+
* @returns The character mapped to the specific sequence position.
|
|
572
|
+
*/
|
|
52
573
|
parse(value: NumberLike, options?: SystemParseOptions): string;
|
|
53
574
|
};
|
|
54
575
|
export declare const systems: {
|
|
@@ -57,7 +578,7 @@ export declare const systems: {
|
|
|
57
578
|
koreanHangulFormal: readonly ["일", "이", "삼", "사", "오", "육", "칠", "팔", "구"];
|
|
58
579
|
koreanHanjaFormal: readonly ["壹", "貳", "參", "四", "五", "六", "七", "八", "九"];
|
|
59
580
|
koreanHanjaInformal: readonly ["一", "二", "三", "四", "五", "六", "七", "八", "九"];
|
|
60
|
-
japaneseFormal: readonly ["壱", "
|
|
581
|
+
japaneseFormal: readonly ["壱", "弍", "参", "四", "伍", "六", "七", "八", "九"];
|
|
61
582
|
japaneseInformal: readonly ["一", "二", "三", "四", "五", "六", "七", "八", "九"];
|
|
62
583
|
hiragana: readonly ["あ", "い", "う", "え", "お", "か", "き", "く", "け", "こ", "さ", "し", "す", "せ", "そ", "た", "ち", "つ", "て", "と", "な", "に", "ぬ", "ね", "の", "は", "ひ", "ふ", "へ", "ほ", "ま", "み", "む", "め", "も", "や", "ゆ", "よ", "ら", "り", "る", "れ", "ろ", "わ", "を", "ん"];
|
|
63
584
|
hiraganaIroha: readonly ["い", "ろ", "は", "に", "ほ", "へ", "と", "ち", "り", "ぬ", "る", "を", "わ", "か", "よ", "た", "れ", "そ", "つ", "ね", "な", "ら", "む", "う", "ゐ", "の", "お", "く", "や", "ま", "け", "ふ", "こ", "え", "て", "あ", "さ", "き", "ゆ", "め", "み", "し", "ゑ", "ひ", "も", "せ", "す"];
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,kBAAkB,EAClB,kBAAkB,EAClB,UAAU,EAEX,MAAM,YAAY,CAAC;AA4BpB,cAAc,YAAY,CAAC;AA8oB3B,eAAO,MAAM,MAAM;IACjB;;;;;;;;OAQG;iBACU,MAAM,YAAY,kBAAkB,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM;CAG7E,CAAC;AAEF,eAAO,MAAM,cAAc;IAvIvB;;;;;OAKG;iBACU,UAAU,GAAG,MAAM;IAMhC;;;;OAIG;gBACS,MAAM,EAAE,GAAG,MAAM;IAQ7B;;;;OAIG;qBACc,MAAM,EAAE,GAAG,MAAM;IAQlC;;;;OAIG;qBACc,MAAM,EAAE,GAAG,MAAM;IAQlC;;;;OAIG;mBACY,MAAM,EAAE,GAAG,MAAM;IAQhC;;OAEG;cACO,MAAM,KAAK,MAAM,GA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oClB,CAAC;AACrD,eAAO,MAAM,aAAa;IA5CtB;;;;;;OAMG;iBACU,UAAU,YAAW,kBAAkB,GAAQ,MAAM;CAqCP,CAAC;AAEhE,eAAO,MAAM,OAAO;;;;;;;;;;;;CAYnB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -34,6 +34,7 @@ const NORMALIZE_MAP = {
|
|
|
34
34
|
팔: "八",
|
|
35
35
|
구: "九",
|
|
36
36
|
壱: "一",
|
|
37
|
+
弍: "二",
|
|
37
38
|
弐: "二",
|
|
38
39
|
参: "三",
|
|
39
40
|
無量大數: "无量大数",
|
|
@@ -77,9 +78,10 @@ function normalizeInput(raw) {
|
|
|
77
78
|
return result;
|
|
78
79
|
}
|
|
79
80
|
function toBigInt(value) {
|
|
80
|
-
if (typeof value === "bigint")
|
|
81
|
+
if (typeof value === "bigint")
|
|
81
82
|
return value;
|
|
82
|
-
|
|
83
|
+
if (typeof value === "string")
|
|
84
|
+
return BigInt(value);
|
|
83
85
|
if (!Number.isFinite(value) || !Number.isInteger(value)) {
|
|
84
86
|
throw new RangeError("Expected an integer value");
|
|
85
87
|
}
|
|
@@ -163,7 +165,7 @@ function parseFractionDigits(raw) {
|
|
|
163
165
|
}
|
|
164
166
|
decimal += String(digit);
|
|
165
167
|
}
|
|
166
|
-
return
|
|
168
|
+
return decimal;
|
|
167
169
|
}
|
|
168
170
|
function toBestNumeric(value, preferBigInt) {
|
|
169
171
|
if (preferBigInt) {
|
|
@@ -223,7 +225,7 @@ function formatSection(section, set) {
|
|
|
223
225
|
pendingZero = false;
|
|
224
226
|
}
|
|
225
227
|
const isTenPosition = value === 10;
|
|
226
|
-
const canDropOne = isTenPosition && digit === 1 && output.length === 0;
|
|
228
|
+
const canDropOne = isTenPosition && digit === 1 && output.length === 0 && (set.dropTenOne ?? true);
|
|
227
229
|
if (!canDropOne) {
|
|
228
230
|
output += set.digits[digit - 1];
|
|
229
231
|
}
|
|
@@ -267,17 +269,15 @@ function formatChineseNumber(value, set) {
|
|
|
267
269
|
return negative ? `負${output}` : output;
|
|
268
270
|
}
|
|
269
271
|
function formatDecimal(value, set) {
|
|
270
|
-
if (!Number.isFinite(value)) {
|
|
272
|
+
if (typeof value === "number" && !Number.isFinite(value)) {
|
|
271
273
|
throw new RangeError("Expected a finite number");
|
|
272
274
|
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
const
|
|
277
|
-
const source = String(Math.abs(value));
|
|
278
|
-
const [intPart, fracPart] = source.split(".");
|
|
275
|
+
const source = String(value);
|
|
276
|
+
const negative = source.startsWith("-");
|
|
277
|
+
const absSource = negative ? source.slice(1) : source;
|
|
278
|
+
const [intPart = "0", fracPart] = absSource.split(".");
|
|
279
279
|
if (!fracPart) {
|
|
280
|
-
return formatChineseNumber(
|
|
280
|
+
return formatChineseNumber(BigInt(intPart), set);
|
|
281
281
|
}
|
|
282
282
|
const intText = formatChineseNumber(BigInt(intPart), set);
|
|
283
283
|
let fracText = "";
|
|
@@ -291,18 +291,35 @@ function formatDecimal(value, set) {
|
|
|
291
291
|
function parseValue(input, options = {}) {
|
|
292
292
|
const modeStem = options.heavenlyStemMode ?? "fixed";
|
|
293
293
|
const modeBranch = options.earthlyBranchMode ?? "fixed";
|
|
294
|
-
|
|
294
|
+
const explicit = options.explicitTyping;
|
|
295
|
+
if (explicit === "cjkHeavenlyStem") {
|
|
295
296
|
return parseCycle(input, STEMS, modeStem);
|
|
296
297
|
}
|
|
297
|
-
|
|
298
|
-
// Not a heavenly stem, continue to next parser.
|
|
299
|
-
}
|
|
300
|
-
try {
|
|
298
|
+
if (explicit === "cjkEarthlyBranch") {
|
|
301
299
|
return parseCycle(input, BRANCHES, modeBranch);
|
|
302
300
|
}
|
|
303
|
-
|
|
304
|
-
|
|
301
|
+
if (explicit === "hiragana") {
|
|
302
|
+
const idx = HIRAGANA.indexOf(input);
|
|
303
|
+
if (idx >= 0)
|
|
304
|
+
return idx + 1;
|
|
305
|
+
}
|
|
306
|
+
if (explicit === "hiraganaIroha") {
|
|
307
|
+
const idx = HIRAGANA_IROHA.indexOf(input);
|
|
308
|
+
if (idx >= 0)
|
|
309
|
+
return idx + 1;
|
|
310
|
+
}
|
|
311
|
+
if (explicit === "katakana") {
|
|
312
|
+
const idx = KATAKANA.indexOf(input);
|
|
313
|
+
if (idx >= 0)
|
|
314
|
+
return idx + 1;
|
|
305
315
|
}
|
|
316
|
+
if (explicit === "katakanaIroha") {
|
|
317
|
+
const idx = KATAKANA_IROHA.indexOf(input);
|
|
318
|
+
if (idx >= 0)
|
|
319
|
+
return idx + 1;
|
|
320
|
+
}
|
|
321
|
+
// Handle other explicit numeric systems by validating characters?
|
|
322
|
+
// Or just fall through if not a sequence symbol.
|
|
306
323
|
const sequenceValue = SEQUENCE_SYMBOL_TO_NUMBER[input];
|
|
307
324
|
if (sequenceValue !== undefined) {
|
|
308
325
|
return sequenceValue;
|
|
@@ -319,35 +336,225 @@ function parseValue(input, options = {}) {
|
|
|
319
336
|
if (body.includes(".")) {
|
|
320
337
|
const [intRaw, fracRaw = ""] = body.split(".");
|
|
321
338
|
const intValue = intRaw ? parseChineseNumber(intRaw) : 0n;
|
|
322
|
-
const
|
|
339
|
+
const fracDigits = parseFractionDigits(fracRaw);
|
|
340
|
+
if (options.mode === "exactDecimal") {
|
|
341
|
+
// Exact path: return a lossless decimal string.
|
|
342
|
+
const exact = `${intValue}.${fracDigits}`;
|
|
343
|
+
return negative ? `-${exact}` : exact;
|
|
344
|
+
}
|
|
345
|
+
// Legacy path: fall back to Number (may lose precision for very large integers).
|
|
323
346
|
if (intValue > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
324
|
-
throw new RangeError("Decimal parse does not support integer part above MAX_SAFE_INTEGER");
|
|
347
|
+
throw new RangeError("Decimal parse does not support integer part above MAX_SAFE_INTEGER. Use { mode: \"exactDecimal\" } to bypass.");
|
|
325
348
|
}
|
|
326
|
-
const composed = Number(intValue) +
|
|
349
|
+
const composed = Number(intValue) + Number(`0.${fracDigits}`);
|
|
327
350
|
return negative ? -composed : composed;
|
|
328
351
|
}
|
|
329
352
|
const parsed = parseChineseNumber(body);
|
|
330
353
|
const signed = negative ? -parsed : parsed;
|
|
331
|
-
return toBestNumeric(signed, options.
|
|
354
|
+
return toBestNumeric(signed, options.mode === "preferBigInt");
|
|
355
|
+
}
|
|
356
|
+
function toScaleFormat(val) {
|
|
357
|
+
const str = String(val);
|
|
358
|
+
const isNeg = str.startsWith("-");
|
|
359
|
+
const abs = isNeg ? str.slice(1) : str;
|
|
360
|
+
const parts = abs.split(".");
|
|
361
|
+
return {
|
|
362
|
+
intPart: parts[0] || "0",
|
|
363
|
+
fracPart: parts[1] || "",
|
|
364
|
+
isNeg,
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
function alignScales(a, b) {
|
|
368
|
+
const parsedA = toScaleFormat(a);
|
|
369
|
+
const parsedB = toScaleFormat(b);
|
|
370
|
+
const maxDec = Math.max(parsedA.fracPart.length, parsedB.fracPart.length);
|
|
371
|
+
const strA = parsedA.intPart + parsedA.fracPart.padEnd(maxDec, "0");
|
|
372
|
+
const strB = parsedB.intPart + parsedB.fracPart.padEnd(maxDec, "0");
|
|
373
|
+
const bigA = BigInt(strA) * (parsedA.isNeg ? -1n : 1n);
|
|
374
|
+
const bigB = BigInt(strB) * (parsedB.isNeg ? -1n : 1n);
|
|
375
|
+
return { bigA, bigB, scale: maxDec };
|
|
376
|
+
}
|
|
377
|
+
function applyScale(val, scale) {
|
|
378
|
+
let str = (val < 0n ? -val : val).toString();
|
|
379
|
+
if (scale === 0)
|
|
380
|
+
return (val < 0n ? "-" : "") + str;
|
|
381
|
+
str = str.padStart(scale + 1, "0");
|
|
382
|
+
const intPart = str.slice(0, -scale);
|
|
383
|
+
const fracPart = str.slice(-scale).replace(/0+$/, "");
|
|
384
|
+
const joined = fracPart ? `${intPart || "0"}.${fracPart}` : (intPart || "0");
|
|
385
|
+
return (val < 0n ? "-" : "") + joined;
|
|
386
|
+
}
|
|
387
|
+
function mixedAdd(a, b) {
|
|
388
|
+
const { bigA, bigB, scale } = alignScales(a, b);
|
|
389
|
+
return applyScale(bigA + bigB, scale);
|
|
390
|
+
}
|
|
391
|
+
function mixedSubtract(a, b) {
|
|
392
|
+
const { bigA, bigB, scale } = alignScales(a, b);
|
|
393
|
+
return applyScale(bigA - bigB, scale);
|
|
394
|
+
}
|
|
395
|
+
function mixedMultiply(a, b) {
|
|
396
|
+
const { bigA, bigB, scale } = alignScales(a, b);
|
|
397
|
+
return applyScale(bigA * bigB, scale * 2);
|
|
398
|
+
}
|
|
399
|
+
function mixedDivide(a, b) {
|
|
400
|
+
const { bigA, bigB } = alignScales(a, b);
|
|
401
|
+
if (bigB === 0n)
|
|
402
|
+
throw new RangeError("Division by zero");
|
|
403
|
+
const EXTRA = 16n;
|
|
404
|
+
const result = (bigA * (10n ** EXTRA)) / bigB;
|
|
405
|
+
return applyScale(result, Number(EXTRA));
|
|
406
|
+
}
|
|
407
|
+
function mixedModulo(a, b) {
|
|
408
|
+
const { bigA, bigB, scale } = alignScales(a, b);
|
|
409
|
+
return applyScale(bigA % bigB, scale);
|
|
410
|
+
}
|
|
411
|
+
function mixedPow(base, exponent) {
|
|
412
|
+
const parsedExp = toScaleFormat(exponent);
|
|
413
|
+
if (parsedExp.fracPart.length > 0)
|
|
414
|
+
return Number(base) ** Number(exponent);
|
|
415
|
+
const expNum = BigInt(parsedExp.intPart) * (parsedExp.isNeg ? -1n : 1n);
|
|
416
|
+
if (expNum < 0n)
|
|
417
|
+
return Number(base) ** Number(exponent);
|
|
418
|
+
const parsedBase = toScaleFormat(base);
|
|
419
|
+
const baseBig = BigInt(parsedBase.intPart + parsedBase.fracPart);
|
|
420
|
+
const scale = parsedBase.fracPart.length * Number(expNum);
|
|
421
|
+
const result = baseBig ** expNum;
|
|
422
|
+
return applyScale(parsedBase.isNeg && expNum % 2n !== 0n ? -result : result, scale);
|
|
423
|
+
}
|
|
424
|
+
function mixedCompare(a, b) {
|
|
425
|
+
const { bigA, bigB } = alignScales(a, b);
|
|
426
|
+
return bigA > bigB ? 1 : bigA < bigB ? -1 : 0;
|
|
332
427
|
}
|
|
333
428
|
function createSystem(set) {
|
|
334
429
|
return {
|
|
430
|
+
/**
|
|
431
|
+
* Formats a numeric value into the specific CJK numeral system.
|
|
432
|
+
*
|
|
433
|
+
* @param value The number or bigint to format.
|
|
434
|
+
* @returns The formatted string representation in the respective CJK system.
|
|
435
|
+
*/
|
|
335
436
|
parse(value) {
|
|
336
|
-
if (
|
|
437
|
+
if (String(value).includes(".")) {
|
|
337
438
|
return formatDecimal(value, set);
|
|
338
439
|
}
|
|
339
440
|
return formatChineseNumber(value, set);
|
|
340
441
|
},
|
|
442
|
+
/**
|
|
443
|
+
* Adds multiple CJK numeric strings together.
|
|
444
|
+
* @param values The CJK numeric strings to add.
|
|
445
|
+
* @returns The sum of the CJK numeric strings.
|
|
446
|
+
*/
|
|
447
|
+
add(values) {
|
|
448
|
+
if (values.length === 0) {
|
|
449
|
+
return set.zero;
|
|
450
|
+
}
|
|
451
|
+
const [first, ...rest] = values.map((v) => number.parse(v));
|
|
452
|
+
const sum = rest.reduce(mixedAdd, first);
|
|
453
|
+
return this.parse(sum);
|
|
454
|
+
},
|
|
455
|
+
/**
|
|
456
|
+
* Subtracts multiple CJK numeric strings from the first one.
|
|
457
|
+
* @param values The CJK numeric strings to subtract.
|
|
458
|
+
* @returns The difference of the CJK numeric strings.
|
|
459
|
+
*/
|
|
460
|
+
subtract(values) {
|
|
461
|
+
if (values.length === 0) {
|
|
462
|
+
return set.zero;
|
|
463
|
+
}
|
|
464
|
+
const [first, ...rest] = values.map((v) => number.parse(v));
|
|
465
|
+
const diff = rest.reduce(mixedSubtract, first);
|
|
466
|
+
return this.parse(diff);
|
|
467
|
+
},
|
|
468
|
+
/**
|
|
469
|
+
* Multiplies multiple CJK numeric strings together.
|
|
470
|
+
* @param values The CJK numeric strings to multiply.
|
|
471
|
+
* @returns The product of the CJK numeric strings.
|
|
472
|
+
*/
|
|
473
|
+
multiply(values) {
|
|
474
|
+
if (values.length === 0) {
|
|
475
|
+
return set.zero;
|
|
476
|
+
}
|
|
477
|
+
const [first, ...rest] = values.map((v) => number.parse(v));
|
|
478
|
+
const product = rest.reduce(mixedMultiply, first);
|
|
479
|
+
return this.parse(product);
|
|
480
|
+
},
|
|
481
|
+
/**
|
|
482
|
+
* Divides multiple CJK numeric strings from the first one.
|
|
483
|
+
* @param values The CJK numeric strings to divide.
|
|
484
|
+
* @returns The quotient of the CJK numeric strings.
|
|
485
|
+
*/
|
|
486
|
+
divide(values) {
|
|
487
|
+
if (values.length === 0) {
|
|
488
|
+
return set.zero;
|
|
489
|
+
}
|
|
490
|
+
const [first, ...rest] = values.map((v) => number.parse(v));
|
|
491
|
+
const quotient = rest.reduce(mixedDivide, first);
|
|
492
|
+
return this.parse(quotient);
|
|
493
|
+
},
|
|
494
|
+
/**
|
|
495
|
+
* Calculates the remainder of the first string divided by the second.
|
|
496
|
+
*/
|
|
497
|
+
modulo(a, b) {
|
|
498
|
+
const numA = number.parse(a);
|
|
499
|
+
const numB = number.parse(b);
|
|
500
|
+
return this.parse(mixedModulo(numA, numB));
|
|
501
|
+
},
|
|
502
|
+
/**
|
|
503
|
+
* Raises the first string to the power of the second string or a number.
|
|
504
|
+
*/
|
|
505
|
+
pow(base, exponent) {
|
|
506
|
+
const numBase = number.parse(base);
|
|
507
|
+
const numExp = typeof exponent === "string" ? number.parse(exponent) : exponent;
|
|
508
|
+
return this.parse(mixedPow(numBase, numExp));
|
|
509
|
+
},
|
|
510
|
+
/**
|
|
511
|
+
* Returns the absolute value of the string.
|
|
512
|
+
*/
|
|
513
|
+
abs(value) {
|
|
514
|
+
const num = number.parse(value);
|
|
515
|
+
if (typeof num === "bigint") {
|
|
516
|
+
return this.parse(num < 0n ? -num : num);
|
|
517
|
+
}
|
|
518
|
+
if (typeof num === "string") {
|
|
519
|
+
return this.parse(num.startsWith("-") ? num.slice(1) : num);
|
|
520
|
+
}
|
|
521
|
+
return this.parse(Math.abs(num));
|
|
522
|
+
},
|
|
523
|
+
/**
|
|
524
|
+
* Compares two strings. Useful for Array.prototype.sort().
|
|
525
|
+
* @returns 1 if a > b, -1 if a < b, 0 if equal.
|
|
526
|
+
*/
|
|
527
|
+
compare(a, b) {
|
|
528
|
+
const numA = number.parse(a);
|
|
529
|
+
const numB = number.parse(b);
|
|
530
|
+
return mixedCompare(numA, numB);
|
|
531
|
+
},
|
|
341
532
|
};
|
|
342
533
|
}
|
|
343
534
|
function createCyclicSystem(chars) {
|
|
344
535
|
return {
|
|
536
|
+
/**
|
|
537
|
+
* Formats a numeric value into the corresponding character of the cyclic sequence.
|
|
538
|
+
*
|
|
539
|
+
* @param value The number or bigint to format.
|
|
540
|
+
* @param options Options defining how to handle sequence boundaries (e.g., 'fixed' or 'cyclic' mode).
|
|
541
|
+
* @returns The character mapped to the specific sequence position.
|
|
542
|
+
*/
|
|
345
543
|
parse(value, options = {}) {
|
|
346
544
|
return fromCycle(value, chars, options.mode ?? "fixed");
|
|
347
545
|
},
|
|
348
546
|
};
|
|
349
547
|
}
|
|
350
548
|
export const number = {
|
|
549
|
+
/**
|
|
550
|
+
* Parses a CJK numeric string into a number, bigint, or exact decimal string.
|
|
551
|
+
*
|
|
552
|
+
* @param input The CJK numeric string to parse.
|
|
553
|
+
* @param options Options defining how to handle the parse.
|
|
554
|
+
* - `mode: "preferBigInt"` – return `bigint` for integers.
|
|
555
|
+
* - `mode: "exactDecimal"` – return decimals as lossless strings, bypassing float limits.
|
|
556
|
+
* @returns The parsed number, bigint, or exact decimal string.
|
|
557
|
+
*/
|
|
351
558
|
parse(input, options) {
|
|
352
559
|
return parseValue(input, options);
|
|
353
560
|
},
|
package/dist/types.d.ts
CHANGED
|
@@ -1,14 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Controls the cyclic mode of the heavenly stem and earthly branch.
|
|
3
|
+
* - `"fixed"` – always return fixed heavenly stem and earthly branch characters.
|
|
4
|
+
* - `"cyclic"` – return cyclic heavenly stem and earthly branch characters.
|
|
5
|
+
*/
|
|
1
6
|
export type CyclicMode = "fixed" | "cyclic";
|
|
7
|
+
/**
|
|
8
|
+
* Options for parsing CJK text into a number.
|
|
9
|
+
*/
|
|
2
10
|
export interface SystemParseOptions {
|
|
3
11
|
mode?: CyclicMode;
|
|
4
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Controls the numeric output type of `number.parse`.
|
|
15
|
+
* - `"number"` – always return a JS `number` (default).
|
|
16
|
+
* - `"preferBigInt"` – return `bigint` for integers; `number` only for decimals.
|
|
17
|
+
* - `"exactDecimal"` – return decimals as a lossless string (e.g. `"10000000000000000.5"`),
|
|
18
|
+
* bypassing JS float precision limits. Integers still return `bigint`.
|
|
19
|
+
*/
|
|
20
|
+
export type NumberMode = "number" | "preferBigInt" | "exactDecimal";
|
|
21
|
+
/**
|
|
22
|
+
* Controls the explicit typing of the output.
|
|
23
|
+
* - `"cjkIdeographic"` – always return CJK ideographic characters.
|
|
24
|
+
* - `"tradChineseInformal"` – always return traditional Chinese informal characters.
|
|
25
|
+
* - `"tradChineseFormal"` – always return traditional Chinese formal characters.
|
|
26
|
+
* - `"simpChineseInformal"` – always return simplified Chinese informal characters.
|
|
27
|
+
* - `"simpChineseFormal"` – always return simplified Chinese formal characters.
|
|
28
|
+
* - `"cjkHeavenlyStem"` – always return CJK heavenly stem characters.
|
|
29
|
+
* - `"cjkEarthlyBranch"` – always return CJK earthly branch characters.
|
|
30
|
+
* - `"koreanHangulFormal"` – always return Korean hangul formal characters.
|
|
31
|
+
* - `"koreanHanjaFormal"` – always return Korean hanja formal characters.
|
|
32
|
+
* - `"koreanHanjaInformal"` – always return Korean hanja informal characters.
|
|
33
|
+
* - `"japaneseFormal"` – always return Japanese formal characters.
|
|
34
|
+
* - `"japaneseInformal"` – always return Japanese informal characters.
|
|
35
|
+
* - `"hiragana"` – always return hiragana characters.
|
|
36
|
+
* - `"hiraganaIroha"` – always return hiragana iroha characters.
|
|
37
|
+
* - `"katakana"` – always return katakana characters.
|
|
38
|
+
* - `"katakanaIroha"` – always return katakana iroha characters.
|
|
39
|
+
*/
|
|
40
|
+
export type ExplicitTyping = "cjkIdeographic" | "tradChineseInformal" | "tradChineseFormal" | "simpChineseInformal" | "simpChineseFormal" | "cjkHeavenlyStem" | "cjkEarthlyBranch" | "koreanHangulFormal" | "koreanHanjaFormal" | "koreanHanjaInformal" | "japaneseFormal" | "japaneseInformal" | "hiragana" | "hiraganaIroha" | "katakana" | "katakanaIroha";
|
|
5
41
|
export interface NumberParseOptions {
|
|
42
|
+
/** Controls whether to reject unsupported characters early. Defaults to `false`. */
|
|
6
43
|
strict?: boolean;
|
|
7
|
-
|
|
44
|
+
/** Controls the numeric output type. Defaults to `"number"`. */
|
|
45
|
+
mode?: NumberMode;
|
|
46
|
+
/** Controls the heavenly stem mode. Defaults to `"fixed"`. */
|
|
8
47
|
heavenlyStemMode?: CyclicMode;
|
|
48
|
+
/** Controls the earthly branch mode. Defaults to `"fixed"`. */
|
|
9
49
|
earthlyBranchMode?: CyclicMode;
|
|
50
|
+
/**
|
|
51
|
+
* Controls the explicit typing of the output.
|
|
52
|
+
* - `"cjkIdeographic"` – always return CJK ideographic characters.
|
|
53
|
+
* - `"tradChineseInformal"` – always return traditional Chinese informal characters.
|
|
54
|
+
* - `"tradChineseFormal"` – always return traditional Chinese formal characters.
|
|
55
|
+
* - `"simpChineseInformal"` – always return simplified Chinese informal characters.
|
|
56
|
+
* - `"simpChineseFormal"` – always return simplified Chinese formal characters.
|
|
57
|
+
* - `"cjkHeavenlyStem"` – always return CJK heavenly stem characters.
|
|
58
|
+
* - `"cjkEarthlyBranch"` – always return CJK earthly branch characters.
|
|
59
|
+
* - `"koreanHangulFormal"` – always return Korean hangul formal characters.
|
|
60
|
+
* - `"koreanHanjaFormal"` – always return Korean hanja formal characters.
|
|
61
|
+
* - `"koreanHanjaInformal"` – always return Korean hanja informal characters.
|
|
62
|
+
* - `"japaneseFormal"` – always return Japanese formal characters.
|
|
63
|
+
* - `"japaneseInformal"` – always return Japanese informal characters.
|
|
64
|
+
* - `"hiragana"` – always return hiragana characters.
|
|
65
|
+
* - `"hiraganaIroha"` – always return hiragana iroha characters.
|
|
66
|
+
* - `"katakana"` – always return katakana characters.
|
|
67
|
+
* - `"katakanaIroha"` – always return katakana iroha characters.
|
|
68
|
+
*/
|
|
69
|
+
explicitTyping?: ExplicitTyping;
|
|
10
70
|
}
|
|
11
|
-
export type NumberLike = number | bigint;
|
|
71
|
+
export type NumberLike = number | bigint | string;
|
|
12
72
|
export type DigitArray9 = readonly [
|
|
13
73
|
string,
|
|
14
74
|
string,
|
|
@@ -26,5 +86,6 @@ export interface DigitSet {
|
|
|
26
86
|
digits: DigitArray9;
|
|
27
87
|
smallUnits: [string, string, string];
|
|
28
88
|
bigUnits: string[];
|
|
89
|
+
dropTenOne?: boolean;
|
|
29
90
|
}
|
|
30
91
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,QAAQ,CAAC;AAE5C,MAAM,WAAW,kBAAkB;IACjC,IAAI,CAAC,EAAE,UAAU,CAAC;CACnB;AAED,MAAM,WAAW,kBAAkB;IACjC,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,QAAQ,CAAC;AAE5C;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,IAAI,CAAC,EAAE,UAAU,CAAC;CACnB;AAED;;;;;;GAMG;AACH,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,cAAc,GAAG,cAAc,CAAC;AAEp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