numeric-quantity 2.0.1 → 3.0.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.
Files changed (33) hide show
  1. package/README.md +15 -3
  2. package/dist/cjs/numeric-quantity.cjs.development.js +247 -246
  3. package/dist/cjs/numeric-quantity.cjs.development.js.map +1 -1
  4. package/dist/cjs/numeric-quantity.cjs.production.js +1 -1
  5. package/dist/cjs/numeric-quantity.cjs.production.js.map +1 -1
  6. package/dist/numeric-quantity.iife.umd.min.js +2 -0
  7. package/dist/numeric-quantity.iife.umd.min.js.map +1 -0
  8. package/dist/numeric-quantity.legacy-esm.js +301 -225
  9. package/dist/numeric-quantity.legacy-esm.js.map +1 -1
  10. package/dist/numeric-quantity.mjs +237 -210
  11. package/dist/numeric-quantity.mjs.map +1 -1
  12. package/dist/numeric-quantity.production.mjs +1 -1
  13. package/dist/numeric-quantity.production.mjs.map +1 -1
  14. package/dist/types/constants.d.ts +79 -0
  15. package/dist/types/dev.d.ts +1 -0
  16. package/dist/types/index.d.ts +4 -0
  17. package/dist/types/numericQuantity.d.ts +12 -0
  18. package/dist/types/parseRomanNumerals.d.ts +8 -0
  19. package/dist/types/types.d.ts +49 -0
  20. package/dist/types-esm/constants.d.mts +79 -0
  21. package/dist/types-esm/dev.d.mts +1 -0
  22. package/dist/types-esm/index.d.mts +4 -0
  23. package/dist/types-esm/numericQuantity.d.mts +12 -0
  24. package/dist/types-esm/parseRomanNumerals.d.mts +8 -0
  25. package/dist/types-esm/types.d.mts +49 -0
  26. package/package.json +23 -18
  27. package/dist/cjs/numeric-quantity.cjs.development.d.ts +0 -222
  28. package/dist/cjs/numeric-quantity.cjs.production.d.ts +0 -222
  29. package/dist/numeric-quantity.d.mts +0 -222
  30. package/dist/numeric-quantity.legacy-esm.d.mts +0 -222
  31. package/dist/numeric-quantity.production.d.mts +0 -222
  32. package/dist/numeric-quantity.umd.min.js +0 -2
  33. package/dist/numeric-quantity.umd.min.js.map +0 -1
