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,225 +1,348 @@
1
- // src/constants.ts
2
- var vulgarFractionToAsciiMap = {
3
- "\xBC": "1/4",
4
- "\xBD": "1/2",
5
- "\xBE": "3/4",
6
- "\u2150": "1/7",
7
- "\u2151": "1/9",
8
- "\u2152": "1/10",
9
- "\u2153": "1/3",
10
- "\u2154": "2/3",
11
- "\u2155": "1/5",
12
- "\u2156": "2/5",
13
- "\u2157": "3/5",
14
- "\u2158": "4/5",
15
- "\u2159": "1/6",
16
- "\u215A": "5/6",
17
- "\u215B": "1/8",
18
- "\u215C": "3/8",
19
- "\u215D": "5/8",
20
- "\u215E": "7/8",
21
- "\u215F": "1/"
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(/\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/"
22
129
  };
23
- 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)?)?$/;
24
- var numericRegexWithTrailingInvalid = new RegExp(
25
- numericRegex.source.replace(/\$$/, "(?:\\s*[^\\.\\d\\/].*)?")
26
- );
27
- var vulgarFractionsRegex = new RegExp(
28
- `(${Object.keys(vulgarFractionToAsciiMap).join("|")})`
29
- );
30
- var romanNumeralValues = {
31
- MMM: 3e3,
32
- MM: 2e3,
33
- M: 1e3,
34
- CM: 900,
35
- DCCC: 800,
36
- DCC: 700,
37
- DC: 600,
38
- D: 500,
39
- CD: 400,
40
- CCC: 300,
41
- CC: 200,
42
- C: 100,
43
- XC: 90,
44
- LXXX: 80,
45
- LXX: 70,
46
- LX: 60,
47
- L: 50,
48
- XL: 40,
49
- XXX: 30,
50
- XX: 20,
51
- XII: 12,
52
- // only here for tests; not used in practice
53
- XI: 11,
54
- // only here for tests; not used in practice
55
- X: 10,
56
- IX: 9,
57
- VIII: 8,
58
- VII: 7,
59
- VI: 6,
60
- V: 5,
61
- IV: 4,
62
- III: 3,
63
- II: 2,
64
- I: 1
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
65
200
  };
66
- var romanNumeralUnicodeToAsciiMap = {
67
- // Roman Numeral One (U+2160)
68
- "\u2160": "I",
69
- // Roman Numeral Two (U+2161)
70
- "\u2161": "II",
71
- // Roman Numeral Three (U+2162)
72
- "\u2162": "III",
73
- // Roman Numeral Four (U+2163)
74
- "\u2163": "IV",
75
- // Roman Numeral Five (U+2164)
76
- "\u2164": "V",
77
- // Roman Numeral Six (U+2165)
78
- "\u2165": "VI",
79
- // Roman Numeral Seven (U+2166)
80
- "\u2166": "VII",
81
- // Roman Numeral Eight (U+2167)
82
- "\u2167": "VIII",
83
- // Roman Numeral Nine (U+2168)
84
- "\u2168": "IX",
85
- // Roman Numeral Ten (U+2169)
86
- "\u2169": "X",
87
- // Roman Numeral Eleven (U+216A)
88
- "\u216A": "XI",
89
- // Roman Numeral Twelve (U+216B)
90
- "\u216B": "XII",
91
- // Roman Numeral Fifty (U+216C)
92
- "\u216C": "L",
93
- // Roman Numeral One Hundred (U+216D)
94
- "\u216D": "C",
95
- // Roman Numeral Five Hundred (U+216E)
96
- "\u216E": "D",
97
- // Roman Numeral One Thousand (U+216F)
98
- "\u216F": "M",
99
- // Small Roman Numeral One (U+2170)
100
- "\u2170": "I",
101
- // Small Roman Numeral Two (U+2171)
102
- "\u2171": "II",
103
- // Small Roman Numeral Three (U+2172)
104
- "\u2172": "III",
105
- // Small Roman Numeral Four (U+2173)
106
- "\u2173": "IV",
107
- // Small Roman Numeral Five (U+2174)
108
- "\u2174": "V",
109
- // Small Roman Numeral Six (U+2175)
110
- "\u2175": "VI",
111
- // Small Roman Numeral Seven (U+2176)
112
- "\u2176": "VII",
113
- // Small Roman Numeral Eight (U+2177)
114
- "\u2177": "VIII",
115
- // Small Roman Numeral Nine (U+2178)
116
- "\u2178": "IX",
117
- // Small Roman Numeral Ten (U+2179)
118
- "\u2179": "X",
119
- // Small Roman Numeral Eleven (U+217A)
120
- "\u217A": "XI",
121
- // Small Roman Numeral Twelve (U+217B)
122
- "\u217B": "XII",
123
- // Small Roman Numeral Fifty (U+217C)
124
- "\u217C": "L",
125
- // Small Roman Numeral One Hundred (U+217D)
126
- "\u217D": "C",
127
- // Small Roman Numeral Five Hundred (U+217E)
128
- "\u217E": "D",
129
- // Small Roman Numeral One Thousand (U+217F)
130
- "\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"
131
237
  };
