quantible 0.1.11-alpha → 0.1.12-alpha

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/dist/index.cjs ADDED
@@ -0,0 +1,1089 @@
1
+ 'use strict';
2
+
3
+ // src/config/default.ts
4
+ var units = {
5
+ // Base units
6
+ m: { singular: "meter", plural: "meters" },
7
+ "%": { singular: "percent", plural: "percent" },
8
+ cm: { singular: "centimeter", plural: "centimeters" },
9
+ mm: { singular: "millimeter", plural: "millimeters" },
10
+ km: { singular: "kilometer", plural: "kilometers" },
11
+ in: { singular: "inch", plural: "inches" },
12
+ ft: { singular: "foot", plural: "feet" },
13
+ yd: { singular: "yard", plural: "yards" },
14
+ mi: { singular: "mile", plural: "miles" },
15
+ g: { singular: "gram", plural: "grams" },
16
+ mg: { singular: "milligram", plural: "milligrams" },
17
+ kg: { singular: "kilogram", plural: "kilograms" },
18
+ L: { singular: "liter", plural: "liters" },
19
+ mL: { singular: "milliliter", plural: "milliliters" },
20
+ s: { singular: "second", plural: "seconds" },
21
+ min: { singular: "minute", plural: "minutes" },
22
+ h: { singular: "hour", plural: "hours" },
23
+ // Additional Time Units
24
+ d: { singular: "day", plural: "days" },
25
+ wk: { singular: "week", plural: "weeks" },
26
+ mo: { singular: "month", plural: "months" },
27
+ yr: { singular: "year", plural: "years" },
28
+ // Additional Length Units
29
+ \u03BCm: { singular: "micrometer", plural: "micrometers" },
30
+ nm: { singular: "nanometer", plural: "nanometers" },
31
+ nmi: { singular: "nautical mile", plural: "nautical miles" },
32
+ // Additional Mass Units
33
+ \u03BCg: { singular: "microgram", plural: "micrograms" },
34
+ t: { singular: "tonne", plural: "tonnes" },
35
+ lb: { singular: "pound", plural: "pounds" },
36
+ oz: { singular: "ounce", plural: "ounces" },
37
+ st: { singular: "stone", plural: "stones" },
38
+ // Volume Units
39
+ "cm\xB3": { singular: "cubic centimeter", plural: "cubic centimeters" },
40
+ gal: { singular: "gallon", plural: "gallons" },
41
+ pt: { singular: "pint", plural: "pints" },
42
+ qt: { singular: "quart", plural: "quarts" },
43
+ "fl oz": { singular: "fluid ounce", plural: "fluid ounces" },
44
+ "ft\xB3": { singular: "cubic foot", plural: "cubic feet" },
45
+ "in\xB3": { singular: "cubic inch", plural: "cubic inches" },
46
+ bbl: { singular: "barrel", plural: "barrels" },
47
+ // Area Units
48
+ "m\xB2": { singular: "square meter", plural: "square meters" },
49
+ "km\xB2": { singular: "square kilometer", plural: "square kilometers" },
50
+ "cm\xB2": { singular: "square centimeter", plural: "square centimeters" },
51
+ "mm\xB2": { singular: "square millimeter", plural: "square millimeters" },
52
+ ha: { singular: "hectare", plural: "hectares" },
53
+ "ft\xB2": { singular: "square foot", plural: "square feet" },
54
+ "in\xB2": { singular: "square inch", plural: "square inches" },
55
+ ac: { singular: "acre", plural: "acres" },
56
+ // Angle Units
57
+ rad: { singular: "radian", plural: "radians" },
58
+ deg: { singular: "degree", plural: "degrees" },
59
+ grad: { singular: "gradian", plural: "gradians" },
60
+ // Temperature Units
61
+ K: { singular: "kelvin", plural: "kelvins" },
62
+ "\xB0C": { singular: "degree Celsius", plural: "degrees Celsius" },
63
+ "\xB0F": { singular: "degree Fahrenheit", plural: "degrees Fahrenheit" },
64
+ // Speed Units
65
+ "m/s": { singular: "meter per second", plural: "meters per second" },
66
+ "m/s\xB2": {
67
+ singular: "meter per second squared",
68
+ plural: "meters per second squared"
69
+ },
70
+ "km/h": { singular: "kilometer per hour", plural: "kilometers per hour" },
71
+ "km/L": { singular: "kilometer per liter", plural: "kilometers per liter" },
72
+ mph: { singular: "mile per hour", plural: "miles per hour" },
73
+ "ft/s": { singular: "foot per second", plural: "feet per second" },
74
+ kn: { singular: "knot", plural: "knots" },
75
+ mach: { singular: "mach", plural: "" },
76
+ c: { singular: "speed of light", plural: "" },
77
+ // Force Units
78
+ N: { singular: "newton", plural: "newtons" },
79
+ kgf: { singular: "kilogram-force", plural: "" },
80
+ lbf: { singular: "pound-force", plural: "" },
81
+ dyn: { singular: "dyne", plural: "dynes" },
82
+ // Pressure Units
83
+ Pa: { singular: "pascal", plural: "pascals" },
84
+ kPa: { singular: "kilopascal", plural: "kilopascals" },
85
+ MPa: { singular: "megapascal", plural: "megapascals" },
86
+ bar: { singular: "bar", plural: "bars" },
87
+ atm: { singular: "atmosphere", plural: "atmospheres" },
88
+ mmHg: { singular: "millimeter of mercury", plural: "millimeters of mercury" },
89
+ inHg: { singular: "inch of mercury", plural: "inches of mercury" },
90
+ psi: { singular: "pound per square inch", plural: "pounds per square inch" },
91
+ "N/m\xB2": {
92
+ singular: "newton per square meter",
93
+ plural: "newtons per square meter"
94
+ },
95
+ "kg/m\xB2": {
96
+ singular: "kilogram per square meter",
97
+ plural: "kilograms per square meter"
98
+ },
99
+ // Energy Units
100
+ J: { singular: "joule", plural: "joules" },
101
+ kJ: { singular: "kilojoule", plural: "kilojoules" },
102
+ MJ: { singular: "megajoule", plural: "megajoules" },
103
+ cal: { singular: "calorie", plural: "calories" },
104
+ kcal: { singular: "kilocalorie", plural: "kilocalories" },
105
+ eV: { singular: "electron volt", plural: "electron volts" },
106
+ BTU: { singular: "British thermal unit", plural: "British thermal units" },
107
+ kWh: { singular: "kilowatt hour", plural: "kilowatt hours" },
108
+ // Power Units
109
+ W: { singular: "watt", plural: "watts" },
110
+ kW: { singular: "kilowatt", plural: "kilowatts" },
111
+ MW: { singular: "megawatt", plural: "megawatts" },
112
+ hp: { singular: "horsepower", plural: "" },
113
+ // Frequency Units
114
+ Hz: { singular: "hertz", plural: "" },
115
+ kHz: { singular: "kilohertz", plural: "" },
116
+ MHz: { singular: "megahertz", plural: "" },
117
+ GHz: { singular: "gigahertz", plural: "" },
118
+ rpm: { singular: "revolution per minute", plural: "revolutions per minute" },
119
+ "rad/s": { singular: "radian per second", plural: "radians per second" },
120
+ "deg/s": { singular: "degree per second", plural: "degrees per second" },
121
+ // Electrical Units
122
+ V: { singular: "volt", plural: "volts" },
123
+ mV: { singular: "millivolt", plural: "millivolts" },
124
+ \u03BCV: { singular: "microvolt", plural: "microvolts" },
125
+ kV: { singular: "kilovolt", plural: "kilovolts" },
126
+ A: { singular: "ampere", plural: "amperes" },
127
+ mA: { singular: "milliampere", plural: "milliamperes" },
128
+ \u03BCA: { singular: "microampere", plural: "microamperes" },
129
+ \u03A9: { singular: "ohm", plural: "ohms" },
130
+ k\u03A9: { singular: "kilohm", plural: "kilohms" },
131
+ M\u03A9: { singular: "megohm", plural: "megohms" },
132
+ F: { singular: "farad", plural: "farads" },
133
+ \u03BCF: { singular: "microfarad", plural: "microfarads" },
134
+ nF: { singular: "nanofarad", plural: "nanofarads" },
135
+ pF: { singular: "picofarad", plural: "picofarads" },
136
+ H: { singular: "henry", plural: "henries" },
137
+ mH: { singular: "millihenry", plural: "millihenries" },
138
+ \u03BCH: { singular: "microhenry", plural: "microhenries" },
139
+ S: { singular: "siemens", plural: "" },
140
+ "S/m": { singular: "siemens per meter", plural: "" },
141
+ "F/m": { singular: "farad per meter", plural: "farads per meter" },
142
+ "\u03A9\xB7m": { singular: "ohm meter", plural: "ohm meters" },
143
+ "V/m": { singular: "volt per meter", plural: "volts per meter" },
144
+ "A/m": { singular: "ampere per meter", plural: "amperes per meter" },
145
+ // Magnetic Units
146
+ T: { singular: "tesla", plural: "teslas" },
147
+ mT: { singular: "millitesla", plural: "milliteslas" },
148
+ \u03BCT: { singular: "microtesla", plural: "microteslas" },
149
+ G: { singular: "gauss", plural: "" },
150
+ Wb: { singular: "weber", plural: "webers" },
151
+ mWb: { singular: "milliweber", plural: "milliwebers" },
152
+ \u03BCWb: { singular: "microweber", plural: "microwebers" },
153
+ // Density Units
154
+ "kg/m\xB3": {
155
+ singular: "kilogram per cubic meter",
156
+ plural: "kilograms per cubic meter"
157
+ },
158
+ "g/cm\xB3": {
159
+ singular: "gram per cubic centimeter",
160
+ plural: "grams per cubic centimeter"
161
+ },
162
+ "g/mL": { singular: "gram per milliliter", plural: "grams per milliliter" },
163
+ "lb/ft\xB3": {
164
+ singular: "pound per cubic foot",
165
+ plural: "pounds per cubic foot"
166
+ },
167
+ "lb/in\xB3": {
168
+ singular: "pound per cubic inch",
169
+ plural: "pounds per cubic inch"
170
+ },
171
+ sg: { singular: "specific gravity", plural: "" },
172
+ // Volumetric Flow Units
173
+ "m\xB3/s": {
174
+ singular: "cubic meter per second",
175
+ plural: "cubic meters per second"
176
+ },
177
+ "L/s": { singular: "liter per second", plural: "liters per second" },
178
+ "L/min": { singular: "liter per minute", plural: "liters per minute" },
179
+ "L/h": { singular: "liter per hour", plural: "liters per hour" },
180
+ "gal/min": { singular: "gallon per minute", plural: "gallons per minute" },
181
+ "ft\xB3/s": {
182
+ singular: "cubic foot per second",
183
+ plural: "cubic feet per second"
184
+ },
185
+ "bbl/d": { singular: "barrel per day", plural: "barrels per day" },
186
+ // Fuel Economy Units
187
+ "L/100km": { singular: "liter per 100 kilometers", plural: "" },
188
+ mpg: { singular: "mile per gallon", plural: "miles per gallon" },
189
+ mpg_imp: {
190
+ singular: "mile per gallon imperial",
191
+ plural: "miles per gallon imperial"
192
+ },
193
+ "L/km": { singular: "liter per kilometer", plural: "liters per kilometer" },
194
+ "L/m": { singular: "liter per meter", plural: "liters per meter" },
195
+ // Concentration Units
196
+ ppm: { singular: "part per million", plural: "parts per million" },
197
+ ppb: { singular: "part per billion", plural: "parts per billion" },
198
+ ppt: { singular: "part per trillion", plural: "parts per trillion" },
199
+ "mol/L": { singular: "mole per liter", plural: "moles per liter" },
200
+ "mol/m\xB3": {
201
+ singular: "mole per cubic meter",
202
+ plural: "moles per cubic meter"
203
+ },
204
+ "mg/L": { singular: "milligram per liter", plural: "milligrams per liter" },
205
+ "g/L": { singular: "gram per liter", plural: "grams per liter" },
206
+ "mg/kg": {
207
+ singular: "milligram per kilogram",
208
+ plural: "milligrams per kilogram"
209
+ },
210
+ // Illumination Units
211
+ lm: { singular: "lumen", plural: "lumens" },
212
+ cd: { singular: "candela", plural: "candelas" },
213
+ lx: { singular: "lux", plural: "" },
214
+ "ft-cd": { singular: "foot-candle", plural: "foot-candles" },
215
+ // Radiation Units
216
+ Bq: { singular: "becquerel", plural: "becquerels" },
217
+ Ci: { singular: "curie", plural: "curies" },
218
+ Sv: { singular: "sievert", plural: "sieverts" },
219
+ Gy: { singular: "gray", plural: "grays" },
220
+ // Catalytic Activity Units
221
+ kat: { singular: "katal", plural: "katals" },
222
+ U: { singular: "enzyme unit", plural: "enzyme units" },
223
+ // Viscosity and Fluid Properties Units
224
+ "Pa\xB7s": { singular: "pascal second", plural: "pascal seconds" },
225
+ cP: { singular: "centipoise", plural: "" },
226
+ "kg/(m\xB7s)": {
227
+ singular: "kilogram per meter second",
228
+ plural: "kilograms per meter second"
229
+ },
230
+ "lb/(ft\xB7s)": {
231
+ singular: "pound per foot second",
232
+ plural: "pounds per foot second"
233
+ },
234
+ "m\xB2/s": {
235
+ singular: "square meter per second",
236
+ plural: "square meters per second"
237
+ },
238
+ St: { singular: "stokes", plural: "" },
239
+ cSt: { singular: "centistokes", plural: "" },
240
+ "N/m": { singular: "newton per meter", plural: "newtons per meter" },
241
+ "dyn/cm": { singular: "dyne per centimeter", plural: "dynes per centimeter" },
242
+ // Thermal Properties Units
243
+ "W/(m\xB7K)": {
244
+ singular: "watt per meter kelvin",
245
+ plural: "watts per meter kelvin"
246
+ },
247
+ "cal/(cm\xB7s\xB7\xB0C)": {
248
+ singular: "calorie per centimeter second degree Celsius",
249
+ plural: "calories per centimeter second degree Celsius"
250
+ },
251
+ "J/(kg\xB7K)": {
252
+ singular: "joule per kilogram kelvin",
253
+ plural: "joules per kilogram kelvin"
254
+ },
255
+ "cal/(g\xB7\xB0C)": {
256
+ singular: "calorie per gram degree Celsius",
257
+ plural: "calories per gram degree Celsius"
258
+ },
259
+ "1/K": { singular: "per kelvin", plural: "" },
260
+ "1/\xB0C": { singular: "per degree Celsius", plural: "" },
261
+ "W/m\xB2": {
262
+ singular: "watt per square meter",
263
+ plural: "watts per square meter"
264
+ },
265
+ "cal/(cm\xB2\xB7s)": {
266
+ singular: "calorie per square centimeter second",
267
+ plural: "calories per square centimeter second"
268
+ },
269
+ "W/(m\xB2\xB7K)": {
270
+ singular: "watt per square meter kelvin",
271
+ plural: "watts per square meter kelvin"
272
+ },
273
+ "cal/(cm\xB2\xB7s\xB7\xB0C)": {
274
+ singular: "calorie per square centimeter second degree Celsius",
275
+ plural: "calories per square centimeter second degree Celsius"
276
+ },
277
+ "K/W": { singular: "kelvin per watt", plural: "kelvins per watt" },
278
+ "\xB0C/W": {
279
+ singular: "degree Celsius per watt",
280
+ plural: "degrees Celsius per watt"
281
+ },
282
+ // Data Transfer and Storage Units
283
+ b: { singular: "bit", plural: "bits" },
284
+ B: { singular: "byte", plural: "bytes" },
285
+ kb: { singular: "kilobit", plural: "kilobits" },
286
+ kB: { singular: "kilobyte", plural: "kilobytes" },
287
+ Mb: { singular: "megabit", plural: "megabits" },
288
+ MB: { singular: "megabyte", plural: "megabytes" },
289
+ Gb: { singular: "gigabit", plural: "gigabits" },
290
+ GB: { singular: "gigabyte", plural: "gigabytes" },
291
+ Tb: { singular: "terabit", plural: "terabits" },
292
+ TB: { singular: "terabyte", plural: "terabytes" },
293
+ bps: { singular: "bit per second", plural: "bits per second" },
294
+ kbps: { singular: "kilobit per second", plural: "kilobits per second" },
295
+ Mbps: { singular: "megabit per second", plural: "megabits per second" },
296
+ Gbps: { singular: "gigabit per second", plural: "gigabits per second" }
297
+ };
298
+ var numbers = {
299
+ ones: ["", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"],
300
+ teens: ["ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"],
301
+ tens: ["", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"],
302
+ scales: ["", "thousand", "million", "billion", "trillion", "quadrillion", "quintillion"]};
303
+ var currencySymbols = {
304
+ $: {
305
+ singular: "dollar",
306
+ plural: "dollars",
307
+ fraction: { singular: "cent", plural: "cents" }
308
+ },
309
+ "\u20AC": {
310
+ singular: "euro",
311
+ plural: "euros",
312
+ fraction: { singular: "cent", plural: "cents" }
313
+ },
314
+ "\xA3": {
315
+ singular: "pound",
316
+ plural: "pounds",
317
+ fraction: { singular: "penny", plural: "pence" }
318
+ },
319
+ "\xA5": {
320
+ singular: "yen",
321
+ plural: "yen",
322
+ fraction: null
323
+ },
324
+ "\u20B9": {
325
+ singular: "rupee",
326
+ plural: "rupees",
327
+ fraction: { singular: "paisa", plural: "paise" }
328
+ }
329
+ };
330
+ var currencyCodes = {
331
+ USD: {
332
+ singular: "dollar",
333
+ plural: "dollars",
334
+ fraction: { singular: "cent", plural: "cents" }
335
+ },
336
+ EUR: {
337
+ singular: "euro",
338
+ plural: "euros",
339
+ fraction: { singular: "cent", plural: "cents" }
340
+ },
341
+ GBP: {
342
+ singular: "pound",
343
+ plural: "pounds",
344
+ fraction: { singular: "penny", plural: "pence" }
345
+ },
346
+ JPY: {
347
+ singular: "yen",
348
+ plural: "yen",
349
+ fraction: null
350
+ },
351
+ INR: {
352
+ singular: "rupee",
353
+ plural: "rupees",
354
+ fraction: { singular: "paisa", plural: "paise" }
355
+ },
356
+ CHF: {
357
+ singular: "Swiss franc",
358
+ plural: "Swiss francs",
359
+ fraction: { singular: "rappen", plural: "rappen" }
360
+ },
361
+ AUD: {
362
+ singular: "Australian dollar",
363
+ plural: "Australian dollars",
364
+ fraction: { singular: "cent", plural: "cents" }
365
+ },
366
+ CAD: {
367
+ singular: "Canadian dollar",
368
+ plural: "Canadian dollars",
369
+ fraction: { singular: "cent", plural: "cents" }
370
+ }
371
+ };
372
+ var currencies = {
373
+ ...currencySymbols,
374
+ ...currencyCodes
375
+ };
376
+ var math = {
377
+ "+": "plus",
378
+ "-": "minus",
379
+ "*": "times",
380
+ "\xD7": "times",
381
+ "\xB7": "times",
382
+ "/": "divided by",
383
+ "\xF7": "divided by",
384
+ ":": "divided by",
385
+ "^": "to the power of"
386
+ };
387
+
388
+ // src/utils/extraction/regexPatterns.ts
389
+ var sanitizeString = (str) => {
390
+ return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
391
+ };
392
+ var currencySymbolsSanitized = Object.keys(currencySymbols).map((key) => sanitizeString(key)).join("|");
393
+ var currencyCodesSanitized = Object.keys(currencyCodes).join("|");
394
+ var allUnits = Object.keys(units).map((key) => sanitizeString(key)).sort((a, b) => b.length - a.length).join("|");
395
+ var operatorSymbols = Object.keys(math).map((operator) => sanitizeString(operator)).join("|");
396
+ var regexMatches = new RegExp(
397
+ [
398
+ // Currency Matching (Highest Priority)
399
+ `(?<=^|\\s)(?:(?<symbolCurrency>(?<negativeSignSymbol>-)?(?<currencySymbol>${currencySymbolsSanitized})\\s*(?<symbolInt>(?:\\d{1,3}(?:,\\d{3})*|\\d+))(?:\\.(?<symbolDec>\\d+))?)|(?<codeCurrency>(?<negativeSignCode>-)?(?<codeInt>(?:\\d{1,3}(?:,\\d{3})*|\\d+))(?:\\.(?<codeDec>\\d+))?[ \\t]*(?<currencyCode>${currencyCodesSanitized})))(?=(?:\\s|$|(?:\\.(?!\\d))|[^\\d.]))`,
400
+ // Ensures the match is followed by whitespace, end of string, or non-numeric characters
401
+ // Scientific Notation 5e-10, 5e10, 5.5e10, 5.5e-10
402
+ `|(?<scientific>(?<negativeSignScientific>-)?(?<scientificInt>\\d+)(?:\\.(?<scientificDec>\\d+))?(?:[eE])(?<scientificExponent>[+-]?\\d+))(?=(?:\\s|$|(?:\\.(?!\\d))|[^\\d.]))`,
403
+ // Ensures the match is followed by whitespace, end of string, or non-numeric characters
404
+ // Numeric Units 5km, 10m/s, 10m/s^2, 10m/s², 10m²/s, 10m²/s²
405
+ `|(?<unit>(?<negativeSignUnit>-)?(?<unitInt>(?:\\d{1,3}(?:,\\d{3})*|\\d+))(?:\\.(?<unitDec>\\d+))?\\s*(?:\\^(?<unitCaretExponentPre>-?\\d+)|(?<unitSuperExponentPre>\u207B?[\xB9\xB2\xB3\u2074\u2075\u2076\u2077\u2078\u2079]))?\\s*(?<unitName>(?:${allUnits})\\b)(?:\\^(?<unitCaretExponentPost>-?\\d+)|(?<unitSuperExponentPost>\u207B?[\xB9\xB2\xB3\u2074\u2075\u2076\u2077\u2078\u2079]))?)(?=(?:\\s|$|(?:\\.(?!\\d))|[^\\d.]))`,
406
+ // Ensures the match is followed by whitespace, end of string, or non-numeric characters
407
+ // Number with optional exponent
408
+ `|(?<!\\w)(?<number>(?<negativeSignInteger>-)?(?<integerInt>(?:\\d{1,3}(?:,\\d{3})*|\\d+))(?:\\.(?<integerDec>\\d+))?(?:(?:\\^(?<integerCaretExponent>-?\\d+))|(?<integerSuperExponent>\u207B?[\xB9\xB2\xB3\u2074\u2075\u2076\u2077\u2078\u2079]))?)(?=(?:\\s|$|(?:\\.(?!\\d))|[^\\d.]))`,
409
+ // Ensures the match is followed by whitespace, end of string, or non-numeric characters
410
+ // Unit Only (e.g., m, kg, m², kg³)
411
+ `|(?<unitOnly>(?<![\\w.])(?<unitNameOnly>(?:${allUnits})\\b)(?:\\^(?<unitOnlyCaretExponent>-?\\d+)|(?<unitOnlySuperExponent>\u207B?[\xB9\xB2\xB3\u2074\u2075\u2076\u2077\u2078\u2079]))?(?!\\w))(?=(?:\\s|$|(?:\\.(?!\\d))|[^\\d.]))`,
412
+ // Ensures the match is followed by whitespace, end of string, or non-numeric characters
413
+ // Mathematical Operators
414
+ `|(?<operator>(?:(?<=^)|(?<=\\s))(${operatorSymbols})(?=\\s|$|(?:\\.(?!\\d))))`
415
+ // Matches mathematical operators
416
+ ].join(""),
417
+ "u"
418
+ );
419
+
420
+ // src/utils/extraction/patternExtractor.ts
421
+ function extractFirstMatch(input) {
422
+ const match = input.match(regexMatches);
423
+ if (match && match.groups && match.index !== void 0) {
424
+ const matchedGroup = Object.fromEntries(Object.entries(match.groups).filter(([_, value]) => value !== void 0));
425
+ let matchType = Object.keys(matchedGroup)[0];
426
+ const extractedGroup = {};
427
+ switch (matchType) {
428
+ case "symbolCurrency":
429
+ extractedGroup.integer = matchedGroup["symbolInt"];
430
+ extractedGroup.decimal = matchedGroup["symbolDec"];
431
+ extractedGroup.negativeInt = matchedGroup["negativeSignSymbol"] !== void 0;
432
+ extractedGroup.currency = matchedGroup["currencySymbol"];
433
+ break;
434
+ case "codeCurrency":
435
+ extractedGroup.integer = matchedGroup["codeInt"];
436
+ extractedGroup.decimal = matchedGroup["codeDec"];
437
+ extractedGroup.negativeInt = matchedGroup["negativeSignCode"] !== void 0;
438
+ extractedGroup.currency = matchedGroup["currencyCode"];
439
+ break;
440
+ case "scientific":
441
+ extractedGroup.integer = matchedGroup["scientificInt"];
442
+ extractedGroup.decimal = matchedGroup["scientificDec"];
443
+ extractedGroup.negativeInt = matchedGroup["negativeSignScientific"] !== void 0;
444
+ extractedGroup.exponent = matchedGroup["scientificExponent"];
445
+ break;
446
+ case "unit":
447
+ extractedGroup.integer = matchedGroup["unitInt"];
448
+ extractedGroup.decimal = matchedGroup["unitDec"];
449
+ extractedGroup.negativeInt = matchedGroup["negativeSignUnit"] !== void 0;
450
+ extractedGroup.unit = matchedGroup["unitName"];
451
+ extractedGroup.exponent = matchedGroup["unitCaretExponentPre"] || matchedGroup["unitSuperExponentPre"];
452
+ extractedGroup.unitExponent = matchedGroup["unitCaretExponentPost"] || matchedGroup["unitSuperExponentPost"];
453
+ break;
454
+ case "unitOnly":
455
+ extractedGroup.unit = matchedGroup["unitNameOnly"];
456
+ extractedGroup.unitExponent = matchedGroup["unitOnlyCaretExponent"] || matchedGroup["unitOnlySuperExponent"];
457
+ break;
458
+ case "operator":
459
+ break;
460
+ case "number":
461
+ extractedGroup.integer = matchedGroup["integerInt"];
462
+ extractedGroup.decimal = matchedGroup["integerDec"];
463
+ extractedGroup.exponent = matchedGroup["integerSuperExponent"] || matchedGroup["integerCaretExponent"];
464
+ extractedGroup.negativeInt = matchedGroup["negativeSignInteger"] !== void 0;
465
+ break;
466
+ }
467
+ extractedGroup.matchType = matchType;
468
+ extractedGroup.input = matchedGroup[matchType];
469
+ extractedGroup.index = match.index;
470
+ if (matchType !== "operator" && matchType !== "scientific" && matchType !== "unitOnly")
471
+ extractedGroup.integer = extractedGroup.integer !== void 0 ? extractedGroup.integer.replace(/,/g, "") : "0";
472
+ return extractedGroup;
473
+ }
474
+ return null;
475
+ }
476
+ function extractAllMatches(input) {
477
+ const results = [];
478
+ let remainingInput = input;
479
+ let currentExtraction = extractFirstMatch(remainingInput);
480
+ while (currentExtraction !== null && currentExtraction.input) {
481
+ const remainingLength = input.length - remainingInput.length;
482
+ if (results.length > 0) {
483
+ currentExtraction.index = remainingInput.indexOf(currentExtraction.input) + remainingLength;
484
+ }
485
+ results.push(currentExtraction);
486
+ remainingInput = remainingInput.substring(
487
+ remainingInput.indexOf(currentExtraction.input) + currentExtraction.input.length
488
+ );
489
+ currentExtraction = extractFirstMatch(remainingInput);
490
+ }
491
+ return results;
492
+ }
493
+
494
+ // src/utils/stringBuilding/zeroTo999.ts
495
+ function zeroTo999(num) {
496
+ if (num === 0) {
497
+ return "";
498
+ }
499
+ let words = "";
500
+ if (num >= 100) {
501
+ words += numbers.ones[Math.floor(num / 100)] + " hundred";
502
+ num %= 100;
503
+ if (num > 0) {
504
+ words += " ";
505
+ }
506
+ }
507
+ if (num >= 20) {
508
+ words += numbers.tens[Math.floor(num / 10)];
509
+ num %= 10;
510
+ if (num > 0) {
511
+ words += " " + numbers.ones[num];
512
+ }
513
+ } else if (num >= 10) {
514
+ words += numbers.teens[num - 10];
515
+ } else if (num > 0) {
516
+ words += numbers.ones[num];
517
+ }
518
+ return words;
519
+ }
520
+
521
+ // src/utils/stringBuilding/positiveInteger.ts
522
+ function positiveInteger(num) {
523
+ if (typeof num !== "number" || !Number.isInteger(num) || num < 0) {
524
+ return "Invalid input: Please provide a non-negative integer.";
525
+ }
526
+ if (num === 0) {
527
+ return "zero";
528
+ }
529
+ let words = "";
530
+ let scaleIndex = 0;
531
+ while (num > 0) {
532
+ if (num % 1e3 !== 0) {
533
+ const upToHundreds = zeroTo999(num % 1e3);
534
+ const magnitudeScale = numbers.scales[scaleIndex] ? " " + numbers.scales[scaleIndex] : "";
535
+ words = upToHundreds + magnitudeScale + (words ? " " + words : "");
536
+ }
537
+ num = Math.floor(num / 1e3);
538
+ scaleIndex++;
539
+ }
540
+ return words.trim().replace(/\s+/g, " ");
541
+ }
542
+
543
+ // src/utils/stringBuilding/twoDigits.ts
544
+ function twoDigit(num) {
545
+ if (num.trim().length !== 2) return "";
546
+ let parsed = parseInt(num);
547
+ if (parsed < 100 && parsed >= 0) return positiveInteger(parsed);
548
+ return "";
549
+ }
550
+
551
+ // src/utils/stringBuilding/negative.ts
552
+ var negative = (bool) => {
553
+ return bool ? "negative " : "";
554
+ };
555
+
556
+ // src/converters/convertCurrencyToSpokenWord.ts
557
+ function convertCurrencyToSpokenWord(amount) {
558
+ let sentence = "";
559
+ const { integer, decimal, negativeInt, currency } = amount;
560
+ let currencyConfig = currencies[currency];
561
+ let parsedInteger = parseInt(integer);
562
+ sentence += negative(negativeInt);
563
+ sentence += positiveInteger(parsedInteger) + " ";
564
+ sentence += parsedInteger < 2 ? currencyConfig.singular : currencyConfig.plural + " ";
565
+ if (decimal !== void 0 && currencyConfig.fraction !== null && currencyConfig.fraction !== void 0) {
566
+ sentence += "and ";
567
+ sentence += twoDigit(decimal) + " ";
568
+ sentence += parseInt(decimal) < 2 ? currencyConfig.fraction.singular : currencyConfig.fraction.plural;
569
+ }
570
+ return sentence.trim();
571
+ }
572
+
573
+ // src/utils/stringBuilding/perDigit.ts
574
+ function perDigit(num) {
575
+ const words = [];
576
+ for (let i = 0; i < num.length; i++) {
577
+ words.push(positiveInteger(parseInt(num[i])));
578
+ }
579
+ return words.join(" ");
580
+ }
581
+
582
+ // src/utils/parseSuperscript.ts
583
+ function toRegularInteger(superscriptString) {
584
+ const superscriptMap = {
585
+ "\u2070": "0",
586
+ "\xB9": "1",
587
+ "\xB2": "2",
588
+ "\xB3": "3",
589
+ "\u2074": "4",
590
+ "\u2075": "5",
591
+ "\u2076": "6",
592
+ "\u2077": "7",
593
+ "\u2078": "8",
594
+ "\u2079": "9"
595
+ };
596
+ let standardDigitString = "";
597
+ for (let char of superscriptString) {
598
+ if (superscriptMap[char]) {
599
+ standardDigitString += superscriptMap[char];
600
+ } else {
601
+ standardDigitString += char;
602
+ }
603
+ }
604
+ return standardDigitString;
605
+ }
606
+
607
+ // src/utils/stringBuilding/exponent.ts
608
+ function exponentSpokenWord(exponent, onlyUsePowerOf = false) {
609
+ const isNegative = exponent.startsWith("-") || exponent.startsWith("\u207B");
610
+ let newExponentString = toRegularInteger(isNegative ? exponent.slice(1) : exponent);
611
+ if (!onlyUsePowerOf && !isNegative) {
612
+ if (newExponentString === "2") {
613
+ return "squared";
614
+ }
615
+ if (newExponentString === "3") {
616
+ return "cubed";
617
+ }
618
+ }
619
+ let res = "to the power of " + (isNegative ? "negative " : "") + positiveInteger(parseInt(newExponentString));
620
+ return res;
621
+ }
622
+
623
+ // src/converters/convertNumberToSpokenWord.ts
624
+ function convertNumberToSpokenWord(num) {
625
+ const { integer, decimal, negativeInt, exponent } = num;
626
+ let sentence = negative(negativeInt);
627
+ sentence += positiveInteger(parseInt(integer)) + " ";
628
+ if (decimal !== void 0) {
629
+ sentence += "point ";
630
+ if (decimal.length === 1 || decimal.length > 2) {
631
+ sentence += perDigit(decimal) + " ";
632
+ } else {
633
+ sentence += twoDigit(decimal) + " ";
634
+ }
635
+ }
636
+ if (exponent !== void 0) {
637
+ sentence += exponentSpokenWord(exponent, true);
638
+ }
639
+ return sentence.trim();
640
+ }
641
+
642
+ // src/converters/convertNumericUnitToSpokenWord.ts
643
+ function convertNumericUnitToSpokenWord(numericUnit) {
644
+ const { integer, decimal, unit, negativeInt, exponent, unitExponent } = numericUnit;
645
+ let sentence = convertNumberToSpokenWord({
646
+ integer,
647
+ decimal,
648
+ negativeInt});
649
+ let spokenUnit;
650
+ let directUnitKey = unit + (unitExponent !== void 0 ? unitExponent : "");
651
+ let directUnit = units[directUnitKey];
652
+ if (directUnit !== void 0) {
653
+ spokenUnit = directUnit;
654
+ } else {
655
+ spokenUnit = units[unit];
656
+ }
657
+ if (spokenUnit === void 0) {
658
+ return "";
659
+ }
660
+ let isPlural = parseFloat(integer + "." + decimal) > 1 && spokenUnit.plural;
661
+ let spokenNumberExponent = "";
662
+ let spokenUnitExponent = "";
663
+ if (exponent !== void 0) {
664
+ spokenNumberExponent = exponentSpokenWord(exponent, true);
665
+ }
666
+ if (unitExponent !== void 0 && directUnit === void 0) {
667
+ spokenUnitExponent = exponentSpokenWord(unitExponent);
668
+ }
669
+ sentence += " " + spokenNumberExponent + " " + (isPlural ? spokenUnit.plural : spokenUnit.singular) + " " + spokenUnitExponent;
670
+ sentence = sentence.trim().replace(/\s+/g, " ");
671
+ return sentence;
672
+ }
673
+
674
+ // src/converters/convertOperatorToSpokenWord.ts
675
+ function convertOperatorToSpokenWord(operatorObject) {
676
+ const { input } = operatorObject;
677
+ if (input === void 0) {
678
+ return "";
679
+ }
680
+ return math[input];
681
+ }
682
+
683
+ // src/converters/convertScientificExpressionToSpokenWord.ts
684
+ function convertScientificExpressionToSpokenWord(expression) {
685
+ const { integer, decimal, exponent, negativeInt } = expression;
686
+ const isNegativeExponent = exponent.startsWith("-") || exponent.startsWith("\u207B");
687
+ let E = "times ten to the power of ";
688
+ let sentence = convertNumberToSpokenWord({
689
+ integer,
690
+ decimal,
691
+ negativeInt}) + " " + E + convertNumberToSpokenWord({
692
+ decimal: void 0,
693
+ negativeInt: isNegativeExponent,
694
+ integer: toRegularInteger(isNegativeExponent ? exponent.slice(1) : exponent)});
695
+ return sentence.trim();
696
+ }
697
+
698
+ // src/converters/convertUnitOnlyToSpokenWord.ts
699
+ function convertUnitOnlyToSpokenWord(unitOnlyObject) {
700
+ const { unit, unitExponent } = unitOnlyObject;
701
+ let spokenUnit;
702
+ spokenUnit = units[unit];
703
+ let result = "";
704
+ if (spokenUnit === void 0) {
705
+ return "";
706
+ }
707
+ if (unitExponent !== void 0) {
708
+ result = spokenUnit.singular + " " + exponentSpokenWord(unitExponent);
709
+ } else {
710
+ result = spokenUnit.singular;
711
+ }
712
+ return result;
713
+ }
714
+
715
+ // src/utils/validateExtractionResultObject.ts
716
+ function isValidIntegerString(str, allowNegative = false) {
717
+ if (str === void 0) {
718
+ return true;
719
+ }
720
+ let regex;
721
+ if (allowNegative) {
722
+ regex = /^(?:[\u207B\u002D]?[\d\u2070-\u2079]+)$/;
723
+ } else {
724
+ regex = /^[\d\u2070-\u2079]+$/;
725
+ }
726
+ return regex.test(str);
727
+ }
728
+ function validateExtractionResult(extractionResult) {
729
+ if (!extractionResult) {
730
+ throw new Error("validateExtractionResult: ExtractionResult cannot be null or undefined.");
731
+ }
732
+ if (typeof extractionResult !== "object") {
733
+ throw new Error("validateExtractionResult: ExtractionResult must be an object.");
734
+ }
735
+ if (!("input" in extractionResult)) {
736
+ throw new Error("validateExtractionResult: ExtractionResult is missing the 'input' property.");
737
+ }
738
+ if (typeof extractionResult.input !== "string") {
739
+ throw new Error("validateExtractionResult: ExtractionResult 'input' property must be a string.");
740
+ }
741
+ if (!("matchType" in extractionResult)) {
742
+ throw new Error("validateExtractionResult: ExtractionResult is missing the 'matchType' property.");
743
+ }
744
+ if (typeof extractionResult.matchType !== "string") {
745
+ throw new Error("validateExtractionResult: ExtractionResult 'matchType' property must be a string.");
746
+ }
747
+ if (!("index" in extractionResult)) {
748
+ throw new Error("validateExtractionResult: ExtractionResult is missing the 'index' property.");
749
+ }
750
+ if (typeof extractionResult.index !== "number") {
751
+ throw new Error("validateExtractionResult: ExtractionResult 'index' property must be a number.");
752
+ }
753
+ const { matchType } = extractionResult;
754
+ switch (matchType) {
755
+ case "number":
756
+ if (!("integer" in extractionResult)) {
757
+ throw new Error(
758
+ "validateExtractionResult: For matchType 'number', ExtractionResult is missing the 'integer' property."
759
+ );
760
+ }
761
+ if (typeof extractionResult.integer !== "string") {
762
+ throw new Error(
763
+ "validateExtractionResult: For matchType 'number', ExtractionResult 'integer' property must be a string."
764
+ );
765
+ }
766
+ if (!isValidIntegerString(extractionResult.integer)) {
767
+ throw new Error(
768
+ "validateExtractionResult: For matchType 'number', ExtractionResult 'integer' property must contain only integers."
769
+ );
770
+ }
771
+ if ("decimal" in extractionResult && extractionResult.decimal !== void 0 && typeof extractionResult.decimal !== "string") {
772
+ throw new Error(
773
+ "validateExtractionResult: For matchType 'number', ExtractionResult 'decimal' property must be a string if present."
774
+ );
775
+ }
776
+ if ("decimal" in extractionResult && extractionResult.decimal !== void 0 && !isValidIntegerString(extractionResult.decimal)) {
777
+ throw new Error(
778
+ "validateExtractionResult: For matchType 'number', ExtractionResult 'decimal' property must contain only integers."
779
+ );
780
+ }
781
+ if (!("negativeInt" in extractionResult)) {
782
+ throw new Error(
783
+ "validateExtractionResult: For matchType 'number', ExtractionResult is missing the 'negativeInt' property."
784
+ );
785
+ }
786
+ if (typeof extractionResult.negativeInt !== "boolean") {
787
+ throw new Error(
788
+ "validateExtractionResult: For matchType 'number', ExtractionResult 'negativeInt' property must be a boolean."
789
+ );
790
+ }
791
+ if ("exponent" in extractionResult && extractionResult.exponent !== void 0 && typeof extractionResult.exponent !== "string") {
792
+ throw new Error(
793
+ "validateExtractionResult: For matchType 'number', ExtractionResult 'exponent' property must be a string if present."
794
+ );
795
+ }
796
+ if ("exponent" in extractionResult && extractionResult.exponent !== void 0 && !isValidIntegerString(extractionResult.exponent, true)) {
797
+ throw new Error(
798
+ "validateExtractionResult: For matchType 'number', ExtractionResult 'exponent' property must contain only integers or superscript integers (and their respective negative symbol - and \u207B)."
799
+ );
800
+ }
801
+ break;
802
+ case "symbolCurrency":
803
+ case "codeCurrency":
804
+ if (!("integer" in extractionResult)) {
805
+ throw new Error(
806
+ `validateExtractionResult: For matchType '${matchType}', ExtractionResult is missing the 'integer' property.`
807
+ );
808
+ }
809
+ if (typeof extractionResult.integer !== "string") {
810
+ throw new Error(
811
+ `validateExtractionResult: For matchType '${matchType}', ExtractionResult 'integer' property must be a string.`
812
+ );
813
+ }
814
+ if (!isValidIntegerString(extractionResult.integer)) {
815
+ throw new Error(
816
+ `validateExtractionResult: For matchType '${matchType}', ExtractionResult 'integer' property must contain only integers.`
817
+ );
818
+ }
819
+ if ("decimal" in extractionResult && extractionResult.decimal !== void 0 && typeof extractionResult.decimal !== "string") {
820
+ throw new Error(
821
+ `validateExtractionResult: For matchType '${matchType}', ExtractionResult 'decimal' property must be a string if present.`
822
+ );
823
+ }
824
+ if ("decimal" in extractionResult && extractionResult.decimal !== void 0 && !isValidIntegerString(extractionResult.decimal)) {
825
+ throw new Error(
826
+ `validateExtractionResult: For matchType '${matchType}', ExtractionResult 'decimal' property must contain only integers.`
827
+ );
828
+ }
829
+ if (!("negativeInt" in extractionResult)) {
830
+ throw new Error(
831
+ `validateExtractionResult: For matchType '${matchType}', ExtractionResult is missing the 'negativeInt' property.`
832
+ );
833
+ }
834
+ if (typeof extractionResult.negativeInt !== "boolean") {
835
+ throw new Error(
836
+ `validateExtractionResult: For matchType '${matchType}', ExtractionResult 'negativeInt' property must be a boolean.`
837
+ );
838
+ }
839
+ if (!("currency" in extractionResult)) {
840
+ throw new Error(
841
+ `validateExtractionResult: For matchType '${matchType}', ExtractionResult is missing the 'currency' property.`
842
+ );
843
+ }
844
+ if (typeof extractionResult.currency !== "string") {
845
+ throw new Error(
846
+ `validateExtractionResult: For matchType '${matchType}', ExtractionResult 'currency' property must be a string.`
847
+ );
848
+ }
849
+ break;
850
+ case "unit":
851
+ if (!("integer" in extractionResult)) {
852
+ throw new Error(
853
+ "validateExtractionResult: For matchType 'unit', ExtractionResult is missing the 'integer' property."
854
+ );
855
+ }
856
+ if (typeof extractionResult.integer !== "string") {
857
+ throw new Error(
858
+ "validateExtractionResult: For matchType 'unit', ExtractionResult 'integer' property must be a string."
859
+ );
860
+ }
861
+ if (!isValidIntegerString(extractionResult.integer)) {
862
+ throw new Error(
863
+ "validateExtractionResult: For matchType 'unit', ExtractionResult 'integer' property must contain only integers."
864
+ );
865
+ }
866
+ if ("decimal" in extractionResult && extractionResult.decimal !== void 0 && typeof extractionResult.decimal !== "string") {
867
+ throw new Error(
868
+ "validateExtractionResult: For matchType 'unit', ExtractionResult 'decimal' property must be a string if present."
869
+ );
870
+ }
871
+ if ("decimal" in extractionResult && extractionResult.decimal !== void 0 && !isValidIntegerString(extractionResult.decimal)) {
872
+ throw new Error(
873
+ "validateExtractionResult: For matchType 'unit', ExtractionResult 'decimal' property must contain only integers."
874
+ );
875
+ }
876
+ if (!("negativeInt" in extractionResult)) {
877
+ throw new Error(
878
+ "validateExtractionResult: For matchType 'unit', ExtractionResult is missing the 'negativeInt' property."
879
+ );
880
+ }
881
+ if (typeof extractionResult.negativeInt !== "boolean") {
882
+ throw new Error(
883
+ "validateExtractionResult: For matchType 'unit', ExtractionResult 'negativeInt' property must be a boolean."
884
+ );
885
+ }
886
+ if (!("unit" in extractionResult)) {
887
+ throw new Error(
888
+ "validateExtractionResult: For matchType 'unit', ExtractionResult is missing the 'unit' property."
889
+ );
890
+ }
891
+ if (typeof extractionResult.unit !== "string") {
892
+ throw new Error(
893
+ "validateExtractionResult: For matchType 'unit', ExtractionResult 'unit' property must be a string."
894
+ );
895
+ }
896
+ if ("exponent" in extractionResult && extractionResult.exponent !== void 0 && typeof extractionResult.exponent !== "string") {
897
+ throw new Error(
898
+ "validateExtractionResult: For matchType 'unit', ExtractionResult 'exponent' property must be a string if present."
899
+ );
900
+ }
901
+ if ("exponent" in extractionResult && extractionResult.exponent !== void 0 && !isValidIntegerString(extractionResult.exponent, true)) {
902
+ throw new Error(
903
+ "validateExtractionResult: For matchType 'unit', ExtractionResult 'exponent' property must contain only integers or superscript integers (and their respective negative symbol - and \u207B)."
904
+ );
905
+ }
906
+ if ("unitExponent" in extractionResult && extractionResult.unitExponent !== void 0 && typeof extractionResult.unitExponent !== "string") {
907
+ throw new Error(
908
+ "validateExtractionResult: For matchType 'unit', ExtractionResult 'unitExponent' property must be a string if present."
909
+ );
910
+ }
911
+ if ("unitExponent" in extractionResult && extractionResult.unitExponent !== void 0 && !isValidIntegerString(extractionResult.unitExponent, true)) {
912
+ throw new Error(
913
+ "validateExtractionResult: For matchType 'unit', ExtractionResult 'unitExponent' property must contain only integers or superscript integers (and their respective negative symbol - and \u207B)."
914
+ );
915
+ }
916
+ break;
917
+ case "unitOnly":
918
+ if (!("unit" in extractionResult)) {
919
+ throw new Error(
920
+ "validateExtractionResult: For matchType 'unitOnly', ExtractionResult is missing the 'unit' property."
921
+ );
922
+ }
923
+ if (typeof extractionResult.unit !== "string") {
924
+ throw new Error(
925
+ "validateExtractionResult: For matchType 'unitOnly', ExtractionResult 'unit' property must be a string."
926
+ );
927
+ }
928
+ if ("unitExponent" in extractionResult && extractionResult.unitExponent !== void 0 && typeof extractionResult.unitExponent !== "string") {
929
+ throw new Error(
930
+ "validateExtractionResult: For matchType 'unitOnly', ExtractionResult 'unitExponent' property must be a string if present."
931
+ );
932
+ }
933
+ if ("unitExponent" in extractionResult && extractionResult.unitExponent !== void 0 && !isValidIntegerString(extractionResult.unitExponent, true)) {
934
+ throw new Error(
935
+ "validateExtractionResult: For matchType 'unitOnly', ExtractionResult 'unitExponent' property must contain only integers or superscript integers (and their respective negative symbol - and \u207B)."
936
+ );
937
+ }
938
+ break;
939
+ case "operator":
940
+ break;
941
+ // No specific properties to validate for operator
942
+ case "scientific":
943
+ if (!("integer" in extractionResult)) {
944
+ throw new Error(
945
+ "validateExtractionResult: For matchType 'scientific', ExtractionResult is missing the 'integer' property."
946
+ );
947
+ }
948
+ if (typeof extractionResult.integer !== "string") {
949
+ throw new Error(
950
+ "validateExtractionResult: For matchType 'scientific', ExtractionResult 'integer' property must be a string."
951
+ );
952
+ }
953
+ if (!isValidIntegerString(extractionResult.integer)) {
954
+ throw new Error(
955
+ "validateExtractionResult: For matchType 'scientific', ExtractionResult 'integer' property must contain only integers."
956
+ );
957
+ }
958
+ if ("decimal" in extractionResult && extractionResult.decimal !== void 0 && typeof extractionResult.decimal !== "string") {
959
+ throw new Error(
960
+ "validateExtractionResult: For matchType 'scientific', ExtractionResult 'decimal' property must be a string if present."
961
+ );
962
+ }
963
+ if ("decimal" in extractionResult && extractionResult.decimal !== void 0 && !isValidIntegerString(extractionResult.decimal)) {
964
+ throw new Error(
965
+ "validateExtractionResult: For matchType 'scientific', ExtractionResult 'decimal' property must contain only integers."
966
+ );
967
+ }
968
+ if (!("negativeInt" in extractionResult)) {
969
+ throw new Error(
970
+ "validateExtractionResult: For matchType 'scientific', ExtractionResult is missing the 'negativeInt' property."
971
+ );
972
+ }
973
+ if (typeof extractionResult.negativeInt !== "boolean") {
974
+ throw new Error(
975
+ "validateExtractionResult: For matchType 'scientific', ExtractionResult 'negativeInt' property must be a boolean."
976
+ );
977
+ }
978
+ if (!("exponent" in extractionResult)) {
979
+ throw new Error(
980
+ "validateExtractionResult: For matchType 'scientific', ExtractionResult is missing the 'exponent' property."
981
+ );
982
+ }
983
+ if (extractionResult.exponent !== void 0 && typeof extractionResult.exponent !== "string") {
984
+ throw new Error(
985
+ "validateExtractionResult: For matchType 'scientific', ExtractionResult 'exponent' property must be a string."
986
+ );
987
+ }
988
+ if (extractionResult.exponent !== void 0 && !isValidIntegerString(extractionResult.exponent, true)) {
989
+ throw new Error(
990
+ "validateExtractionResult: For matchType 'scientific', ExtractionResult 'exponent' property must contain only integers or superscript integers (and their respective negative symbol - and \u207B)."
991
+ );
992
+ }
993
+ break;
994
+ default:
995
+ throw new Error(`validateExtractionResult: Unknown matchType: ${matchType}`);
996
+ }
997
+ }
998
+
999
+ // src/index.ts
1000
+ var extractQuantities = {
1001
+ /**
1002
+ * Extracts the first match (number || currency || unit || operator || scientific expression) from the input string.
1003
+ * @param {string} input - The string to extract from.
1004
+ * @returns {ExtractionResult | null} The extracted data or null if no match is found.
1005
+ */
1006
+ firstMatch: extractFirstMatch,
1007
+ /**
1008
+ * Extracts all matches (number || currency || unit || operator || scientific expression) from the input string.
1009
+ * @param {string} input - The string to extract from.
1010
+ * @returns {ExtractionResult[]} The extracted data.
1011
+ */
1012
+ allMatches: extractAllMatches
1013
+ };
1014
+ var convertQuantities = {
1015
+ /**
1016
+ * Translates an ExtractionResult object (number || currency || unit || operator || scientific expression) into its spoken word equivalent.
1017
+ *
1018
+ * @param {ExtractionResult} extractionResult - The ExtractionResult object to translate.
1019
+ * @returns {string} The spoken word equivalent of the ExtractionResult.
1020
+ */
1021
+ translateMatch: (extractionResult) => {
1022
+ let result = "";
1023
+ switch (extractionResult.matchType) {
1024
+ case "number":
1025
+ result = convertNumberToSpokenWord(extractionResult);
1026
+ break;
1027
+ case "symbolCurrency":
1028
+ result = convertCurrencyToSpokenWord(extractionResult);
1029
+ break;
1030
+ case "codeCurrency":
1031
+ result = convertCurrencyToSpokenWord(extractionResult);
1032
+ break;
1033
+ case "unit":
1034
+ result = convertNumericUnitToSpokenWord(extractionResult);
1035
+ break;
1036
+ case "unitOnly":
1037
+ result = convertUnitOnlyToSpokenWord(extractionResult);
1038
+ break;
1039
+ case "operator":
1040
+ result = convertOperatorToSpokenWord(extractionResult);
1041
+ break;
1042
+ case "scientific":
1043
+ result = convertScientificExpressionToSpokenWord(extractionResult);
1044
+ break;
1045
+ }
1046
+ return result;
1047
+ },
1048
+ /**
1049
+ * Extracts the first match (number || currency || unit || operator || scientific expression) from the input string
1050
+ * and translates it to its spoken word equivalent.
1051
+ *
1052
+ * @param {string} input - The string to extract and translate from.
1053
+ * @returns {string} The input string with the first match replaced by its spoken word equivalent,
1054
+ * or an empty string if no match is found.
1055
+ */
1056
+ autoReplaceFirstMatch: (input) => {
1057
+ const match = extractFirstMatch(input);
1058
+ if (!match) return "";
1059
+ return input.replace(match.input, convertQuantities.translateMatch(match));
1060
+ },
1061
+ /**
1062
+ * Extracts all matches (number || currency || unit || operator || scientific expression) from the input string
1063
+ * and translates them to their spoken word equivalents.
1064
+ *
1065
+ * @param {string} input - The string to extract and translate from.
1066
+ * @returns {string} The input string with all matches replaced by their spoken word equivalents. Returns the original string if no matches are found.
1067
+ */
1068
+ autoReplaceAllMatches: (input) => {
1069
+ const matches = extractAllMatches(input);
1070
+ if (matches.length === 0) {
1071
+ return input;
1072
+ }
1073
+ let output = "";
1074
+ let lastIndex = 0;
1075
+ for (const match of matches) {
1076
+ output += input.substring(lastIndex, match.index);
1077
+ output += convertQuantities.translateMatch(match);
1078
+ lastIndex = match.index + match.input.length;
1079
+ }
1080
+ output += input.substring(lastIndex);
1081
+ return output.replace(/\s+/g, " ").trim();
1082
+ }
1083
+ };
1084
+
1085
+ exports.convertQuantities = convertQuantities;
1086
+ exports.extractQuantities = extractQuantities;
1087
+ exports.validateExtractionResult = validateExtractionResult;
1088
+ //# sourceMappingURL=index.cjs.map
1089
+ //# sourceMappingURL=index.cjs.map