@@ -1,233 +1,309 @@
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
+ * Map of Unicode fraction code points to their ASCII equivalents.
4
+ */
5
+ const vulgarFractionToAsciiMap = {
6
+ "¼": "1/4",
7
+ "½": "1/2",
8
+ "¾": "3/4",
9
+ "⅐": "1/7",
10
+ "⅑": "1/9",
11
+ "⅒": "1/10",
12
+ "⅓": "1/3",
13
+ "⅔": "2/3",
14
+ "⅕": "1/5",
15
+ "⅖": "2/5",
16
+ "⅗": "3/5",
17
+ "⅘": "4/5",
18
+ "⅙": "1/6",
19
+ "⅚": "5/6",
20
+ "⅛": "1/8",
21
+ "⅜": "3/8",
22
+ "⅝": "5/8",
23
+ "⅞": "7/8",
24
+ "⅟": "1/"
16
25
  };
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
26
+ /**
27
+ * Captures the individual elements of a numeric string. Commas and underscores are allowed
28
+ * as separators, as long as they appear between digits and are not consecutive.
29
+ *
30
+ * Capture groups:
31
+ *
32
+ * | # | Description | Example(s) |
33
+ * | --- | ------------------------------------------------ | ------------------------------------------------------------------- |
34
+ * | `0` | entire string | `"2 1/3"` from `"2 1/3"` |
35
+ * | `1` | "negative" dash | `"-"` from `"-2 1/3"` |
36
+ * | `2` | whole number or numerator | `"2"` from `"2 1/3"`; `"1"` from `"1/3"` |
37
+ * | `3` | entire fraction, decimal portion, or denominator | `" 1/3"` from `"2 1/3"`; `".33"` from `"2.33"`; `"/3"` from `"1/3"` |
38
+ *
39
+ * _Capture group 2 may include comma/underscore separators._
40
+ *
41
+ * @example
42
+ *
43
+ * ```ts
44
+ * numericRegex.exec("1") // [ "1", "1", null, null ]
45
+ * numericRegex.exec("1.23") // [ "1.23", "1", ".23", null ]
46
+ * numericRegex.exec("1 2/3") // [ "1 2/3", "1", " 2/3", " 2" ]
47
+ * numericRegex.exec("2/3") // [ "2/3", "2", "/3", null ]
48
+ * numericRegex.exec("2 / 3") // [ "2 / 3", "2", "/ 3", null ]
49
+ * ```
50
+ */
51
+ const numericRegex = new RegExp("^(?=-?\\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)*)?$", "");
52
+ /**
53
+ * Same as {@link numericRegex}, but allows (and ignores) trailing invalid characters.
54
+ */
55
+ const numericRegexWithTrailingInvalid = new RegExp("^(?=-?\\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/].*)?", "");
56
+ /**
57
+ * Captures any Unicode vulgar fractions.
58
+ */
59
+ const vulgarFractionsRegex = new RegExp("([¼½¾⅐⅑⅒⅓⅔⅕⅖⅗⅘⅙⅚⅛⅜⅝⅞⅟}])", "g");
60
+ /**
61
+ * Map of Roman numeral sequences to their decimal equivalents.
62
+ */
63
+ const romanNumeralValues = {
64
+ MMM: 3e3,
65
+ MM: 2e3,
66
+ M: 1e3,
67
+ CM: 900,
68
+ DCCC: 800,
69
+ DCC: 700,
70
+ DC: 600,
71
+ D: 500,
72
+ CD: 400,
73
+ CCC: 300,
74
+ CC: 200,
75
+ C: 100,
76
+ XC: 90,
77
+ LXXX: 80,
78
+ LXX: 70,
79
+ LX: 60,
80
+ L: 50,
81
+ XL: 40,
82
+ XXX: 30,
83
+ XX: 20,
84
+ XII: 12,
85
+ XI: 11,
86
+ X: 10,
87
+ IX: 9,
88
+ VIII: 8,
89
+ VII: 7,
90
+ VI: 6,
91
+ V: 5,
92
+ IV: 4,
93
+ III: 3,
94
+ II: 2,
95
+ I: 1
82
96
  };
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"
97
+ /**
98
+ * Map of Unicode Roman numeral code points to their ASCII equivalents.
99
+ */
100
+ const romanNumeralUnicodeToAsciiMap = {
101
+ Ⅰ: "I",
102
+ Ⅱ: "II",
103
+ Ⅲ: "III",
104
+ Ⅳ: "IV",
105
+ Ⅴ: "V",
106
+ Ⅵ: "VI",
107
+ Ⅶ: "VII",
108
+ Ⅷ: "VIII",
109
+ Ⅸ: "IX",
110
+ Ⅹ: "X",
111
+ Ⅺ: "XI",
112
+ Ⅻ: "XII",
113
+ Ⅼ: "L",
114
+ Ⅽ: "C",
115
+ Ⅾ: "D",
116
+ Ⅿ: "M",
117
+ ⅰ: "I",
118
+ ⅱ: "II",
119
+ ⅲ: "III",
120
+ ⅳ: "IV",
121
+ ⅴ: "V",
122
+ ⅵ: "VI",
123
+ ⅶ: "VII",
124
+ ⅷ: "VIII",
125
+ ⅸ: "IX",
126
+ ⅹ: "X",
127
+ ⅺ: "XI",
128
+ ⅻ: "XII",
129
+ ⅼ: "L",
130
+ ⅽ: "C",
131
+ ⅾ: "D",
132
+ ⅿ: "M"
148
133
  };
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
134
+ /**
135
+ * Captures all Unicode Roman numeral code points.
136
+ */
137
+ const romanNumeralUnicodeRegex = new RegExp("([ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩⅪⅫⅬⅭⅮⅯⅰⅱⅲⅳⅴⅵⅶⅷⅸⅹⅺⅻⅼⅽⅾⅿ])", "gi");
138
+ /**
139
+ * Captures a valid Roman numeral sequence.
140
+ *
141
+ * Capture groups:
142
+ *
143
+ * | # | Description | Example |
144
+ * | --- | --------------- | ------------------------ |
145
+ * | `0` | Entire string | "MCCXIV" from "MCCXIV" |
146
+ * | `1` | Thousands | "M" from "MCCXIV" |
147
+ * | `2` | Hundreds | "CC" from "MCCXIV" |
148
+ * | `3` | Tens | "X" from "MCCXIV" |
149
+ * | `4` | Ones | "IV" from "MCCXIV" |
150
+ *
151
+ * @example
152
+ *
153
+ * ```ts
154
+ * romanNumeralRegex.exec("M") // [ "M", "M", "", "", "" ]
155
+ * romanNumeralRegex.exec("XII") // [ "XII", "", "", "X", "II" ]
156
+ * romanNumeralRegex.exec("MCCXIV") // [ "MCCXIV", "M", "CC", "X", "IV" ]
157
+ * ```
158
+ */
159
+ const romanNumeralRegex = new RegExp("^(?=[MDCLXVI])(M{0,3})(C[MD]|D?C{0,3})(X[CL]|L?X{0,3})(I[XV]|V?I{0,3})$", "i");
160
+ /**
161
+ * Default options for {@link numericQuantity}.
162
+ */
163
+ const defaultOptions = {
164
+ round: 3,
165
+ allowTrailingInvalid: false,
166
+ romanNumerals: false,
167
+ bigIntOnOverflow: false,
168
+ decimalSeparator: "."
158
169
  };