132
- var romanNumeralUnicodeRegex = new RegExp(
133
- `(${Object.keys(romanNumeralUnicodeToAsciiMap).join("|")})`,
134
- "gi"
135
- );
136
- 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;
137
- var defaultOptions = {
138
- round: 3,
139
- allowTrailingInvalid: false,
140
- romanNumerals: false,
141
- bigIntOnOverflow: false
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: "."
142
273
  };
143
274
 
144
- // src/parseRomanNumerals.ts
145
- var parseRomanNumerals = (romanNumerals) => {
146
- const normalized = `${romanNumerals}`.replace(
147
- romanNumeralUnicodeRegex,
148
- (_m, rn) => romanNumeralUnicodeToAsciiMap[rn]
149
- ).toUpperCase();
150
- const regexResult = romanNumeralRegex.exec(normalized);
151
- if (!regexResult) {
152
- return NaN;
153
- }
154
- const [, thousands, hundreds, tens, ones] = regexResult;
155
- return (romanNumeralValues[thousands] ?? 0) + (romanNumeralValues[hundreds] ?? 0) + (romanNumeralValues[tens] ?? 0) + (romanNumeralValues[ones] ?? 0);
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
+ const normalized = `${romanNumerals}`.replace(romanNumeralUnicodeRegex, (_m, rn) => romanNumeralUnicodeToAsciiMap[rn]).toUpperCase();
286
+ const regexResult = romanNumeralRegex.exec(normalized);
287
+ if (!regexResult) return NaN;
288
+ const [, thousands, hundreds, tens, ones] = regexResult;
289
+ return (romanNumeralValues[thousands] ?? 0) + (romanNumeralValues[hundreds] ?? 0) + (romanNumeralValues[tens] ?? 0) + (romanNumeralValues[ones] ?? 0);
156
290
  };
157
291
 
