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,240 +1,412 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
- var __hasOwnProp = Object.prototype.hasOwnProperty;
4
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
- var __spreadValues = (a, b) => {
7
- for (var prop in b || (b = {}))
8
- if (__hasOwnProp.call(b, prop))
9
- __defNormalProp(a, prop, b[prop]);
10
- if (__getOwnPropSymbols)
11
- for (var prop of __getOwnPropSymbols(b)) {
12
- if (__propIsEnum.call(b, prop))
13
- __defNormalProp(a, prop, b[prop]);
14
- }
15
- return a;
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
- // src/constants.ts
19
- var vulgarFractionToAsciiMap = {
20
- "\xBC": "1/4",
21
- "\xBD": "1/2",
22
- "\xBE": "3/4",
23
- "\u2150": "1/7",
24
- "\u2151": "1/9",
25
- "\u2152": "1/10",
26
- "\u2153": "1/3",
27
- "\u2154": "2/3",
28
- "\u2155": "1/5",
29
- "\u2156": "2/5",
30
- "\u2157": "3/5",
31
- "\u2158": "4/5",
32
- "\u2159": "1/6",
33
- "\u215A": "5/6",
34
- "\u215B": "1/8",
35
- "\u215C": "3/8",
36
- "\u215D": "5/8",
37
- "\u215E": "7/8",
38
- "\u215F": "1/"
39
- };
40
- 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)?)?$/;
41
- var numericRegexWithTrailingInvalid = new RegExp(
42
- numericRegex.source.replace(/\$$/, "(?:\\s*[^\\.\\d\\/].*)?")
43
- );
44
- var vulgarFractionsRegex = new RegExp(
45
- `(${Object.keys(vulgarFractionToAsciiMap).join("|")})`
46
- );
47
- var romanNumeralValues = {
48
- MMM: 3e3,
49
- MM: 2e3,
50
- M: 1e3,
51
- CM: 900,
52
- DCCC: 800,
53
- DCC: 700,
54
- DC: 600,
55
- D: 500,
56
- CD: 400,
57
- CCC: 300,
58
- CC: 200,
59
- C: 100,
60
- XC: 90,
61
- LXXX: 80,
62
- LXX: 70,
63
- LX: 60,
64
- L: 50,
65
- XL: 40,
66
- XXX: 30,
67
- XX: 20,
68
- XII: 12,
69
- // only here for tests; not used in practice
70
- XI: 11,
71
- // only here for tests; not used in practice
72
- X: 10,
73
- IX: 9,
74
- VIII: 8,
75
- VII: 7,
76
- VI: 6,
77
- V: 5,
78
- IV: 4,
79
- III: 3,
80
- II: 2,
81
- 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
82
200
  };