159
170
 
160
- // src/parseRomanNumerals.ts
161
- var parseRomanNumerals = (romanNumerals) => {
162
- var _a, _b, _c, _d;
163
- const normalized = `${romanNumerals}`.replace(
164
- romanNumeralUnicodeRegex,
165
- (_m, rn) => romanNumeralUnicodeToAsciiMap[rn]
166
- ).toUpperCase();
167
- const regexResult = romanNumeralRegex.exec(normalized);
168
- if (!regexResult) {
169
- return NaN;
170
- }
171
- const [, thousands, hundreds, tens, ones] = regexResult;
172
- 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);
171
+ //#endregion
172
+ //#region src/parseRomanNumerals.ts
173
+ /**
174
+ * Converts a string of Roman numerals to a number, like `parseInt`
175
+ * for Roman numerals. Uses modern, strict rules (only 1 to 3999).
176
+ *
177
+ * The string can include ASCII representations of Roman numerals
178
+ * or Unicode Roman numeral code points (`U+2160` through `U+217F`).
179
+ */
180
+ const parseRomanNumerals = (romanNumerals) => {
181
+ var _romanNumeralValues, _romanNumeralValues2, _romanNumeralValues3, _romanNumeralValues4;
182
+ const normalized = `${romanNumerals}`.replace(romanNumeralUnicodeRegex, (_m, rn) => romanNumeralUnicodeToAsciiMap[rn]).toUpperCase();
183
+ const regexResult = romanNumeralRegex.exec(normalized);
184
+ if (!regexResult) return NaN;
185
+ const [, thousands, hundreds, tens, ones] = regexResult;
186
+ 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);
173
187
  };
174
188
 