158
- // src/numericQuantity.ts
159
- var spaceThenSlashRegex = /^\s*\//;
292
+ //#endregion
293
+ //#region src/numericQuantity.ts
294
+ const spaceThenSlashRegex = /^\s*\//;
160
295
  function numericQuantity(quantity, options = defaultOptions) {
161
- if (typeof quantity === "number" || typeof quantity === "bigint") {
162
- return quantity;
163
- }
164
- let finalResult = NaN;
165
- const quantityAsString = `${quantity}`.replace(
166
- vulgarFractionsRegex,
167
- (_m, vf) => ` ${vulgarFractionToAsciiMap[vf]}`
168
- ).replace("\u2044", "/").trim();
169
- if (quantityAsString.length === 0) {
170
- return NaN;
171
- }
172
- const opts = {
173
- ...defaultOptions,
174
- ...options
175
- };
176
- const regexResult = (opts.allowTrailingInvalid ? numericRegexWithTrailingInvalid : numericRegex).exec(quantityAsString);
177
- if (!regexResult) {
178
- return opts.romanNumerals ? parseRomanNumerals(quantityAsString) : NaN;
179
- }
180
- const [, dash, ng1temp, ng2temp] = regexResult;
181
- const numberGroup1 = ng1temp.replace(/[,_]/g, "");
182
- const numberGroup2 = ng2temp?.replace(/[,_]/g, "");
183
- if (!numberGroup1 && numberGroup2 && numberGroup2.startsWith(".")) {
184
- finalResult = 0;
185
- } else {
186
- if (opts.bigIntOnOverflow) {
187
- const asBigInt = dash ? BigInt(`-${numberGroup1}`) : BigInt(numberGroup1);
188
- if (asBigInt > BigInt(Number.MAX_SAFE_INTEGER) || asBigInt < BigInt(Number.MIN_SAFE_INTEGER)) {
189
- return asBigInt;
190
- }
191
- }
192
- finalResult = parseInt(numberGroup1);
193
- }
194
- if (!numberGroup2) {
195
- return dash ? finalResult * -1 : finalResult;
196
- }
197
- const roundingFactor = opts.round === false ? NaN : parseFloat(`1e${Math.floor(Math.max(0, opts.round))}`);
198
- if (numberGroup2.startsWith(".") || numberGroup2.startsWith("e") || numberGroup2.startsWith("E")) {
199
- const decimalValue = parseFloat(`${finalResult}${numberGroup2}`);
200
- finalResult = isNaN(roundingFactor) ? decimalValue : Math.round(decimalValue * roundingFactor) / roundingFactor;
201
- } else if (spaceThenSlashRegex.test(numberGroup2)) {
202
- const numerator = parseInt(numberGroup1);
203
- const denominator = parseInt(numberGroup2.replace("/", ""));
204
- finalResult = isNaN(roundingFactor) ? numerator / denominator : Math.round(numerator * roundingFactor / denominator) / roundingFactor;
205
- } else {
206
- const fractionArray = numberGroup2.split("/");
207
- const [numerator, denominator] = fractionArray.map((v) => parseInt(v));
208
- finalResult += isNaN(roundingFactor) ? numerator / denominator : Math.round(numerator * roundingFactor / denominator) / roundingFactor;
209
- }
210
- return dash ? finalResult * -1 : finalResult;
296
+ if (typeof quantity === "number" || typeof quantity === "bigint") return quantity;
297
+ let finalResult = NaN;
298
+ const quantityAsString = normalizeDigits(`${quantity}`.replace(vulgarFractionsRegex, (_m, vf) => ` ${vulgarFractionToAsciiMap[vf]}`).replace("⁄", "/").trim());
299
+ if (quantityAsString.length === 0) return NaN;
300
+ const opts = {
301
+ ...defaultOptions,
302
+ ...options
303
+ };
304
+ let normalizedString = quantityAsString;
305
+ if (opts.decimalSeparator === ",") {
306
+ const commaCount = (quantityAsString.match(/,/g) || []).length;
307
+ if (commaCount === 1) normalizedString = quantityAsString.replaceAll(".", "_").replace(",", ".");
308
+ else if (commaCount > 1) {
309
+ if (!opts.allowTrailingInvalid) return NaN;
310
+ const firstCommaIndex = quantityAsString.indexOf(",");
311
+ const secondCommaIndex = quantityAsString.indexOf(",", firstCommaIndex + 1);
312
+ const beforeSecondComma = quantityAsString.substring(0, secondCommaIndex).replaceAll(".", "_").replace(",", ".");
313
+ const afterSecondComma = quantityAsString.substring(secondCommaIndex + 1);
314
+ normalizedString = opts.allowTrailingInvalid ? beforeSecondComma + "&" + afterSecondComma : beforeSecondComma;
315
+ } else normalizedString = quantityAsString.replaceAll(".", "_");
316
+ }
317
+ const regexResult = (opts.allowTrailingInvalid ? numericRegexWithTrailingInvalid : numericRegex).exec(normalizedString);
318
+ if (!regexResult) return opts.romanNumerals ? parseRomanNumerals(quantityAsString) : NaN;
319
+ const [, dash, ng1temp, ng2temp] = regexResult;
320
+ const numberGroup1 = ng1temp.replaceAll(",", "").replaceAll("_", "");
321
+ const numberGroup2 = ng2temp === null || ng2temp === void 0 ? void 0 : ng2temp.replaceAll(",", "").replaceAll("_", "");
322
+ if (!numberGroup1 && numberGroup2 && numberGroup2.startsWith(".")) finalResult = 0;
323
+ else {
324
+ if (opts.bigIntOnOverflow) {
325
+ const asBigInt = dash ? BigInt(`-${numberGroup1}`) : BigInt(numberGroup1);
326
+ if (asBigInt > BigInt(Number.MAX_SAFE_INTEGER) || asBigInt < BigInt(Number.MIN_SAFE_INTEGER)) return asBigInt;
327
+ }
328
+ finalResult = parseInt(numberGroup1);
329
+ }
330
+ if (!numberGroup2) return dash ? finalResult * -1 : finalResult;
331
+ const roundingFactor = opts.round === false ? NaN : parseFloat(`1e${Math.floor(Math.max(0, opts.round))}`);
332
+ if (numberGroup2.startsWith(".") || numberGroup2.startsWith("e") || numberGroup2.startsWith("E")) {
333
+ const decimalValue = parseFloat(`${finalResult}${numberGroup2}`);
334
+ finalResult = isNaN(roundingFactor) ? decimalValue : Math.round(decimalValue * roundingFactor) / roundingFactor;
335
+ } else if (spaceThenSlashRegex.test(numberGroup2)) {
336
+ const numerator = parseInt(numberGroup1);
337
+ const denominator = parseInt(numberGroup2.replace("/", ""));
338
+ finalResult = isNaN(roundingFactor) ? numerator / denominator : Math.round(numerator * roundingFactor / denominator) / roundingFactor;
339
+ } else {
340
+ const [numerator, denominator] = numberGroup2.split("/").map((v) => parseInt(v));
341
+ finalResult += isNaN(roundingFactor) ? numerator / denominator : Math.round(numerator * roundingFactor / denominator) / roundingFactor;
342
+ }
343
+ return dash ? finalResult * -1 : finalResult;
211
344
  }
212
- export {
213
- defaultOptions,
214
- numericQuantity,
215
- numericRegex,
216
- numericRegexWithTrailingInvalid,
217
- parseRomanNumerals,
218
- romanNumeralRegex,
219
- romanNumeralUnicodeRegex,
220
- romanNumeralUnicodeToAsciiMap,
221
- romanNumeralValues,
222
- vulgarFractionToAsciiMap,
223
- vulgarFractionsRegex
224
- };
345
+
346
+ //#endregion
347
+ export { defaultOptions, normalizeDigits, numericQuantity, numericRegex, numericRegexWithTrailingInvalid, parseRomanNumerals, romanNumeralRegex, romanNumeralUnicodeRegex, romanNumeralUnicodeToAsciiMap, romanNumeralValues, vulgarFractionToAsciiMap, vulgarFractionsRegex };
225
348
  //# sourceMappingURL=numeric-quantity.mjs.map