83
- var romanNumeralUnicodeToAsciiMap = {
84
- // Roman Numeral One (U+2160)
85
- "\u2160": "I",
86
- // Roman Numeral Two (U+2161)
87
- "\u2161": "II",
88
- // Roman Numeral Three (U+2162)
89
- "\u2162": "III",
90
- // Roman Numeral Four (U+2163)
91
- "\u2163": "IV",
92
- // Roman Numeral Five (U+2164)
93
- "\u2164": "V",
94
- // Roman Numeral Six (U+2165)
95
- "\u2165": "VI",
96
- // Roman Numeral Seven (U+2166)
97
- "\u2166": "VII",
98
- // Roman Numeral Eight (U+2167)
99
- "\u2167": "VIII",
100
- // Roman Numeral Nine (U+2168)
101
- "\u2168": "IX",
102
- // Roman Numeral Ten (U+2169)
103
- "\u2169": "X",
104
- // Roman Numeral Eleven (U+216A)
105
- "\u216A": "XI",
106
- // Roman Numeral Twelve (U+216B)
107
- "\u216B": "XII",
108
- // Roman Numeral Fifty (U+216C)
109
- "\u216C": "L",
110
- // Roman Numeral One Hundred (U+216D)
111
- "\u216D": "C",
112
- // Roman Numeral Five Hundred (U+216E)
113
- "\u216E": "D",
114
- // Roman Numeral One Thousand (U+216F)
115
- "\u216F": "M",
116
- // Small Roman Numeral One (U+2170)
117
- "\u2170": "I",
118
- // Small Roman Numeral Two (U+2171)
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
- var romanNumeralUnicodeRegex = new RegExp(
150
- `(${Object.keys(romanNumeralUnicodeToAsciiMap).join("|")})`,
151
- "gi"
152
- );
153
- 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;
154
- var defaultOptions = {
155
- round: 3,
156
- allowTrailingInvalid: false,
157
- romanNumerals: false,
158
- 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: "."
159
273
  };
160
274
 
161
- // src/parseRomanNumerals.ts
162
- var parseRomanNumerals = (romanNumerals) => {
163
- var _a, _b, _c, _d;
164
- const normalized = `${romanNumerals}`.replace(
165
- romanNumeralUnicodeRegex,
166
- (_m, rn) => romanNumeralUnicodeToAsciiMap[rn]
167
- ).toUpperCase();
168
- const regexResult = romanNumeralRegex.exec(normalized);
169
- if (!regexResult) {
170
- return NaN;
171
- }
172
- const [, thousands, hundreds, tens, ones] = regexResult;
173
- return ((_a = romanNumeralValues[thousands]) != null ? _a : 0) + ((_b = romanNumeralValues[hundreds]) != null ? _b : 0) + ((_c = romanNumeralValues[tens]) != null ? _c : 0) + ((_d = romanNumeralValues[ones]) != null ? _d : 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
+ 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
- // src/numericQuantity.ts
177
- var spaceThenSlashRegex = /^\s*\//;
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
- if (typeof quantity === "number" || typeof quantity === "bigint") {
180
- return quantity;
181
- }
182
- let finalResult = NaN;
183
- const quantityAsString = `${quantity}`.replace(
184
- vulgarFractionsRegex,
185
- (_m, vf) => ` ${vulgarFractionToAsciiMap[vf]}`
186
- ).replace("\u2044", "/").trim();
187
- if (quantityAsString.length === 0) {
188
- return NaN;
189
- }
190
- const opts = __spreadValues(__spreadValues({}, defaultOptions), options);
191
- const regexResult = (opts.allowTrailingInvalid ? numericRegexWithTrailingInvalid : numericRegex).exec(quantityAsString);
192
- if (!regexResult) {
193
- return opts.romanNumerals ? parseRomanNumerals(quantityAsString) : NaN;
194
- }
195
- const [, dash, ng1temp, ng2temp] = regexResult;
196
- const numberGroup1 = ng1temp.replace(/[,_]/g, "");
197
- const numberGroup2 = ng2temp == null ? void 0 : ng2temp.replace(/[,_]/g, "");
198
- if (!numberGroup1 && numberGroup2 && numberGroup2.startsWith(".")) {
199
- finalResult = 0;
200
- } else {
201
- if (opts.bigIntOnOverflow) {
202
- const asBigInt = dash ? BigInt(`-${numberGroup1}`) : BigInt(numberGroup1);
203
- if (asBigInt > BigInt(Number.MAX_SAFE_INTEGER) || asBigInt < BigInt(Number.MIN_SAFE_INTEGER)) {
204
- return asBigInt;
205
- }
206
- }
207
- finalResult = parseInt(numberGroup1);
208
- }
209
- if (!numberGroup2) {
210
- return dash ? finalResult * -1 : finalResult;
211
- }
212
- const roundingFactor = opts.round === false ? NaN : parseFloat(`1e${Math.floor(Math.max(0, opts.round))}`);
213
- if (numberGroup2.startsWith(".") || numberGroup2.startsWith("e") || numberGroup2.startsWith("E")) {
214
- const decimalValue = parseFloat(`${finalResult}${numberGroup2}`);
215
- finalResult = isNaN(roundingFactor) ? decimalValue : Math.round(decimalValue * roundingFactor) / roundingFactor;
216
- } else if (spaceThenSlashRegex.test(numberGroup2)) {
217
- const numerator = parseInt(numberGroup1);
218
- const denominator = parseInt(numberGroup2.replace("/", ""));
219
- finalResult = isNaN(roundingFactor) ? numerator / denominator : Math.round(numerator * roundingFactor / denominator) / roundingFactor;
220
- } else {
221
- const fractionArray = numberGroup2.split("/");
222
- const [numerator, denominator] = fractionArray.map((v) => parseInt(v));
223
- finalResult += isNaN(roundingFactor) ? numerator / denominator : Math.round(numerator * roundingFactor / denominator) / roundingFactor;
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
- export {
228
- defaultOptions,
229
- numericQuantity,
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