numeric-quantity 2.1.0 → 3.1.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 +15 -3
- package/dist/cjs/numeric-quantity.cjs.development.js +349 -250
- package/dist/cjs/numeric-quantity.cjs.development.js.map +1 -1
- package/dist/cjs/numeric-quantity.cjs.production.js +1 -1
- package/dist/cjs/numeric-quantity.cjs.production.js.map +1 -1
- package/dist/numeric-quantity.iife.umd.min.js +2 -0
- package/dist/numeric-quantity.iife.umd.min.js.map +1 -0
- package/dist/numeric-quantity.legacy-esm.js +402 -230
- package/dist/numeric-quantity.legacy-esm.js.map +1 -1
- package/dist/numeric-quantity.mjs +338 -215
- package/dist/numeric-quantity.mjs.map +1 -1
- package/dist/numeric-quantity.production.mjs +1 -1
- package/dist/numeric-quantity.production.mjs.map +1 -1
- package/dist/types/constants.d.ts +10 -1
- package/dist/types/numericQuantity.d.ts +0 -1
- package/dist/types/types.d.ts +6 -0
- package/dist/types-esm/constants.d.mts +10 -1
- package/dist/types-esm/numericQuantity.d.mts +0 -1
- package/dist/types-esm/types.d.mts +6 -0
- package/package.json +16 -13
- package/dist/numeric-quantity.umd.min.js +0 -2
- package/dist/numeric-quantity.umd.min.js.map +0 -1
|
@@ -1,240 +1,412 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
//#region src/constants.ts
|
|
2
|
+
/**
|
|
3
|
+
* Unicode decimal digit block start code points.
|
|
4
|
+
* Each block contains 10 contiguous digits (0-9).
|
|
5
|
+
* This list covers all \p{Nd} (Decimal_Number) blocks through Unicode 17.0.
|
|
6
|
+
* The drift test in index.test.ts validates completeness against the JS engine.
|
|
7
|
+
*/
|
|
8
|
+
const decimalDigitBlockStarts = [
|
|
9
|
+
48,
|
|
10
|
+
1632,
|
|
11
|
+
1776,
|
|
12
|
+
1984,
|
|
13
|
+
2406,
|
|
14
|
+
2534,
|
|
15
|
+
2662,
|
|
16
|
+
2790,
|
|
17
|
+
2918,
|
|
18
|
+
3046,
|
|
19
|
+
3174,
|
|
20
|
+
3302,
|
|
21
|
+
3430,
|
|
22
|
+
3558,
|
|
23
|
+
3664,
|
|
24
|
+
3792,
|
|
25
|
+
3872,
|
|
26
|
+
4160,
|
|
27
|
+
4240,
|
|
28
|
+
6112,
|
|
29
|
+
6160,
|
|
30
|
+
6470,
|
|
31
|
+
6608,
|
|
32
|
+
6784,
|
|
33
|
+
6800,
|
|
34
|
+
6992,
|
|
35
|
+
7088,
|
|
36
|
+
7232,
|
|
37
|
+
7248,
|
|
38
|
+
42528,
|
|
39
|
+
43216,
|
|
40
|
+
43264,
|
|
41
|
+
43472,
|
|
42
|
+
43504,
|
|
43
|
+
43600,
|
|
44
|
+
44016,
|
|
45
|
+
65296,
|
|
46
|
+
66720,
|
|
47
|
+
68912,
|
|
48
|
+
68928,
|
|
49
|
+
69734,
|
|
50
|
+
69872,
|
|
51
|
+
69942,
|
|
52
|
+
70096,
|
|
53
|
+
70384,
|
|
54
|
+
70736,
|
|
55
|
+
70864,
|
|
56
|
+
71248,
|
|
57
|
+
71360,
|
|
58
|
+
71376,
|
|
59
|
+
71386,
|
|
60
|
+
71472,
|
|
61
|
+
71904,
|
|
62
|
+
72016,
|
|
63
|
+
72688,
|
|
64
|
+
72784,
|
|
65
|
+
73040,
|
|
66
|
+
73120,
|
|
67
|
+
73184,
|
|
68
|
+
73552,
|
|
69
|
+
90416,
|
|
70
|
+
92768,
|
|
71
|
+
92864,
|
|
72
|
+
93008,
|
|
73
|
+
93552,
|
|
74
|
+
118e3,
|
|
75
|
+
120782,
|
|
76
|
+
120792,
|
|
77
|
+
120802,
|
|
78
|
+
120812,
|
|
79
|
+
120822,
|
|
80
|
+
123200,
|
|
81
|
+
123632,
|
|
82
|
+
124144,
|
|
83
|
+
124401,
|
|
84
|
+
125264,
|
|
85
|
+
130032
|
|
86
|
+
];
|
|
87
|
+
/**
|
|
88
|
+
* Normalizes non-ASCII decimal digits to ASCII digits.
|
|
89
|
+
* Converts characters from Unicode decimal digit blocks (e.g., Arabic-Indic,
|
|
90
|
+
* Devanagari, Bengali) to their ASCII equivalents (0-9).
|
|
91
|
+
*
|
|
92
|
+
* All current Unicode \p{Nd} blocks are included in decimalDigitBlockStarts.
|
|
93
|
+
*/
|
|
94
|
+
const normalizeDigits = (str) => str.replace(/* @__PURE__ */ new RegExp("\\p{Nd}", "gu"), (ch) => {
|
|
95
|
+
const cp = ch.codePointAt(0);
|
|
96
|
+
if (cp <= 57) return ch;
|
|
97
|
+
let lo = 0;
|
|
98
|
+
let hi = decimalDigitBlockStarts.length - 1;
|
|
99
|
+
while (lo < hi) {
|
|
100
|
+
const mid = lo + hi + 1 >>> 1;
|
|
101
|
+
if (decimalDigitBlockStarts[mid] <= cp) lo = mid;
|
|
102
|
+
else hi = mid - 1;
|
|
103
|
+
}
|
|
104
|
+
return String(cp - decimalDigitBlockStarts[lo]);
|
|
105
|
+
});
|
|
106
|
+
/**
|
|
107
|
+
* Map of Unicode fraction code points to their ASCII equivalents.
|
|
108
|
+
*/
|
|
109
|
+
const vulgarFractionToAsciiMap = {
|
|
110
|
+
"¼": "1/4",
|
|
111
|
+
"½": "1/2",
|
|
112
|
+
"¾": "3/4",
|
|
113
|
+
"⅐": "1/7",
|
|
114
|
+
"⅑": "1/9",
|
|
115
|
+
"⅒": "1/10",
|
|
116
|
+
"⅓": "1/3",
|
|
117
|
+
"⅔": "2/3",
|
|
118
|
+
"⅕": "1/5",
|
|
119
|
+
"⅖": "2/5",
|
|
120
|
+
"⅗": "3/5",
|
|
121
|
+
"⅘": "4/5",
|
|
122
|
+
"⅙": "1/6",
|
|
123
|
+
"⅚": "5/6",
|
|
124
|
+
"⅛": "1/8",
|
|
125
|
+
"⅜": "3/8",
|
|
126
|
+
"⅝": "5/8",
|
|
127
|
+
"⅞": "7/8",
|
|
128
|
+
"⅟": "1/"
|
|
16
129
|
};
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
"
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
)
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
130
|
+
/**
|
|
131
|
+
* Captures the individual elements of a numeric string. Commas and underscores are allowed
|
|
132
|
+
* as separators, as long as they appear between digits and are not consecutive.
|
|
133
|
+
*
|
|
134
|
+
* Capture groups:
|
|
135
|
+
*
|
|
136
|
+
* | # | Description | Example(s) |
|
|
137
|
+
* | --- | ------------------------------------------------ | ------------------------------------------------------------------- |
|
|
138
|
+
* | `0` | entire string | `"2 1/3"` from `"2 1/3"` |
|
|
139
|
+
* | `1` | "negative" dash | `"-"` from `"-2 1/3"` |
|
|
140
|
+
* | `2` | whole number or numerator | `"2"` from `"2 1/3"`; `"1"` from `"1/3"` |
|
|
141
|
+
* | `3` | entire fraction, decimal portion, or denominator | `" 1/3"` from `"2 1/3"`; `".33"` from `"2.33"`; `"/3"` from `"1/3"` |
|
|
142
|
+
*
|
|
143
|
+
* _Capture group 2 may include comma/underscore separators._
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
*
|
|
147
|
+
* ```ts
|
|
148
|
+
* numericRegex.exec("1") // [ "1", "1", null, null ]
|
|
149
|
+
* numericRegex.exec("1.23") // [ "1.23", "1", ".23", null ]
|
|
150
|
+
* numericRegex.exec("1 2/3") // [ "1 2/3", "1", " 2/3", " 2" ]
|
|
151
|
+
* numericRegex.exec("2/3") // [ "2/3", "2", "/3", null ]
|
|
152
|
+
* numericRegex.exec("2 / 3") // [ "2 / 3", "2", "/ 3", null ]
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
const numericRegex = /^(?=-?\s*\.\d|-?\s*\d)(-)?\s*((?:\d(?:[,_]\d|\d)*)*)(([eE][+-]?\d(?:[,_]\d|\d)*)?|\.\d(?:[,_]\d|\d)*([eE][+-]?\d(?:[,_]\d|\d)*)?|(\s+\d(?:[,_]\d|\d)*\s*)?\s*\/\s*\d(?:[,_]\d|\d)*)?$/;
|
|
156
|
+
/**
|
|
157
|
+
* Same as {@link numericRegex}, but allows (and ignores) trailing invalid characters.
|
|
158
|
+
*/
|
|
159
|
+
const numericRegexWithTrailingInvalid = /^(?=-?\s*\.\d|-?\s*\d)(-)?\s*((?:\d(?:[,_]\d|\d)*)*)(([eE][+-]?\d(?:[,_]\d|\d)*)?|\.\d(?:[,_]\d|\d)*([eE][+-]?\d(?:[,_]\d|\d)*)?|(\s+\d(?:[,_]\d|\d)*\s*)?\s*\/\s*\d(?:[,_]\d|\d)*)?(?:\s*[^.\d/].*)?/;
|
|
160
|
+
/**
|
|
161
|
+
* Captures any Unicode vulgar fractions.
|
|
162
|
+
*/
|
|
163
|
+
const vulgarFractionsRegex = /([¼½¾⅐⅑⅒⅓⅔⅕⅖⅗⅘⅙⅚⅛⅜⅝⅞⅟}])/g;
|
|
164
|
+
/**
|
|
165
|
+
* Map of Roman numeral sequences to their decimal equivalents.
|
|
166
|
+
*/
|
|
167
|
+
const romanNumeralValues = {
|
|
168
|
+
MMM: 3e3,
|
|
169
|
+
MM: 2e3,
|
|
170
|
+
M: 1e3,
|
|
171
|
+
CM: 900,
|
|
172
|
+
DCCC: 800,
|
|
173
|
+
DCC: 700,
|
|
174
|
+
DC: 600,
|
|
175
|
+
D: 500,
|
|
176
|
+
CD: 400,
|
|
177
|
+
CCC: 300,
|
|
178
|
+
CC: 200,
|
|
179
|
+
C: 100,
|
|
180
|
+
XC: 90,
|
|
181
|
+
LXXX: 80,
|
|
182
|
+
LXX: 70,
|
|
183
|
+
LX: 60,
|
|
184
|
+
L: 50,
|
|
185
|
+
XL: 40,
|
|
186
|
+
XXX: 30,
|
|
187
|
+
XX: 20,
|
|
188
|
+
XII: 12,
|
|
189
|
+
XI: 11,
|
|
190
|
+
X: 10,
|
|
191
|
+
IX: 9,
|
|
192
|
+
VIII: 8,
|
|
193
|
+
VII: 7,
|
|
194
|
+
VI: 6,
|
|
195
|
+
V: 5,
|
|
196
|
+
IV: 4,
|
|
197
|
+
III: 3,
|
|
198
|
+
II: 2,
|
|
199
|
+
I: 1
|
|
82
200
|
};
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
"\u2171": "II",
|
|
120
|
-
// Small Roman Numeral Three (U+2172)
|
|
121
|
-
"\u2172": "III",
|
|
122
|
-
// Small Roman Numeral Four (U+2173)
|
|
123
|
-
"\u2173": "IV",
|
|
124
|
-
// Small Roman Numeral Five (U+2174)
|
|
125
|
-
"\u2174": "V",
|
|
126
|
-
// Small Roman Numeral Six (U+2175)
|
|
127
|
-
"\u2175": "VI",
|
|
128
|
-
// Small Roman Numeral Seven (U+2176)
|
|
129
|
-
"\u2176": "VII",
|
|
130
|
-
// Small Roman Numeral Eight (U+2177)
|
|
131
|
-
"\u2177": "VIII",
|
|
132
|
-
// Small Roman Numeral Nine (U+2178)
|
|
133
|
-
"\u2178": "IX",
|
|
134
|
-
// Small Roman Numeral Ten (U+2179)
|
|
135
|
-
"\u2179": "X",
|
|
136
|
-
// Small Roman Numeral Eleven (U+217A)
|
|
137
|
-
"\u217A": "XI",
|
|
138
|
-
// Small Roman Numeral Twelve (U+217B)
|
|
139
|
-
"\u217B": "XII",
|
|
140
|
-
// Small Roman Numeral Fifty (U+217C)
|
|
141
|
-
"\u217C": "L",
|
|
142
|
-
// Small Roman Numeral One Hundred (U+217D)
|
|
143
|
-
"\u217D": "C",
|
|
144
|
-
// Small Roman Numeral Five Hundred (U+217E)
|
|
145
|
-
"\u217E": "D",
|
|
146
|
-
// Small Roman Numeral One Thousand (U+217F)
|
|
147
|
-
"\u217F": "M"
|
|
201
|
+
/**
|
|
202
|
+
* Map of Unicode Roman numeral code points to their ASCII equivalents.
|
|
203
|
+
*/
|
|
204
|
+
const romanNumeralUnicodeToAsciiMap = {
|
|
205
|
+
Ⅰ: "I",
|
|
206
|
+
Ⅱ: "II",
|
|
207
|
+
Ⅲ: "III",
|
|
208
|
+
Ⅳ: "IV",
|
|
209
|
+
Ⅴ: "V",
|
|
210
|
+
Ⅵ: "VI",
|
|
211
|
+
Ⅶ: "VII",
|
|
212
|
+
Ⅷ: "VIII",
|
|
213
|
+
Ⅸ: "IX",
|
|
214
|
+
Ⅹ: "X",
|
|
215
|
+
Ⅺ: "XI",
|
|
216
|
+
Ⅻ: "XII",
|
|
217
|
+
Ⅼ: "L",
|
|
218
|
+
Ⅽ: "C",
|
|
219
|
+
Ⅾ: "D",
|
|
220
|
+
Ⅿ: "M",
|
|
221
|
+
ⅰ: "I",
|
|
222
|
+
ⅱ: "II",
|
|
223
|
+
ⅲ: "III",
|
|
224
|
+
ⅳ: "IV",
|
|
225
|
+
ⅴ: "V",
|
|
226
|
+
ⅵ: "VI",
|
|
227
|
+
ⅶ: "VII",
|
|
228
|
+
ⅷ: "VIII",
|
|
229
|
+
ⅸ: "IX",
|
|
230
|
+
ⅹ: "X",
|
|
231
|
+
ⅺ: "XI",
|
|
232
|
+
ⅻ: "XII",
|
|
233
|
+
ⅼ: "L",
|
|
234
|
+
ⅽ: "C",
|
|
235
|
+
ⅾ: "D",
|
|
236
|
+
ⅿ: "M"
|
|
148
237
|
};
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
);
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
238
|
+
/**
|
|
239
|
+
* Captures all Unicode Roman numeral code points.
|
|
240
|
+
*/
|
|
241
|
+
const romanNumeralUnicodeRegex = /([ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩⅪⅫⅬⅭⅮⅯⅰⅱⅲⅳⅴⅵⅶⅷⅸⅹⅺⅻⅼⅽⅾⅿ])/gi;
|
|
242
|
+
/**
|
|
243
|
+
* Captures a valid Roman numeral sequence.
|
|
244
|
+
*
|
|
245
|
+
* Capture groups:
|
|
246
|
+
*
|
|
247
|
+
* | # | Description | Example |
|
|
248
|
+
* | --- | --------------- | ------------------------ |
|
|
249
|
+
* | `0` | Entire string | "MCCXIV" from "MCCXIV" |
|
|
250
|
+
* | `1` | Thousands | "M" from "MCCXIV" |
|
|
251
|
+
* | `2` | Hundreds | "CC" from "MCCXIV" |
|
|
252
|
+
* | `3` | Tens | "X" from "MCCXIV" |
|
|
253
|
+
* | `4` | Ones | "IV" from "MCCXIV" |
|
|
254
|
+
*
|
|
255
|
+
* @example
|
|
256
|
+
*
|
|
257
|
+
* ```ts
|
|
258
|
+
* romanNumeralRegex.exec("M") // [ "M", "M", "", "", "" ]
|
|
259
|
+
* romanNumeralRegex.exec("XII") // [ "XII", "", "", "X", "II" ]
|
|
260
|
+
* romanNumeralRegex.exec("MCCXIV") // [ "MCCXIV", "M", "CC", "X", "IV" ]
|
|
261
|
+
* ```
|
|
262
|
+
*/
|
|
263
|
+
const romanNumeralRegex = /^(?=[MDCLXVI])(M{0,3})(C[MD]|D?C{0,3})(X[CL]|L?X{0,3})(I[XV]|V?I{0,3})$/i;
|
|
264
|
+
/**
|
|
265
|
+
* Default options for {@link numericQuantity}.
|
|
266
|
+
*/
|
|
267
|
+
const defaultOptions = {
|
|
268
|
+
round: 3,
|
|
269
|
+
allowTrailingInvalid: false,
|
|
270
|
+
romanNumerals: false,
|
|
271
|
+
bigIntOnOverflow: false,
|
|
272
|
+
decimalSeparator: "."
|
|
159
273
|
};
|
|
160
274
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
275
|
+
//#endregion
|
|
276
|
+
//#region src/parseRomanNumerals.ts
|
|
277
|
+
/**
|
|
278
|
+
* Converts a string of Roman numerals to a number, like `parseInt`
|
|
279
|
+
* for Roman numerals. Uses modern, strict rules (only 1 to 3999).
|
|
280
|
+
*
|
|
281
|
+
* The string can include ASCII representations of Roman numerals
|
|
282
|
+
* or Unicode Roman numeral code points (`U+2160` through `U+217F`).
|
|
283
|
+
*/
|
|
284
|
+
const parseRomanNumerals = (romanNumerals) => {
|
|
285
|
+
var _romanNumeralValues, _romanNumeralValues2, _romanNumeralValues3, _romanNumeralValues4;
|
|
286
|
+
const normalized = `${romanNumerals}`.replace(romanNumeralUnicodeRegex, (_m, rn) => romanNumeralUnicodeToAsciiMap[rn]).toUpperCase();
|
|
287
|
+
const regexResult = romanNumeralRegex.exec(normalized);
|
|
288
|
+
if (!regexResult) return NaN;
|
|
289
|
+
const [, thousands, hundreds, tens, ones] = regexResult;
|
|
290
|
+
return ((_romanNumeralValues = romanNumeralValues[thousands]) !== null && _romanNumeralValues !== void 0 ? _romanNumeralValues : 0) + ((_romanNumeralValues2 = romanNumeralValues[hundreds]) !== null && _romanNumeralValues2 !== void 0 ? _romanNumeralValues2 : 0) + ((_romanNumeralValues3 = romanNumeralValues[tens]) !== null && _romanNumeralValues3 !== void 0 ? _romanNumeralValues3 : 0) + ((_romanNumeralValues4 = romanNumeralValues[ones]) !== null && _romanNumeralValues4 !== void 0 ? _romanNumeralValues4 : 0);
|
|
174
291
|
};
|
|
175
292
|
|
|
176
|
-
|
|
177
|
-
|
|
293
|
+
//#endregion
|
|
294
|
+
//#region \0@oxc-project+runtime@0.112.0/helpers/typeof.js
|
|
295
|
+
function _typeof(o) {
|
|
296
|
+
"@babel/helpers - typeof";
|
|
297
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
298
|
+
return typeof o;
|
|
299
|
+
} : function(o) {
|
|
300
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
301
|
+
}, _typeof(o);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
//#endregion
|
|
305
|
+
//#region \0@oxc-project+runtime@0.112.0/helpers/toPrimitive.js
|
|
306
|
+
function toPrimitive(t, r) {
|
|
307
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
308
|
+
var e = t[Symbol.toPrimitive];
|
|
309
|
+
if (void 0 !== e) {
|
|
310
|
+
var i = e.call(t, r || "default");
|
|
311
|
+
if ("object" != _typeof(i)) return i;
|
|
312
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
313
|
+
}
|
|
314
|
+
return ("string" === r ? String : Number)(t);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
//#endregion
|
|
318
|
+
//#region \0@oxc-project+runtime@0.112.0/helpers/toPropertyKey.js
|
|
319
|
+
function toPropertyKey(t) {
|
|
320
|
+
var i = toPrimitive(t, "string");
|
|
321
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
//#endregion
|
|
325
|
+
//#region \0@oxc-project+runtime@0.112.0/helpers/defineProperty.js
|
|
326
|
+
function _defineProperty(e, r, t) {
|
|
327
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
328
|
+
value: t,
|
|
329
|
+
enumerable: !0,
|
|
330
|
+
configurable: !0,
|
|
331
|
+
writable: !0
|
|
332
|
+
}) : e[r] = t, e;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
//#endregion
|
|
336
|
+
//#region \0@oxc-project+runtime@0.112.0/helpers/objectSpread2.js
|
|
337
|
+
function ownKeys(e, r) {
|
|
338
|
+
var t = Object.keys(e);
|
|
339
|
+
if (Object.getOwnPropertySymbols) {
|
|
340
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
341
|
+
r && (o = o.filter(function(r) {
|
|
342
|
+
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
343
|
+
})), t.push.apply(t, o);
|
|
344
|
+
}
|
|
345
|
+
return t;
|
|
346
|
+
}
|
|
347
|
+
function _objectSpread2(e) {
|
|
348
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
349
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
350
|
+
r % 2 ? ownKeys(Object(t), !0).forEach(function(r) {
|
|
351
|
+
_defineProperty(e, r, t[r]);
|
|
352
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r) {
|
|
353
|
+
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
return e;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
//#endregion
|
|
360
|
+
//#region src/numericQuantity.ts
|
|
361
|
+
const spaceThenSlashRegex = /^\s*\//;
|
|
178
362
|
function numericQuantity(quantity, options = defaultOptions) {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
}
|
|
225
|
-
return dash ? finalResult * -1 : finalResult;
|
|
363
|
+
if (typeof quantity === "number" || typeof quantity === "bigint") return quantity;
|
|
364
|
+
let finalResult = NaN;
|
|
365
|
+
const quantityAsString = normalizeDigits(`${quantity}`.replace(vulgarFractionsRegex, (_m, vf) => ` ${vulgarFractionToAsciiMap[vf]}`).replace("⁄", "/").trim());
|
|
366
|
+
if (quantityAsString.length === 0) return NaN;
|
|
367
|
+
const opts = _objectSpread2(_objectSpread2({}, defaultOptions), options);
|
|
368
|
+
let normalizedString = quantityAsString;
|
|
369
|
+
if (opts.decimalSeparator === ",") {
|
|
370
|
+
const commaCount = (quantityAsString.match(/,/g) || []).length;
|
|
371
|
+
if (commaCount === 1) normalizedString = quantityAsString.replaceAll(".", "_").replace(",", ".");
|
|
372
|
+
else if (commaCount > 1) {
|
|
373
|
+
if (!opts.allowTrailingInvalid) return NaN;
|
|
374
|
+
const firstCommaIndex = quantityAsString.indexOf(",");
|
|
375
|
+
const secondCommaIndex = quantityAsString.indexOf(",", firstCommaIndex + 1);
|
|
376
|
+
const beforeSecondComma = quantityAsString.substring(0, secondCommaIndex).replaceAll(".", "_").replace(",", ".");
|
|
377
|
+
const afterSecondComma = quantityAsString.substring(secondCommaIndex + 1);
|
|
378
|
+
normalizedString = opts.allowTrailingInvalid ? beforeSecondComma + "&" + afterSecondComma : beforeSecondComma;
|
|
379
|
+
} else normalizedString = quantityAsString.replaceAll(".", "_");
|
|
380
|
+
}
|
|
381
|
+
const regexResult = (opts.allowTrailingInvalid ? numericRegexWithTrailingInvalid : numericRegex).exec(normalizedString);
|
|
382
|
+
if (!regexResult) return opts.romanNumerals ? parseRomanNumerals(quantityAsString) : NaN;
|
|
383
|
+
const [, dash, ng1temp, ng2temp] = regexResult;
|
|
384
|
+
const numberGroup1 = ng1temp.replaceAll(",", "").replaceAll("_", "");
|
|
385
|
+
const numberGroup2 = ng2temp === null || ng2temp === void 0 ? void 0 : ng2temp.replaceAll(",", "").replaceAll("_", "");
|
|
386
|
+
if (!numberGroup1 && numberGroup2 && numberGroup2.startsWith(".")) finalResult = 0;
|
|
387
|
+
else {
|
|
388
|
+
if (opts.bigIntOnOverflow) {
|
|
389
|
+
const asBigInt = dash ? BigInt(`-${numberGroup1}`) : BigInt(numberGroup1);
|
|
390
|
+
if (asBigInt > BigInt(Number.MAX_SAFE_INTEGER) || asBigInt < BigInt(Number.MIN_SAFE_INTEGER)) return asBigInt;
|
|
391
|
+
}
|
|
392
|
+
finalResult = parseInt(numberGroup1);
|
|
393
|
+
}
|
|
394
|
+
if (!numberGroup2) return dash ? finalResult * -1 : finalResult;
|
|
395
|
+
const roundingFactor = opts.round === false ? NaN : parseFloat(`1e${Math.floor(Math.max(0, opts.round))}`);
|
|
396
|
+
if (numberGroup2.startsWith(".") || numberGroup2.startsWith("e") || numberGroup2.startsWith("E")) {
|
|
397
|
+
const decimalValue = parseFloat(`${finalResult}${numberGroup2}`);
|
|
398
|
+
finalResult = isNaN(roundingFactor) ? decimalValue : Math.round(decimalValue * roundingFactor) / roundingFactor;
|
|
399
|
+
} else if (spaceThenSlashRegex.test(numberGroup2)) {
|
|
400
|
+
const numerator = parseInt(numberGroup1);
|
|
401
|
+
const denominator = parseInt(numberGroup2.replace("/", ""));
|
|
402
|
+
finalResult = isNaN(roundingFactor) ? numerator / denominator : Math.round(numerator * roundingFactor / denominator) / roundingFactor;
|
|
403
|
+
} else {
|
|
404
|
+
const [numerator, denominator] = numberGroup2.split("/").map((v) => parseInt(v));
|
|
405
|
+
finalResult += isNaN(roundingFactor) ? numerator / denominator : Math.round(numerator * roundingFactor / denominator) / roundingFactor;
|
|
406
|
+
}
|
|
407
|
+
return dash ? finalResult * -1 : finalResult;
|
|
226
408
|
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
numericRegex,
|
|
231
|
-
numericRegexWithTrailingInvalid,
|
|
232
|
-
parseRomanNumerals,
|
|
233
|
-
romanNumeralRegex,
|
|
234
|
-
romanNumeralUnicodeRegex,
|
|
235
|
-
romanNumeralUnicodeToAsciiMap,
|
|
236
|
-
romanNumeralValues,
|
|
237
|
-
vulgarFractionToAsciiMap,
|
|
238
|
-
vulgarFractionsRegex
|
|
239
|
-
};
|
|
409
|
+
|
|
410
|
+
//#endregion
|
|
411
|
+
export { defaultOptions, normalizeDigits, numericQuantity, numericRegex, numericRegexWithTrailingInvalid, parseRomanNumerals, romanNumeralRegex, romanNumeralUnicodeRegex, romanNumeralUnicodeToAsciiMap, romanNumeralValues, vulgarFractionToAsciiMap, vulgarFractionsRegex };
|
|
240
412
|
//# sourceMappingURL=numeric-quantity.legacy-esm.js.map
|