175
- // src/numericQuantity.ts
176
- var spaceThenSlashRegex = /^\s*\//;
177
- var numericQuantity = (quantity, options = defaultOptions) => {
178
- if (typeof quantity === "number" || typeof quantity === "bigint") {
179
- return quantity;
180
- }
181
- let finalResult = NaN;
182
- const quantityAsString = `${quantity}`.replace(
183
- vulgarFractionsRegex,
184
- (_m, vf) => ` ${vulgarFractionToAsciiMap[vf]}`
185
- ).replace("\u2044", "/").trim();
186
- if (quantityAsString.length === 0) {
187
- return NaN;
188
- }
189
- const opts = __spreadValues(__spreadValues({}, defaultOptions), options);
190
- const regexResult = (opts.allowTrailingInvalid ? numericRegexWithTrailingInvalid : numericRegex).exec(quantityAsString);
191
- if (!regexResult) {
192
- return opts.romanNumerals ? parseRomanNumerals(quantityAsString) : NaN;
193
- }
194
- const [, dash, ng1temp, ng2temp] = regexResult;
195
- const numberGroup1 = ng1temp.replace(/[,_]/g, "");
196
- const numberGroup2 = ng2temp == null ? void 0 : ng2temp.replace(/[,_]/g, "");
197
- if (!numberGroup1 && numberGroup2 && numberGroup2.startsWith(".")) {
198
- finalResult = 0;
199
- } else {
200
- finalResult = parseInt(numberGroup1);
201
- }
202
- if (!numberGroup2) {
203
- return dash ? finalResult * -1 : finalResult;
204
- }
205
- const roundingFactor = opts.round === false ? NaN : parseFloat(`1e${Math.floor(Math.max(0, opts.round))}`);
206
- if (numberGroup2.startsWith(".") || numberGroup2.startsWith("e") || numberGroup2.startsWith("E")) {
207
- const decimalValue = parseFloat(`${finalResult}${numberGroup2}`);
208
- finalResult = isNaN(roundingFactor) ? decimalValue : Math.round(decimalValue * roundingFactor) / roundingFactor;
209
- } else if (spaceThenSlashRegex.test(numberGroup2)) {
210
- const numerator = parseInt(numberGroup1);
211
- const denominator = parseInt(numberGroup2.replace("/", ""));
212
- finalResult = isNaN(roundingFactor) ? numerator / denominator : Math.round(numerator * roundingFactor / denominator) / roundingFactor;
213
- } else {
214
- const fractionArray = numberGroup2.split("/");
215
- const [numerator, denominator] = fractionArray.map((v) => parseInt(v));
216
- finalResult += isNaN(roundingFactor) ? numerator / denominator : Math.round(numerator * roundingFactor / denominator) / roundingFactor;
217
- }
218
- return dash ? finalResult * -1 : finalResult;
219
- };
220
- export {
221
- defaultOptions,
222
- numericQuantity,
223
- numericRegex,
224
- numericRegexWithTrailingInvalid,
225
- parseRomanNumerals,
226
- romanNumeralRegex,
227
- romanNumeralUnicodeRegex,
228
- romanNumeralUnicodeToAsciiMap,
229
- romanNumeralValues,
230
- vulgarFractionToAsciiMap,
231
- vulgarFractionsRegex
232
- };
189
+ //#endregion
190
+ //#region node_modules/@oxc-project/runtime/src/helpers/esm/typeof.js
191
+ function _typeof(o) {
192
+ "@babel/helpers - typeof";
193
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
194
+ return typeof o$1;
195
+ } : function(o$1) {
196
+ return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
197
+ }, _typeof(o);
198
+ }
199
+
200
+ //#endregion
201
+ //#region node_modules/@oxc-project/runtime/src/helpers/esm/toPrimitive.js
202
+ function toPrimitive(t, r) {
203
+ if ("object" != _typeof(t) || !t) return t;
204
+ var e = t[Symbol.toPrimitive];
205
+ if (void 0 !== e) {
206
+ var i = e.call(t, r || "default");
207
+ if ("object" != _typeof(i)) return i;
208
+ throw new TypeError("@@toPrimitive must return a primitive value.");
209
+ }
210
+ return ("string" === r ? String : Number)(t);
211
+ }
212
+
213
+ //#endregion
214
+ //#region node_modules/@oxc-project/runtime/src/helpers/esm/toPropertyKey.js
215
+ function toPropertyKey(t) {
216
+ var i = toPrimitive(t, "string");
217
+ return "symbol" == _typeof(i) ? i : i + "";
218
+ }
219
+
220
+ //#endregion
221
+ //#region node_modules/@oxc-project/runtime/src/helpers/esm/defineProperty.js
222
+ function _defineProperty(e, r, t) {
223
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
224
+ value: t,
225
+ enumerable: !0,
226
+ configurable: !0,
227
+ writable: !0
228
+ }) : e[r] = t, e;
229
+ }
230
+
231
+ //#endregion
232
+ //#region node_modules/@oxc-project/runtime/src/helpers/esm/objectSpread2.js
233
+ function ownKeys(e, r) {
234
+ var t = Object.keys(e);
235
+ if (Object.getOwnPropertySymbols) {
236
+ var o = Object.getOwnPropertySymbols(e);
237
+ r && (o = o.filter(function(r$1) {
238
+ return Object.getOwnPropertyDescriptor(e, r$1).enumerable;
239
+ })), t.push.apply(t, o);
240
+ }
241
+ return t;
242
+ }
243
+ function _objectSpread2(e) {
244
+ for (var r = 1; r < arguments.length; r++) {
245
+ var t = null != arguments[r] ? arguments[r] : {};
246
+ r % 2 ? ownKeys(Object(t), !0).forEach(function(r$1) {
247
+ _defineProperty(e, r$1, t[r$1]);
248
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r$1) {
249
+ Object.defineProperty(e, r$1, Object.getOwnPropertyDescriptor(t, r$1));
250
+ });
251
+ }
252
+ return e;
253
+ }
254
+
255
+ //#endregion
256
+ //#region src/numericQuantity.ts
257
+ const spaceThenSlashRegex = /^\s*\//;
258
+ function numericQuantity(quantity, options = defaultOptions) {
259
+ if (typeof quantity === "number" || typeof quantity === "bigint") return quantity;
260
+ let finalResult = NaN;
261
+ const quantityAsString = `${quantity}`.replace(vulgarFractionsRegex, (_m, vf) => ` ${vulgarFractionToAsciiMap[vf]}`).replace("⁄", "/").trim();
262
+ if (quantityAsString.length === 0) return NaN;
263
+ const opts = _objectSpread2(_objectSpread2({}, defaultOptions), options);
264
+ let normalizedString = quantityAsString;
265
+ if (opts.decimalSeparator === ",") {
266
+ const commaCount = (quantityAsString.match(/,/g) || []).length;
267
+ if (commaCount === 1) normalizedString = quantityAsString.replaceAll(".", "_").replace(",", ".");
268
+ else if (commaCount > 1) {
269
+ if (!opts.allowTrailingInvalid) return NaN;
270
+ const firstCommaIndex = quantityAsString.indexOf(",");
271
+ const secondCommaIndex = quantityAsString.indexOf(",", firstCommaIndex + 1);
272
+ const beforeSecondComma = quantityAsString.substring(0, secondCommaIndex).replaceAll(".", "_").replace(",", ".");
273
+ const afterSecondComma = quantityAsString.substring(secondCommaIndex + 1);
274
+ normalizedString = opts.allowTrailingInvalid ? beforeSecondComma + "&" + afterSecondComma : beforeSecondComma;
275
+ } else normalizedString = quantityAsString.replaceAll(".", "_");
276
+ }
277
+ const regexResult = (opts.allowTrailingInvalid ? numericRegexWithTrailingInvalid : numericRegex).exec(normalizedString);
278
+ if (!regexResult) return opts.romanNumerals ? parseRomanNumerals(quantityAsString) : NaN;
279
+ const [, dash, ng1temp, ng2temp] = regexResult;
280
+ const numberGroup1 = ng1temp.replaceAll(",", "").replaceAll("_", "");
281
+ const numberGroup2 = ng2temp === null || ng2temp === void 0 ? void 0 : ng2temp.replaceAll(",", "").replaceAll("_", "");
282
+ if (!numberGroup1 && numberGroup2 && numberGroup2.startsWith(".")) finalResult = 0;
283
+ else {
284
+ if (opts.bigIntOnOverflow) {
285
+ const asBigInt = dash ? BigInt(`-${numberGroup1}`) : BigInt(numberGroup1);
286
+ if (asBigInt > BigInt(Number.MAX_SAFE_INTEGER) || asBigInt < BigInt(Number.MIN_SAFE_INTEGER)) return asBigInt;
287
+ }
288
+ finalResult = parseInt(numberGroup1);
289
+ }
290
+ if (!numberGroup2) return dash ? finalResult * -1 : finalResult;
291
+ const roundingFactor = opts.round === false ? NaN : parseFloat(`1e${Math.floor(Math.max(0, opts.round))}`);
292
+ if (numberGroup2.startsWith(".") || numberGroup2.startsWith("e") || numberGroup2.startsWith("E")) {
293
+ const decimalValue = parseFloat(`${finalResult}${numberGroup2}`);
294
+ finalResult = isNaN(roundingFactor) ? decimalValue : Math.round(decimalValue * roundingFactor) / roundingFactor;
295
+ } else if (spaceThenSlashRegex.test(numberGroup2)) {
296
+ const numerator = parseInt(numberGroup1);
297
+ const denominator = parseInt(numberGroup2.replace("/", ""));
298
+ finalResult = isNaN(roundingFactor) ? numerator / denominator : Math.round(numerator * roundingFactor / denominator) / roundingFactor;
299
+ } else {
300
+ const fractionArray = numberGroup2.split("/");
301
+ const [numerator, denominator] = fractionArray.map((v) => parseInt(v));
302
+ finalResult += isNaN(roundingFactor) ? numerator / denominator : Math.round(numerator * roundingFactor / denominator) / roundingFactor;
303
+ }
304
+ return dash ? finalResult * -1 : finalResult;
305
+ }
306
+
307
+ //#endregion
308
+ export { defaultOptions, numericQuantity, numericRegex, numericRegexWithTrailingInvalid, parseRomanNumerals, romanNumeralRegex, romanNumeralUnicodeRegex, romanNumeralUnicodeToAsciiMap, romanNumeralValues, vulgarFractionToAsciiMap, vulgarFractionsRegex };
233
309
  //# sourceMappingURL=numeric-quantity.legacy-esm.js.map