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