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