quantible 0.1.0-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 (102) hide show
  1. package/README.md +97 -0
  2. package/dist/cjs/config/default.js +395 -0
  3. package/dist/cjs/config/default.js.map +1 -0
  4. package/dist/cjs/converters/convertCurrencyToSpokenWord.js +28 -0
  5. package/dist/cjs/converters/convertCurrencyToSpokenWord.js.map +1 -0
  6. package/dist/cjs/converters/convertNumberToSpokenWord.js +32 -0
  7. package/dist/cjs/converters/convertNumberToSpokenWord.js.map +1 -0
  8. package/dist/cjs/converters/convertNumericUnitToSpokenWord.js +48 -0
  9. package/dist/cjs/converters/convertNumericUnitToSpokenWord.js.map +1 -0
  10. package/dist/cjs/converters/convertOperatorToSpokenWord.js +17 -0
  11. package/dist/cjs/converters/convertOperatorToSpokenWord.js.map +1 -0
  12. package/dist/cjs/converters/convertScientificExpressionToSpokenWord.js +35 -0
  13. package/dist/cjs/converters/convertScientificExpressionToSpokenWord.js.map +1 -0
  14. package/dist/cjs/converters/convertUnitOnlyToSpokenWord.js +27 -0
  15. package/dist/cjs/converters/convertUnitOnlyToSpokenWord.js.map +1 -0
  16. package/dist/cjs/index.js +116 -0
  17. package/dist/cjs/index.js.map +1 -0
  18. package/dist/cjs/interfaces/configurations/default.js +3 -0
  19. package/dist/cjs/interfaces/configurations/default.js.map +1 -0
  20. package/dist/cjs/interfaces/definitions.js +3 -0
  21. package/dist/cjs/interfaces/definitions.js.map +1 -0
  22. package/dist/cjs/utils/extraction/patternExtractor.js +96 -0
  23. package/dist/cjs/utils/extraction/patternExtractor.js.map +1 -0
  24. package/dist/cjs/utils/extraction/regexPatterns.js +65 -0
  25. package/dist/cjs/utils/extraction/regexPatterns.js.map +1 -0
  26. package/dist/cjs/utils/parseSuperscript.js +33 -0
  27. package/dist/cjs/utils/parseSuperscript.js.map +1 -0
  28. package/dist/cjs/utils/stringBuilding/exponent.js +21 -0
  29. package/dist/cjs/utils/stringBuilding/exponent.js.map +1 -0
  30. package/dist/cjs/utils/stringBuilding/negative.js +8 -0
  31. package/dist/cjs/utils/stringBuilding/negative.js.map +1 -0
  32. package/dist/cjs/utils/stringBuilding/perDigit.js +18 -0
  33. package/dist/cjs/utils/stringBuilding/perDigit.js.map +1 -0
  34. package/dist/cjs/utils/stringBuilding/positiveInteger.js +31 -0
  35. package/dist/cjs/utils/stringBuilding/positiveInteger.js.map +1 -0
  36. package/dist/cjs/utils/stringBuilding/twoDigits.js +18 -0
  37. package/dist/cjs/utils/stringBuilding/twoDigits.js.map +1 -0
  38. package/dist/cjs/utils/stringBuilding/zeroTo999.js +37 -0
  39. package/dist/cjs/utils/stringBuilding/zeroTo999.js.map +1 -0
  40. package/dist/cjs/utils/validateExtractionResultObject.js +206 -0
  41. package/dist/cjs/utils/validateExtractionResultObject.js.map +1 -0
  42. package/dist/esm/config/default.js +392 -0
  43. package/dist/esm/config/default.js.map +1 -0
  44. package/dist/esm/converters/convertCurrencyToSpokenWord.js +25 -0
  45. package/dist/esm/converters/convertCurrencyToSpokenWord.js.map +1 -0
  46. package/dist/esm/converters/convertNumberToSpokenWord.js +29 -0
  47. package/dist/esm/converters/convertNumberToSpokenWord.js.map +1 -0
  48. package/dist/esm/converters/convertNumericUnitToSpokenWord.js +45 -0
  49. package/dist/esm/converters/convertNumericUnitToSpokenWord.js.map +1 -0
  50. package/dist/esm/converters/convertOperatorToSpokenWord.js +14 -0
  51. package/dist/esm/converters/convertOperatorToSpokenWord.js.map +1 -0
  52. package/dist/esm/converters/convertScientificExpressionToSpokenWord.js +32 -0
  53. package/dist/esm/converters/convertScientificExpressionToSpokenWord.js.map +1 -0
  54. package/dist/esm/converters/convertUnitOnlyToSpokenWord.js +24 -0
  55. package/dist/esm/converters/convertUnitOnlyToSpokenWord.js.map +1 -0
  56. package/dist/esm/index.js +111 -0
  57. package/dist/esm/index.js.map +1 -0
  58. package/dist/esm/interfaces/configurations/default.js +2 -0
  59. package/dist/esm/interfaces/configurations/default.js.map +1 -0
  60. package/dist/esm/interfaces/definitions.js +2 -0
  61. package/dist/esm/interfaces/definitions.js.map +1 -0
  62. package/dist/esm/utils/extraction/patternExtractor.js +92 -0
  63. package/dist/esm/utils/extraction/patternExtractor.js.map +1 -0
  64. package/dist/esm/utils/extraction/regexPatterns.js +62 -0
  65. package/dist/esm/utils/extraction/regexPatterns.js.map +1 -0
  66. package/dist/esm/utils/parseSuperscript.js +30 -0
  67. package/dist/esm/utils/parseSuperscript.js.map +1 -0
  68. package/dist/esm/utils/stringBuilding/exponent.js +18 -0
  69. package/dist/esm/utils/stringBuilding/exponent.js.map +1 -0
  70. package/dist/esm/utils/stringBuilding/negative.js +4 -0
  71. package/dist/esm/utils/stringBuilding/negative.js.map +1 -0
  72. package/dist/esm/utils/stringBuilding/perDigit.js +15 -0
  73. package/dist/esm/utils/stringBuilding/perDigit.js.map +1 -0
  74. package/dist/esm/utils/stringBuilding/positiveInteger.js +28 -0
  75. package/dist/esm/utils/stringBuilding/positiveInteger.js.map +1 -0
  76. package/dist/esm/utils/stringBuilding/twoDigits.js +15 -0
  77. package/dist/esm/utils/stringBuilding/twoDigits.js.map +1 -0
  78. package/dist/esm/utils/stringBuilding/zeroTo999.js +34 -0
  79. package/dist/esm/utils/stringBuilding/zeroTo999.js.map +1 -0
  80. package/dist/esm/utils/validateExtractionResultObject.js +203 -0
  81. package/dist/esm/utils/validateExtractionResultObject.js.map +1 -0
  82. package/dist/types/config/default.d.ts +39 -0
  83. package/dist/types/converters/convertCurrencyToSpokenWord.d.ts +7 -0
  84. package/dist/types/converters/convertNumberToSpokenWord.d.ts +7 -0
  85. package/dist/types/converters/convertNumericUnitToSpokenWord.d.ts +7 -0
  86. package/dist/types/converters/convertOperatorToSpokenWord.d.ts +7 -0
  87. package/dist/types/converters/convertScientificExpressionToSpokenWord.d.ts +7 -0
  88. package/dist/types/converters/convertUnitOnlyToSpokenWord.d.ts +7 -0
  89. package/dist/types/index.d.ts +58 -0
  90. package/dist/types/interfaces/configurations/default.d.ts +22 -0
  91. package/dist/types/interfaces/definitions.d.ts +100 -0
  92. package/dist/types/utils/extraction/patternExtractor.d.ts +21 -0
  93. package/dist/types/utils/extraction/regexPatterns.d.ts +2 -0
  94. package/dist/types/utils/parseSuperscript.d.ts +6 -0
  95. package/dist/types/utils/stringBuilding/exponent.d.ts +2 -0
  96. package/dist/types/utils/stringBuilding/negative.d.ts +1 -0
  97. package/dist/types/utils/stringBuilding/perDigit.d.ts +7 -0
  98. package/dist/types/utils/stringBuilding/positiveInteger.d.ts +6 -0
  99. package/dist/types/utils/stringBuilding/twoDigits.d.ts +6 -0
  100. package/dist/types/utils/stringBuilding/zeroTo999.d.ts +6 -0
  101. package/dist/types/utils/validateExtractionResultObject.d.ts +12 -0
  102. package/package.json +61 -0
@@ -0,0 +1,15 @@
1
+ import { positiveInteger } from "./positiveInteger";
2
+ /**
3
+ * Converts each digit in a number to words, and returns them as a joined string.
4
+ * @param num The number to convert, as a string.
5
+ * @returns A string of space-separated words, where each word is a digit in the original number.
6
+ * @example convertPerDigit("123") => "one two three"
7
+ */
8
+ export function perDigit(num) {
9
+ const words = [];
10
+ for (let i = 0; i < num.length; i++) {
11
+ words.push(positiveInteger(parseInt(num[i])));
12
+ }
13
+ return words.join(" ");
14
+ }
15
+ //# sourceMappingURL=perDigit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"perDigit.js","sourceRoot":"","sources":["../../../../src/utils/stringBuilding/perDigit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD;;;;;GAKG;AAEH,MAAM,UAAU,QAAQ,CAAC,GAAW;IAClC,MAAM,KAAK,GAAG,EAAE,CAAC;IACjB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACpC,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAChD,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACzB,CAAC"}
@@ -0,0 +1,28 @@
1
+ import { numbers } from "../../config/default";
2
+ import { zeroTo999 } from "./zeroTo999";
3
+ /**
4
+ * Converts a non-negative integer into its full English word representation.
5
+ * @param num The integer to convert.
6
+ * @returns The word representation of the number, or an error message for invalid input.
7
+ */
8
+ export function positiveInteger(num) {
9
+ if (typeof num !== "number" || !Number.isInteger(num) || num < 0) {
10
+ return "Invalid input: Please provide a non-negative integer.";
11
+ }
12
+ if (num === 0) {
13
+ return "zero";
14
+ }
15
+ let words = "";
16
+ let scaleIndex = 0;
17
+ while (num > 0) {
18
+ if (num % 1000 !== 0) {
19
+ const upToHundreds = zeroTo999(num % 1000);
20
+ const magnitudeScale = numbers.scales[scaleIndex] ? " " + numbers.scales[scaleIndex] : "";
21
+ words = upToHundreds + magnitudeScale + (words ? " " + words : "");
22
+ }
23
+ num = Math.floor(num / 1000);
24
+ scaleIndex++;
25
+ }
26
+ return words.trim().replace(/\s+/g, " ");
27
+ }
28
+ //# sourceMappingURL=positiveInteger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"positiveInteger.js","sourceRoot":"","sources":["../../../../src/utils/stringBuilding/positiveInteger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC;;;;GAIG;AAEH,MAAM,UAAU,eAAe,CAAC,GAAW;IACzC,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,GAAG,GAAG,CAAC,EAAE,CAAC;QACjE,OAAO,uDAAuD,CAAC;IACjE,CAAC;IAED,IAAI,GAAG,KAAK,CAAC,EAAE,CAAC;QACd,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,IAAI,KAAK,GAAG,EAAE,CAAC;IACf,IAAI,UAAU,GAAG,CAAC,CAAC;IAEnB,OAAO,GAAG,GAAG,CAAC,EAAE,CAAC;QACf,IAAI,GAAG,GAAG,IAAI,KAAK,CAAC,EAAE,CAAC;YACrB,MAAM,YAAY,GAAG,SAAS,CAAC,GAAG,GAAG,IAAI,CAAC,CAAC;YAC3C,MAAM,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YAC1F,KAAK,GAAG,YAAY,GAAG,cAAc,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QACrE,CAAC;QACD,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,IAAI,CAAC,CAAC;QAC7B,UAAU,EAAE,CAAC;IACf,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAC3C,CAAC"}
@@ -0,0 +1,15 @@
1
+ import { positiveInteger } from "./positiveInteger";
2
+ /**
3
+ * Converts a given number of cents to words, provided it is a valid number between 0 and 99.
4
+ * @param num The number of cents to convert, as a string.
5
+ * @returns The word representation of the number of cents, or an empty string if the conversion failed.
6
+ */
7
+ export function twoDigit(num) {
8
+ if (num.trim().length !== 2)
9
+ return "";
10
+ let parsed = parseInt(num);
11
+ if (parsed < 100 && parsed >= 0)
12
+ return positiveInteger(parsed);
13
+ return "";
14
+ }
15
+ //# sourceMappingURL=twoDigits.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"twoDigits.js","sourceRoot":"","sources":["../../../../src/utils/stringBuilding/twoDigits.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD;;;;GAIG;AAEH,MAAM,UAAU,QAAQ,CAAC,GAAW;IAClC,IAAI,GAAG,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IACvC,IAAI,MAAM,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC;IAE3B,IAAI,MAAM,GAAG,GAAG,IAAI,MAAM,IAAI,CAAC;QAAE,OAAO,eAAe,CAAC,MAAM,CAAC,CAAC;IAChE,OAAO,EAAE,CAAC;AACZ,CAAC"}
@@ -0,0 +1,34 @@
1
+ import { numbers } from "../../config/default";
2
+ /**
3
+ * Converts a number less than 1000 into words.
4
+ * @param num The number to convert (0-999).
5
+ * @returns The word representation of the number.
6
+ */
7
+ export function zeroTo999(num) {
8
+ if (num === 0) {
9
+ return "";
10
+ }
11
+ let words = "";
12
+ if (num >= 100) {
13
+ words += numbers.ones[Math.floor(num / 100)] + " hundred";
14
+ num %= 100;
15
+ if (num > 0) {
16
+ words += " ";
17
+ }
18
+ }
19
+ if (num >= 20) {
20
+ words += numbers.tens[Math.floor(num / 10)];
21
+ num %= 10;
22
+ if (num > 0) {
23
+ words += " " + numbers.ones[num];
24
+ }
25
+ }
26
+ else if (num >= 10) {
27
+ words += numbers.teens[num - 10];
28
+ }
29
+ else if (num > 0) {
30
+ words += numbers.ones[num];
31
+ }
32
+ return words;
33
+ }
34
+ //# sourceMappingURL=zeroTo999.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zeroTo999.js","sourceRoot":"","sources":["../../../../src/utils/stringBuilding/zeroTo999.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C;;;;GAIG;AAEH,MAAM,UAAU,SAAS,CAAC,GAAW;IACnC,IAAI,GAAG,KAAK,CAAC,EAAE,CAAC;QACd,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,IAAI,KAAK,GAAG,EAAE,CAAC;IAEf,IAAI,GAAG,IAAI,GAAG,EAAE,CAAC;QACf,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC,GAAG,UAAU,CAAC;QAC1D,GAAG,IAAI,GAAG,CAAC;QACX,IAAI,GAAG,GAAG,CAAC,EAAE,CAAC;YACZ,KAAK,IAAI,GAAG,CAAC;QACf,CAAC;IACH,CAAC;IAED,IAAI,GAAG,IAAI,EAAE,EAAE,CAAC;QACd,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,EAAE,CAAC,CAAC,CAAC;QAC5C,GAAG,IAAI,EAAE,CAAC;QACV,IAAI,GAAG,GAAG,CAAC,EAAE,CAAC;YACZ,KAAK,IAAI,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACnC,CAAC;IACH,CAAC;SAAM,IAAI,GAAG,IAAI,EAAE,EAAE,CAAC;QACrB,KAAK,IAAI,OAAO,CAAC,KAAK,CAAC,GAAG,GAAG,EAAE,CAAC,CAAC;IACnC,CAAC;SAAM,IAAI,GAAG,GAAG,CAAC,EAAE,CAAC;QACnB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,203 @@
1
+ function isValidIntegerString(str, allowNegative = false) {
2
+ if (str === undefined) {
3
+ return true;
4
+ }
5
+ let regex;
6
+ if (allowNegative) {
7
+ regex = /^(?:[\u207B\u002D]?[\d\u2070-\u2079]+)$/;
8
+ }
9
+ else {
10
+ regex = /^[\d\u2070-\u2079]+$/;
11
+ }
12
+ return regex.test(str);
13
+ }
14
+ /**
15
+ * Validates an ExtractionResult object.
16
+ *
17
+ * Checks that the object is present, contains the required properties, and that
18
+ * the values of those properties are of the correct type.
19
+ *
20
+ * If the object is invalid, throws an Error with a description of the problem.
21
+ *
22
+ * @param {ExtractionResult} extractionResult - The object to validate.
23
+ */
24
+ export function validateExtractionResult(extractionResult) {
25
+ if (!extractionResult) {
26
+ throw new Error("validateExtractionResult: ExtractionResult cannot be null or undefined.");
27
+ }
28
+ if (typeof extractionResult !== "object") {
29
+ throw new Error("validateExtractionResult: ExtractionResult must be an object.");
30
+ }
31
+ if (!("input" in extractionResult)) {
32
+ throw new Error("validateExtractionResult: ExtractionResult is missing the 'input' property.");
33
+ }
34
+ if (typeof extractionResult.input !== "string") {
35
+ throw new Error("validateExtractionResult: ExtractionResult 'input' property must be a string.");
36
+ }
37
+ if (!("matchType" in extractionResult)) {
38
+ throw new Error("validateExtractionResult: ExtractionResult is missing the 'matchType' property.");
39
+ }
40
+ if (typeof extractionResult.matchType !== "string") {
41
+ throw new Error("validateExtractionResult: ExtractionResult 'matchType' property must be a string.");
42
+ }
43
+ if (!("index" in extractionResult)) {
44
+ throw new Error("validateExtractionResult: ExtractionResult is missing the 'index' property.");
45
+ }
46
+ if (typeof extractionResult.index !== "number") {
47
+ throw new Error("validateExtractionResult: ExtractionResult 'index' property must be a number.");
48
+ }
49
+ const { matchType } = extractionResult;
50
+ switch (matchType) {
51
+ case "number":
52
+ if (!("integer" in extractionResult)) {
53
+ throw new Error("validateExtractionResult: For matchType 'number', ExtractionResult is missing the 'integer' property.");
54
+ }
55
+ if (typeof extractionResult.integer !== "string") {
56
+ throw new Error("validateExtractionResult: For matchType 'number', ExtractionResult 'integer' property must be a string.");
57
+ }
58
+ if (!isValidIntegerString(extractionResult.integer)) {
59
+ throw new Error("validateExtractionResult: For matchType 'number', ExtractionResult 'integer' property must contain only integers.");
60
+ }
61
+ if ("decimal" in extractionResult && extractionResult.decimal !== undefined && typeof extractionResult.decimal !== "string") {
62
+ throw new Error("validateExtractionResult: For matchType 'number', ExtractionResult 'decimal' property must be a string if present.");
63
+ }
64
+ if ("decimal" in extractionResult && extractionResult.decimal !== undefined && !isValidIntegerString(extractionResult.decimal)) {
65
+ throw new Error("validateExtractionResult: For matchType 'number', ExtractionResult 'decimal' property must contain only integers.");
66
+ }
67
+ if (!("negativeInt" in extractionResult)) {
68
+ throw new Error("validateExtractionResult: For matchType 'number', ExtractionResult is missing the 'negativeInt' property.");
69
+ }
70
+ if (typeof extractionResult.negativeInt !== "boolean") {
71
+ throw new Error("validateExtractionResult: For matchType 'number', ExtractionResult 'negativeInt' property must be a boolean.");
72
+ }
73
+ if ("exponent" in extractionResult && extractionResult.exponent !== undefined && typeof extractionResult.exponent !== "string") {
74
+ throw new Error("validateExtractionResult: For matchType 'number', ExtractionResult 'exponent' property must be a string if present.");
75
+ }
76
+ if ("exponent" in extractionResult && extractionResult.exponent !== undefined && !isValidIntegerString(extractionResult.exponent, true)) {
77
+ throw new Error("validateExtractionResult: For matchType 'number', ExtractionResult 'exponent' property must contain only integers or superscript integers (and their respective negative symbol - and ⁻).");
78
+ }
79
+ break;
80
+ case "symbolCurrency":
81
+ case "codeCurrency":
82
+ if (!("integer" in extractionResult)) {
83
+ throw new Error(`validateExtractionResult: For matchType '${matchType}', ExtractionResult is missing the 'integer' property.`);
84
+ }
85
+ if (typeof extractionResult.integer !== "string") {
86
+ throw new Error(`validateExtractionResult: For matchType '${matchType}', ExtractionResult 'integer' property must be a string.`);
87
+ }
88
+ if (!isValidIntegerString(extractionResult.integer)) {
89
+ throw new Error(`validateExtractionResult: For matchType '${matchType}', ExtractionResult 'integer' property must contain only integers.`);
90
+ }
91
+ if ("decimal" in extractionResult && extractionResult.decimal !== undefined && typeof extractionResult.decimal !== "string") {
92
+ throw new Error(`validateExtractionResult: For matchType '${matchType}', ExtractionResult 'decimal' property must be a string if present.`);
93
+ }
94
+ if ("decimal" in extractionResult && extractionResult.decimal !== undefined && !isValidIntegerString(extractionResult.decimal)) {
95
+ throw new Error(`validateExtractionResult: For matchType '${matchType}', ExtractionResult 'decimal' property must contain only integers.`);
96
+ }
97
+ if (!("negativeInt" in extractionResult)) {
98
+ throw new Error(`validateExtractionResult: For matchType '${matchType}', ExtractionResult is missing the 'negativeInt' property.`);
99
+ }
100
+ if (typeof extractionResult.negativeInt !== "boolean") {
101
+ throw new Error(`validateExtractionResult: For matchType '${matchType}', ExtractionResult 'negativeInt' property must be a boolean.`);
102
+ }
103
+ if (!("currency" in extractionResult)) {
104
+ throw new Error(`validateExtractionResult: For matchType '${matchType}', ExtractionResult is missing the 'currency' property.`);
105
+ }
106
+ if (typeof extractionResult.currency !== "string") {
107
+ throw new Error(`validateExtractionResult: For matchType '${matchType}', ExtractionResult 'currency' property must be a string.`);
108
+ }
109
+ break;
110
+ case "unit":
111
+ if (!("integer" in extractionResult)) {
112
+ throw new Error("validateExtractionResult: For matchType 'unit', ExtractionResult is missing the 'integer' property.");
113
+ }
114
+ if (typeof extractionResult.integer !== "string") {
115
+ throw new Error("validateExtractionResult: For matchType 'unit', ExtractionResult 'integer' property must be a string.");
116
+ }
117
+ if (!isValidIntegerString(extractionResult.integer)) {
118
+ throw new Error("validateExtractionResult: For matchType 'unit', ExtractionResult 'integer' property must contain only integers.");
119
+ }
120
+ if ("decimal" in extractionResult && extractionResult.decimal !== undefined && typeof extractionResult.decimal !== "string") {
121
+ throw new Error("validateExtractionResult: For matchType 'unit', ExtractionResult 'decimal' property must be a string if present.");
122
+ }
123
+ if ("decimal" in extractionResult && extractionResult.decimal !== undefined && !isValidIntegerString(extractionResult.decimal)) {
124
+ throw new Error("validateExtractionResult: For matchType 'unit', ExtractionResult 'decimal' property must contain only integers.");
125
+ }
126
+ if (!("negativeInt" in extractionResult)) {
127
+ throw new Error("validateExtractionResult: For matchType 'unit', ExtractionResult is missing the 'negativeInt' property.");
128
+ }
129
+ if (typeof extractionResult.negativeInt !== "boolean") {
130
+ throw new Error("validateExtractionResult: For matchType 'unit', ExtractionResult 'negativeInt' property must be a boolean.");
131
+ }
132
+ if (!("unit" in extractionResult)) {
133
+ throw new Error("validateExtractionResult: For matchType 'unit', ExtractionResult is missing the 'unit' property.");
134
+ }
135
+ if (typeof extractionResult.unit !== "string") {
136
+ throw new Error("validateExtractionResult: For matchType 'unit', ExtractionResult 'unit' property must be a string.");
137
+ }
138
+ if ("exponent" in extractionResult && extractionResult.exponent !== undefined && typeof extractionResult.exponent !== "string") {
139
+ throw new Error("validateExtractionResult: For matchType 'unit', ExtractionResult 'exponent' property must be a string if present.");
140
+ }
141
+ if ("exponent" in extractionResult && extractionResult.exponent !== undefined && !isValidIntegerString(extractionResult.exponent, true)) {
142
+ throw new Error("validateExtractionResult: For matchType 'unit', ExtractionResult 'exponent' property must contain only integers or superscript integers (and their respective negative symbol - and ⁻).");
143
+ }
144
+ if ("unitExponent" in extractionResult && extractionResult.unitExponent !== undefined && typeof extractionResult.unitExponent !== "string") {
145
+ throw new Error("validateExtractionResult: For matchType 'unit', ExtractionResult 'unitExponent' property must be a string if present.");
146
+ }
147
+ if ("unitExponent" in extractionResult && extractionResult.unitExponent !== undefined && !isValidIntegerString(extractionResult.unitExponent, true)) {
148
+ throw new Error("validateExtractionResult: For matchType 'unit', ExtractionResult 'unitExponent' property must contain only integers or superscript integers (and their respective negative symbol - and ⁻).");
149
+ }
150
+ break;
151
+ case "unitOnly":
152
+ if (!("unit" in extractionResult)) {
153
+ throw new Error("validateExtractionResult: For matchType 'unitOnly', ExtractionResult is missing the 'unit' property.");
154
+ }
155
+ if (typeof extractionResult.unit !== "string") {
156
+ throw new Error("validateExtractionResult: For matchType 'unitOnly', ExtractionResult 'unit' property must be a string.");
157
+ }
158
+ if ("unitExponent" in extractionResult && extractionResult.unitExponent !== undefined && typeof extractionResult.unitExponent !== "string") {
159
+ throw new Error("validateExtractionResult: For matchType 'unitOnly', ExtractionResult 'unitExponent' property must be a string if present.");
160
+ }
161
+ if ("unitExponent" in extractionResult && extractionResult.unitExponent !== undefined && !isValidIntegerString(extractionResult.unitExponent, true)) {
162
+ throw new Error("validateExtractionResult: For matchType 'unitOnly', ExtractionResult 'unitExponent' property must contain only integers or superscript integers (and their respective negative symbol - and ⁻).");
163
+ }
164
+ break;
165
+ case "operator":
166
+ break; // No specific properties to validate for operator
167
+ case "scientific":
168
+ if (!("integer" in extractionResult)) {
169
+ throw new Error("validateExtractionResult: For matchType 'scientific', ExtractionResult is missing the 'integer' property.");
170
+ }
171
+ if (typeof extractionResult.integer !== "string") {
172
+ throw new Error("validateExtractionResult: For matchType 'scientific', ExtractionResult 'integer' property must be a string.");
173
+ }
174
+ if (!isValidIntegerString(extractionResult.integer)) {
175
+ throw new Error("validateExtractionResult: For matchType 'scientific', ExtractionResult 'integer' property must contain only integers.");
176
+ }
177
+ if ("decimal" in extractionResult && extractionResult.decimal !== undefined && typeof extractionResult.decimal !== "string") {
178
+ throw new Error("validateExtractionResult: For matchType 'scientific', ExtractionResult 'decimal' property must be a string if present.");
179
+ }
180
+ if ("decimal" in extractionResult && extractionResult.decimal !== undefined && !isValidIntegerString(extractionResult.decimal)) {
181
+ throw new Error("validateExtractionResult: For matchType 'scientific', ExtractionResult 'decimal' property must contain only integers.");
182
+ }
183
+ if (!("negativeInt" in extractionResult)) {
184
+ throw new Error("validateExtractionResult: For matchType 'scientific', ExtractionResult is missing the 'negativeInt' property.");
185
+ }
186
+ if (typeof extractionResult.negativeInt !== "boolean") {
187
+ throw new Error("validateExtractionResult: For matchType 'scientific', ExtractionResult 'negativeInt' property must be a boolean.");
188
+ }
189
+ if (!("exponent" in extractionResult)) {
190
+ throw new Error("validateExtractionResult: For matchType 'scientific', ExtractionResult is missing the 'exponent' property.");
191
+ }
192
+ if (extractionResult.exponent !== undefined && typeof extractionResult.exponent !== "string") {
193
+ throw new Error("validateExtractionResult: For matchType 'scientific', ExtractionResult 'exponent' property must be a string.");
194
+ }
195
+ if (extractionResult.exponent !== undefined && !isValidIntegerString(extractionResult.exponent, true)) {
196
+ throw new Error("validateExtractionResult: For matchType 'scientific', ExtractionResult 'exponent' property must contain only integers or superscript integers (and their respective negative symbol - and ⁻).");
197
+ }
198
+ break;
199
+ default:
200
+ throw new Error(`validateExtractionResult: Unknown matchType: ${matchType}`);
201
+ }
202
+ }
203
+ //# sourceMappingURL=validateExtractionResultObject.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validateExtractionResultObject.js","sourceRoot":"","sources":["../../../src/utils/validateExtractionResultObject.ts"],"names":[],"mappings":"AAEA,SAAS,oBAAoB,CAAC,GAAuB,EAAE,gBAAyB,KAAK;IACnF,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QACtB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,KAAK,CAAC;IACV,IAAI,aAAa,EAAE,CAAC;QAClB,KAAK,GAAG,yCAAyC,CAAC;IACpD,CAAC;SAAM,CAAC;QACN,KAAK,GAAG,sBAAsB,CAAC;IACjC,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACzB,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,wBAAwB,CAAC,gBAAkC;IACzE,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CAAC,yEAAyE,CAAC,CAAC;IAC7F,CAAC;IAED,IAAI,OAAO,gBAAgB,KAAK,QAAQ,EAAE,CAAC;QACzC,MAAM,IAAI,KAAK,CAAC,+DAA+D,CAAC,CAAC;IACnF,CAAC;IAED,IAAI,CAAC,CAAC,OAAO,IAAI,gBAAgB,CAAC,EAAE,CAAC;QACnC,MAAM,IAAI,KAAK,CAAC,6EAA6E,CAAC,CAAC;IACjG,CAAC;IACD,IAAI,OAAO,gBAAgB,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC/C,MAAM,IAAI,KAAK,CAAC,+EAA+E,CAAC,CAAC;IACnG,CAAC;IAED,IAAI,CAAC,CAAC,WAAW,IAAI,gBAAgB,CAAC,EAAE,CAAC;QACvC,MAAM,IAAI,KAAK,CAAC,iFAAiF,CAAC,CAAC;IACrG,CAAC;IACD,IAAI,OAAO,gBAAgB,CAAC,SAAS,KAAK,QAAQ,EAAE,CAAC;QACnD,MAAM,IAAI,K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AAI,OAAO,gBAAgB,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;gBAC7F,MAAM,IAAI,KAAK,CAAC,8GAA8G,CAAC,CAAC;YAClI,CAAC;YACD,IAAI,gBAAgB,CAAC,QAAQ,KAAK,SAAS,IAAI,CAAC,oBAAoB,CAAC,gBAAgB,CAAC,QAAQ,EAAE,IAAI,CAAC,EAAE,CAAC;gBACtG,MAAM,IAAI,KAAK,CAAC,+LAA+L,CAAC,CAAC;YACnN,CAAC;YACD,MAAM;QAER;YACE,MAAM,IAAI,KAAK,CAAC,gDAAgD,SAAS,EAAE,CAAC,CAAC;IACjF,CAAC;AACH,CAAC"}
@@ -0,0 +1,39 @@
1
+ import { Currency, Unit } from "../interfaces/configurations/default";
2
+ export declare const units: {
3
+ [key: string]: Unit;
4
+ };
5
+ export declare const numbers: {
6
+ ones: string[];
7
+ teens: string[];
8
+ tens: string[];
9
+ scales: string[];
10
+ ordinals: {
11
+ one: string;
12
+ two: string;
13
+ three: string;
14
+ five: string;
15
+ eight: string;
16
+ nine: string;
17
+ twelve: string;
18
+ };
19
+ };
20
+ export declare const currencySymbols: {
21
+ [key: string]: Currency;
22
+ };
23
+ export declare const currencyCodes: {
24
+ [key: string]: Currency;
25
+ };
26
+ export declare const currencies: {
27
+ [x: string]: Currency;
28
+ };
29
+ export declare const math: {
30
+ "+": string;
31
+ "-": string;
32
+ "*": string;
33
+ "\u00D7": string;
34
+ "\u00B7": string;
35
+ "/": string;
36
+ "\u00F7": string;
37
+ ":": string;
38
+ "^": string;
39
+ };
@@ -0,0 +1,7 @@
1
+ import { baseCurrency } from "../interfaces/definitions";
2
+ /**
3
+ * Converts a currency object into its spoken word representation.
4
+ * @param {baseCurrency} amount - The currency object to convert.
5
+ * @returns {string} The spoken word representation of the currency.
6
+ */
7
+ export declare function convertCurrencyToSpokenWord(amount: baseCurrency): string;
@@ -0,0 +1,7 @@
1
+ import { baseNumber } from "../interfaces/definitions";
2
+ /**
3
+ * Converts a number object into its spoken word representation.
4
+ * @param {baseNumber} num - The number object to convert.
5
+ * @returns {string} The spoken word representation of the number.
6
+ */
7
+ export declare function convertNumberToSpokenWord(num: baseNumber): string;
@@ -0,0 +1,7 @@
1
+ import { baseNumberUnit } from "../interfaces/definitions";
2
+ /**
3
+ * Converts a numeric unit object into its spoken word representation.
4
+ * @param {baseNumberUnit} numericUnit - The numeric unit object to convert.
5
+ * @returns {string} The spoken word representation of the numeric unit.
6
+ */
7
+ export declare function convertNumericUnitToSpokenWord(numericUnit: baseNumberUnit): string;
@@ -0,0 +1,7 @@
1
+ import { baseOperator } from "../interfaces/definitions";
2
+ /**
3
+ * Converts an operator object into its spoken word representation.
4
+ * @param {baseOperator} operatorObject - The operator object to convert.
5
+ * @returns {string} The spoken word representation of the operator.
6
+ */
7
+ export declare function convertOperatorToSpokenWord(operatorObject: baseOperator): string;
@@ -0,0 +1,7 @@
1
+ import { baseScientific } from "../interfaces/definitions";
2
+ /**
3
+ * Converts a scientific expression object into its spoken word representation.
4
+ * @param {baseScientific} expression - The scientific expression object to convert.
5
+ * @returns {string} The spoken word representation of the scientific expression.
6
+ */
7
+ export declare function convertScientificExpressionToSpokenWord(expression: baseScientific): string;
@@ -0,0 +1,7 @@
1
+ import { baseUnitOnly } from "../interfaces/definitions";
2
+ /**
3
+ * Converts a unit-only object into its spoken word representation.
4
+ * @param {baseUnitOnly} unitOnlyObject - The unit-only object to convert.
5
+ * @returns {string} The spoken word representation of the unit.
6
+ */
7
+ export declare function convertUnitOnlyToSpokenWord(unitOnlyObject: baseUnitOnly): string;
@@ -0,0 +1,58 @@
1
+ import { extractFirstMatch, extractAllMatches } from "./utils/extraction/patternExtractor";
2
+ import { ExtractionResult } from "./interfaces/definitions";
3
+ import { validateExtractionResult } from "./utils/validateExtractionResultObject";
4
+ /**
5
+ * @namespace extractQuantities
6
+ * @description Contains functions for extracting numeric data from a string.
7
+ */
8
+ declare const extractQuantities: {
9
+ /**
10
+ * Extracts the first match (number || currency || unit || operator || scientific expression) from the input string.
11
+ * @param {string} input - The string to extract from.
12
+ * @returns {ExtractionResult | null} The extracted data or null if no match is found.
13
+ */
14
+ firstMatch: typeof extractFirstMatch;
15
+ /**
16
+ * Extracts all matches (number || currency || unit || operator || scientific expression) from the input string.
17
+ * @param {string} input - The string to extract from.
18
+ * @returns {ExtractionResult[]} The extracted data.
19
+ */
20
+ allMatches: typeof extractAllMatches;
21
+ };
22
+ /**
23
+ * @namespace convertQuantities
24
+ * @description Contains functions for converting (number || currency || unit || operator || scientific expression) data from a string or object to spoken word.
25
+ */
26
+ declare const convertQuantities: {
27
+ /**
28
+ * Translates an ExtractionResult object (number || currency || unit || operator || scientific expression) into its spoken word equivalent.
29
+ *
30
+ * @param {ExtractionResult} extractionResult - The ExtractionResult object to translate.
31
+ * @returns {string} The spoken word equivalent of the ExtractionResult.
32
+ */
33
+ /**
34
+ * Translates an ExtractionResult object (number || currency || unit || operator || scientific expression) into its spoken word equivalent.
35
+ *
36
+ * @param {ExtractionResult} extractionResult - The ExtractionResult object to translate.
37
+ * @returns {string} The spoken word equivalent of the ExtractionResult.
38
+ */
39
+ translateMatch: (extractionResult: ExtractionResult) => string;
40
+ /**
41
+ * Extracts the first match (number || currency || unit || operator || scientific expression) from the input string
42
+ * and translates it to its spoken word equivalent.
43
+ *
44
+ * @param {string} input - The string to extract and translate from.
45
+ * @returns {string} The input string with the first match replaced by its spoken word equivalent,
46
+ * or an empty string if no match is found.
47
+ */
48
+ autoReplaceFirstMatch: (input: string) => string;
49
+ /**
50
+ * Extracts all matches (number || currency || unit || operator || scientific expression) from the input string
51
+ * and translates them to their spoken word equivalents.
52
+ *
53
+ * @param {string} input - The string to extract and translate from.
54
+ * @returns {string} The input string with all matches replaced by their spoken word equivalents. Returns the original string if no matches are found.
55
+ */
56
+ autoReplaceAllMatches: (input: string) => string;
57
+ };
58
+ export { convertQuantities, extractQuantities, validateExtractionResult };
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Configuration for currency fraction (e.g., cents).
3
+ */
4
+ export interface CurrencyFractionConfig {
5
+ singular: string;
6
+ plural: string;
7
+ }
8
+ /**
9
+ * Configuration for currency (e.g., USD).
10
+ */
11
+ export interface Currency {
12
+ singular: string;
13
+ plural: string;
14
+ fraction: CurrencyFractionConfig | null;
15
+ }
16
+ /**
17
+ * Configuration for a unit (e.g., meter).
18
+ */
19
+ export interface Unit {
20
+ singular: string;
21
+ plural: string;
22
+ }
@@ -0,0 +1,100 @@
1
+ /**
2
+ * Represents the base structure for all extraction results,
3
+ * containing the input string, match type, index, and length of the extracted value.
4
+ */
5
+ interface baseExtraction {
6
+ input: string;
7
+ matchType: string;
8
+ index: number;
9
+ }
10
+ /**
11
+ * @interface numericBaseExtraction
12
+ * @extends {baseExtraction}
13
+ * @description Represents the base structure for numeric extraction results,
14
+ * extending the baseExtraction with properties for integer, decimal, and negative integer indication.
15
+ */
16
+ interface numericBaseExtraction extends baseExtraction {
17
+ integer: string;
18
+ decimal?: string;
19
+ negativeInt: boolean;
20
+ }
21
+ /**
22
+ * @interface baseCurrency
23
+ * @extends {numericBaseExtraction}
24
+ * @description Represents the structure for currency extraction results,
25
+ * extending the numericBaseExtraction with properties for match type (symbol or code) and currency symbol or code.
26
+ */
27
+ export interface baseCurrency extends numericBaseExtraction {
28
+ matchType: "symbolCurrency" | "codeCurrency";
29
+ currency: string;
30
+ }
31
+ /**
32
+ * @interface baseScientific
33
+ * @extends {numericBaseExtraction}
34
+ * @description Represents the structure for scientific notation extraction results,
35
+ * extending the numericBaseExtraction with properties for match type (scientific) and a mandatory exponent value.
36
+ */
37
+ export interface baseScientific extends numericBaseExtraction {
38
+ matchType: "scientific";
39
+ exponent: string;
40
+ }
41
+ /**
42
+ * @interface baseNumberUnit
43
+ * @extends {numericBaseExtraction}
44
+ * @description Represents the structure for quantitative unit extraction results,
45
+ * extending the numericBaseExtraction with properties for match type (unit), unit name, optional exponent, and optional unit exponent.
46
+ */
47
+ export interface baseNumberUnit extends numericBaseExtraction {
48
+ matchType: "unit";
49
+ unit: string;
50
+ exponent?: string;
51
+ unitExponent?: string;
52
+ }
53
+ /**
54
+ * @interface baseUnitOnly
55
+ * @extends {baseExtraction}
56
+ * @description Represents the structure for unit-only extraction results,
57
+ * extending the baseExtraction with properties for match type (unitOnly), unit name, and optional unit exponent.
58
+ */
59
+ export interface baseUnitOnly extends baseExtraction {
60
+ matchType: "unitOnly";
61
+ unit: string;
62
+ unitExponent?: string;
63
+ }
64
+ /**
65
+ * @interface baseOperator
66
+ * @extends {baseExtraction}
67
+ * @description Represents the structure for mathematical operator extraction results,
68
+ * extending the baseExtraction with a property for match type (operator).
69
+ */
70
+ export interface baseOperator extends baseExtraction {
71
+ matchType: "operator";
72
+ }
73
+ /**
74
+ * @interface baseNumber
75
+ * @extends {numericBaseExtraction}
76
+ * @description Represents the structure for number extraction results,
77
+ * extending the numericBaseExtraction with properties for match type (number) and an optional exponent.
78
+ */
79
+ export interface baseNumber extends numericBaseExtraction {
80
+ matchType: "number";
81
+ exponent?: string;
82
+ }
83
+ /**
84
+ * @interface ExtractionResult
85
+ * @description Represents all possible extraction results
86
+ * and contains all properties that can be extracted from a given input string.
87
+ */
88
+ export interface ExtractionResult {
89
+ input: string;
90
+ matchType: string;
91
+ index: number;
92
+ integer?: string;
93
+ decimal?: string;
94
+ negativeInt?: boolean;
95
+ currency?: string;
96
+ exponent?: string;
97
+ unit?: string;
98
+ unitExponent?: string;
99
+ }
100
+ export {};
@@ -0,0 +1,21 @@
1
+ import { ExtractionResult } from "../../interfaces/definitions";
2
+ /**
3
+ * Returns the first match of a number, currency, unit, or exponent in the given string.
4
+ * The returned object contains the extracted groups and additional information such as
5
+ * the type of match and the index of the match in the string.
6
+ *
7
+ * @param {string} input - The string to search for matches
8
+ * @returns {patternExtraction | null} - The extracted groups and additional information, or null if no match is found
9
+ */
10
+ export declare function extractFirstMatch(input: string): ExtractionResult | null;
11
+ /**
12
+ * Extracts all matches of a number, currency, unit, or exponent in the given string
13
+ * and returns an array of the extracted groups and additional information such as
14
+ * the type of match and the index of the match in the string.
15
+ *
16
+ * If the input string contains no matches, an empty array is returned.
17
+ *
18
+ * @param {string} input - The string to search for matches
19
+ * @returns {patternExtraction[]} - The extracted groups and additional information, or an empty array if no match is found
20
+ */
21
+ export declare function extractAllMatches(input: string): ExtractionResult[];
@@ -0,0 +1,2 @@
1
+ declare const regexMatches: RegExp;
2
+ export { regexMatches };