quantible 0.1.9-alpha → 0.1.11-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +83 -7
- package/dist/index.js +142 -86
- package/dist/index.js.map +1 -1
- package/package.json +5 -12
- package/dist/index.cjs +0 -1058
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -107
- package/dist/index.global.js +0 -1054
- package/dist/index.global.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,85 @@
|
|
|
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
|
+
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
|
+
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
|
+
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
|
+
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
|
+
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
|
+
interface baseNumber extends numericBaseExtraction {
|
|
80
|
+
matchType: "number";
|
|
81
|
+
exponent?: string;
|
|
82
|
+
}
|
|
1
83
|
/**
|
|
2
84
|
* @interface ExtractionResult
|
|
3
85
|
* @description Represents all possible extraction results
|
|
@@ -72,12 +154,6 @@ declare const extractQuantities: {
|
|
|
72
154
|
* @description Contains functions for converting (number || currency || unit || operator || scientific expression) data from a string or object to spoken word.
|
|
73
155
|
*/
|
|
74
156
|
declare const convertQuantities: {
|
|
75
|
-
/**
|
|
76
|
-
* Translates an ExtractionResult object (number || currency || unit || operator || scientific expression) into its spoken word equivalent.
|
|
77
|
-
*
|
|
78
|
-
* @param {ExtractionResult} extractionResult - The ExtractionResult object to translate.
|
|
79
|
-
* @returns {string} The spoken word equivalent of the ExtractionResult.
|
|
80
|
-
*/
|
|
81
157
|
/**
|
|
82
158
|
* Translates an ExtractionResult object (number || currency || unit || operator || scientific expression) into its spoken word equivalent.
|
|
83
159
|
*
|
|
@@ -104,4 +180,4 @@ declare const convertQuantities: {
|
|
|
104
180
|
autoReplaceAllMatches: (input: string) => string;
|
|
105
181
|
};
|
|
106
182
|
|
|
107
|
-
export { convertQuantities, extractQuantities, validateExtractionResult };
|
|
183
|
+
export { type ExtractionResult, type baseCurrency, type baseNumber, type baseNumberUnit, type baseOperator, type baseScientific, type baseUnitOnly, convertQuantities, extractQuantities, validateExtractionResult };
|
package/dist/index.js
CHANGED
|
@@ -297,17 +297,7 @@ var numbers = {
|
|
|
297
297
|
ones: ["", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"],
|
|
298
298
|
teens: ["ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"],
|
|
299
299
|
tens: ["", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"],
|
|
300
|
-
scales: ["", "thousand", "million", "billion", "trillion", "quadrillion", "quintillion"]
|
|
301
|
-
ordinals: {
|
|
302
|
-
one: "first",
|
|
303
|
-
two: "second",
|
|
304
|
-
three: "third",
|
|
305
|
-
five: "fifth",
|
|
306
|
-
eight: "eighth",
|
|
307
|
-
nine: "ninth",
|
|
308
|
-
twelve: "twelfth"
|
|
309
|
-
}
|
|
310
|
-
};
|
|
300
|
+
scales: ["", "thousand", "million", "billion", "trillion", "quadrillion", "quintillion"]};
|
|
311
301
|
var currencySymbols = {
|
|
312
302
|
$: {
|
|
313
303
|
singular: "dollar",
|
|
@@ -471,8 +461,6 @@ function extractFirstMatch(input) {
|
|
|
471
461
|
extractedGroup.exponent = matchedGroup["integerSuperExponent"] || matchedGroup["integerCaretExponent"];
|
|
472
462
|
extractedGroup.negativeInt = matchedGroup["negativeSignInteger"] !== void 0;
|
|
473
463
|
break;
|
|
474
|
-
default:
|
|
475
|
-
break;
|
|
476
464
|
}
|
|
477
465
|
extractedGroup.matchType = matchType;
|
|
478
466
|
extractedGroup.input = matchedGroup[matchType];
|
|
@@ -655,11 +643,7 @@ function convertNumericUnitToSpokenWord(numericUnit) {
|
|
|
655
643
|
let sentence = convertNumberToSpokenWord({
|
|
656
644
|
integer,
|
|
657
645
|
decimal,
|
|
658
|
-
negativeInt
|
|
659
|
-
matchType: "number",
|
|
660
|
-
input: "",
|
|
661
|
-
index: 0
|
|
662
|
-
});
|
|
646
|
+
negativeInt});
|
|
663
647
|
let spokenUnit;
|
|
664
648
|
let directUnitKey = unit + (unitExponent !== void 0 ? unitExponent : "");
|
|
665
649
|
let directUnit = units[directUnitKey];
|
|
@@ -702,18 +686,10 @@ function convertScientificExpressionToSpokenWord(expression) {
|
|
|
702
686
|
let sentence = convertNumberToSpokenWord({
|
|
703
687
|
integer,
|
|
704
688
|
decimal,
|
|
705
|
-
negativeInt
|
|
706
|
-
matchType: "number",
|
|
707
|
-
input: "",
|
|
708
|
-
index: 0
|
|
709
|
-
}) + " " + E + convertNumberToSpokenWord({
|
|
689
|
+
negativeInt}) + " " + E + convertNumberToSpokenWord({
|
|
710
690
|
decimal: void 0,
|
|
711
691
|
negativeInt: isNegativeExponent,
|
|
712
|
-
integer: toRegularInteger(isNegativeExponent ? exponent.slice(1) : exponent)
|
|
713
|
-
matchType: "number",
|
|
714
|
-
input: "",
|
|
715
|
-
index: 0
|
|
716
|
-
});
|
|
692
|
+
integer: toRegularInteger(isNegativeExponent ? exponent.slice(1) : exponent)});
|
|
717
693
|
return sentence.trim();
|
|
718
694
|
}
|
|
719
695
|
|
|
@@ -776,116 +752,186 @@ function validateExtractionResult(extractionResult) {
|
|
|
776
752
|
switch (matchType) {
|
|
777
753
|
case "number":
|
|
778
754
|
if (!("integer" in extractionResult)) {
|
|
779
|
-
throw new Error(
|
|
755
|
+
throw new Error(
|
|
756
|
+
"validateExtractionResult: For matchType 'number', ExtractionResult is missing the 'integer' property."
|
|
757
|
+
);
|
|
780
758
|
}
|
|
781
759
|
if (typeof extractionResult.integer !== "string") {
|
|
782
|
-
throw new Error(
|
|
760
|
+
throw new Error(
|
|
761
|
+
"validateExtractionResult: For matchType 'number', ExtractionResult 'integer' property must be a string."
|
|
762
|
+
);
|
|
783
763
|
}
|
|
784
764
|
if (!isValidIntegerString(extractionResult.integer)) {
|
|
785
|
-
throw new Error(
|
|
765
|
+
throw new Error(
|
|
766
|
+
"validateExtractionResult: For matchType 'number', ExtractionResult 'integer' property must contain only integers."
|
|
767
|
+
);
|
|
786
768
|
}
|
|
787
769
|
if ("decimal" in extractionResult && extractionResult.decimal !== void 0 && typeof extractionResult.decimal !== "string") {
|
|
788
|
-
throw new Error(
|
|
770
|
+
throw new Error(
|
|
771
|
+
"validateExtractionResult: For matchType 'number', ExtractionResult 'decimal' property must be a string if present."
|
|
772
|
+
);
|
|
789
773
|
}
|
|
790
774
|
if ("decimal" in extractionResult && extractionResult.decimal !== void 0 && !isValidIntegerString(extractionResult.decimal)) {
|
|
791
|
-
throw new Error(
|
|
775
|
+
throw new Error(
|
|
776
|
+
"validateExtractionResult: For matchType 'number', ExtractionResult 'decimal' property must contain only integers."
|
|
777
|
+
);
|
|
792
778
|
}
|
|
793
779
|
if (!("negativeInt" in extractionResult)) {
|
|
794
|
-
throw new Error(
|
|
780
|
+
throw new Error(
|
|
781
|
+
"validateExtractionResult: For matchType 'number', ExtractionResult is missing the 'negativeInt' property."
|
|
782
|
+
);
|
|
795
783
|
}
|
|
796
784
|
if (typeof extractionResult.negativeInt !== "boolean") {
|
|
797
|
-
throw new Error(
|
|
785
|
+
throw new Error(
|
|
786
|
+
"validateExtractionResult: For matchType 'number', ExtractionResult 'negativeInt' property must be a boolean."
|
|
787
|
+
);
|
|
798
788
|
}
|
|
799
789
|
if ("exponent" in extractionResult && extractionResult.exponent !== void 0 && typeof extractionResult.exponent !== "string") {
|
|
800
|
-
throw new Error(
|
|
790
|
+
throw new Error(
|
|
791
|
+
"validateExtractionResult: For matchType 'number', ExtractionResult 'exponent' property must be a string if present."
|
|
792
|
+
);
|
|
801
793
|
}
|
|
802
794
|
if ("exponent" in extractionResult && extractionResult.exponent !== void 0 && !isValidIntegerString(extractionResult.exponent, true)) {
|
|
803
|
-
throw new Error(
|
|
795
|
+
throw new Error(
|
|
796
|
+
"validateExtractionResult: For matchType 'number', ExtractionResult 'exponent' property must contain only integers or superscript integers (and their respective negative symbol - and \u207B)."
|
|
797
|
+
);
|
|
804
798
|
}
|
|
805
799
|
break;
|
|
806
800
|
case "symbolCurrency":
|
|
807
801
|
case "codeCurrency":
|
|
808
802
|
if (!("integer" in extractionResult)) {
|
|
809
|
-
throw new Error(
|
|
803
|
+
throw new Error(
|
|
804
|
+
`validateExtractionResult: For matchType '${matchType}', ExtractionResult is missing the 'integer' property.`
|
|
805
|
+
);
|
|
810
806
|
}
|
|
811
807
|
if (typeof extractionResult.integer !== "string") {
|
|
812
|
-
throw new Error(
|
|
808
|
+
throw new Error(
|
|
809
|
+
`validateExtractionResult: For matchType '${matchType}', ExtractionResult 'integer' property must be a string.`
|
|
810
|
+
);
|
|
813
811
|
}
|
|
814
812
|
if (!isValidIntegerString(extractionResult.integer)) {
|
|
815
|
-
throw new Error(
|
|
813
|
+
throw new Error(
|
|
814
|
+
`validateExtractionResult: For matchType '${matchType}', ExtractionResult 'integer' property must contain only integers.`
|
|
815
|
+
);
|
|
816
816
|
}
|
|
817
817
|
if ("decimal" in extractionResult && extractionResult.decimal !== void 0 && typeof extractionResult.decimal !== "string") {
|
|
818
|
-
throw new Error(
|
|
818
|
+
throw new Error(
|
|
819
|
+
`validateExtractionResult: For matchType '${matchType}', ExtractionResult 'decimal' property must be a string if present.`
|
|
820
|
+
);
|
|
819
821
|
}
|
|
820
822
|
if ("decimal" in extractionResult && extractionResult.decimal !== void 0 && !isValidIntegerString(extractionResult.decimal)) {
|
|
821
|
-
throw new Error(
|
|
823
|
+
throw new Error(
|
|
824
|
+
`validateExtractionResult: For matchType '${matchType}', ExtractionResult 'decimal' property must contain only integers.`
|
|
825
|
+
);
|
|
822
826
|
}
|
|
823
827
|
if (!("negativeInt" in extractionResult)) {
|
|
824
|
-
throw new Error(
|
|
828
|
+
throw new Error(
|
|
829
|
+
`validateExtractionResult: For matchType '${matchType}', ExtractionResult is missing the 'negativeInt' property.`
|
|
830
|
+
);
|
|
825
831
|
}
|
|
826
832
|
if (typeof extractionResult.negativeInt !== "boolean") {
|
|
827
|
-
throw new Error(
|
|
833
|
+
throw new Error(
|
|
834
|
+
`validateExtractionResult: For matchType '${matchType}', ExtractionResult 'negativeInt' property must be a boolean.`
|
|
835
|
+
);
|
|
828
836
|
}
|
|
829
837
|
if (!("currency" in extractionResult)) {
|
|
830
|
-
throw new Error(
|
|
838
|
+
throw new Error(
|
|
839
|
+
`validateExtractionResult: For matchType '${matchType}', ExtractionResult is missing the 'currency' property.`
|
|
840
|
+
);
|
|
831
841
|
}
|
|
832
842
|
if (typeof extractionResult.currency !== "string") {
|
|
833
|
-
throw new Error(
|
|
843
|
+
throw new Error(
|
|
844
|
+
`validateExtractionResult: For matchType '${matchType}', ExtractionResult 'currency' property must be a string.`
|
|
845
|
+
);
|
|
834
846
|
}
|
|
835
847
|
break;
|
|
836
848
|
case "unit":
|
|
837
849
|
if (!("integer" in extractionResult)) {
|
|
838
|
-
throw new Error(
|
|
850
|
+
throw new Error(
|
|
851
|
+
"validateExtractionResult: For matchType 'unit', ExtractionResult is missing the 'integer' property."
|
|
852
|
+
);
|
|
839
853
|
}
|
|
840
854
|
if (typeof extractionResult.integer !== "string") {
|
|
841
|
-
throw new Error(
|
|
855
|
+
throw new Error(
|
|
856
|
+
"validateExtractionResult: For matchType 'unit', ExtractionResult 'integer' property must be a string."
|
|
857
|
+
);
|
|
842
858
|
}
|
|
843
859
|
if (!isValidIntegerString(extractionResult.integer)) {
|
|
844
|
-
throw new Error(
|
|
860
|
+
throw new Error(
|
|
861
|
+
"validateExtractionResult: For matchType 'unit', ExtractionResult 'integer' property must contain only integers."
|
|
862
|
+
);
|
|
845
863
|
}
|
|
846
864
|
if ("decimal" in extractionResult && extractionResult.decimal !== void 0 && typeof extractionResult.decimal !== "string") {
|
|
847
|
-
throw new Error(
|
|
865
|
+
throw new Error(
|
|
866
|
+
"validateExtractionResult: For matchType 'unit', ExtractionResult 'decimal' property must be a string if present."
|
|
867
|
+
);
|
|
848
868
|
}
|
|
849
869
|
if ("decimal" in extractionResult && extractionResult.decimal !== void 0 && !isValidIntegerString(extractionResult.decimal)) {
|
|
850
|
-
throw new Error(
|
|
870
|
+
throw new Error(
|
|
871
|
+
"validateExtractionResult: For matchType 'unit', ExtractionResult 'decimal' property must contain only integers."
|
|
872
|
+
);
|
|
851
873
|
}
|
|
852
874
|
if (!("negativeInt" in extractionResult)) {
|
|
853
|
-
throw new Error(
|
|
875
|
+
throw new Error(
|
|
876
|
+
"validateExtractionResult: For matchType 'unit', ExtractionResult is missing the 'negativeInt' property."
|
|
877
|
+
);
|
|
854
878
|
}
|
|
855
879
|
if (typeof extractionResult.negativeInt !== "boolean") {
|
|
856
|
-
throw new Error(
|
|
880
|
+
throw new Error(
|
|
881
|
+
"validateExtractionResult: For matchType 'unit', ExtractionResult 'negativeInt' property must be a boolean."
|
|
882
|
+
);
|
|
857
883
|
}
|
|
858
884
|
if (!("unit" in extractionResult)) {
|
|
859
|
-
throw new Error(
|
|
885
|
+
throw new Error(
|
|
886
|
+
"validateExtractionResult: For matchType 'unit', ExtractionResult is missing the 'unit' property."
|
|
887
|
+
);
|
|
860
888
|
}
|
|
861
889
|
if (typeof extractionResult.unit !== "string") {
|
|
862
|
-
throw new Error(
|
|
890
|
+
throw new Error(
|
|
891
|
+
"validateExtractionResult: For matchType 'unit', ExtractionResult 'unit' property must be a string."
|
|
892
|
+
);
|
|
863
893
|
}
|
|
864
894
|
if ("exponent" in extractionResult && extractionResult.exponent !== void 0 && typeof extractionResult.exponent !== "string") {
|
|
865
|
-
throw new Error(
|
|
895
|
+
throw new Error(
|
|
896
|
+
"validateExtractionResult: For matchType 'unit', ExtractionResult 'exponent' property must be a string if present."
|
|
897
|
+
);
|
|
866
898
|
}
|
|
867
899
|
if ("exponent" in extractionResult && extractionResult.exponent !== void 0 && !isValidIntegerString(extractionResult.exponent, true)) {
|
|
868
|
-
throw new Error(
|
|
900
|
+
throw new Error(
|
|
901
|
+
"validateExtractionResult: For matchType 'unit', ExtractionResult 'exponent' property must contain only integers or superscript integers (and their respective negative symbol - and \u207B)."
|
|
902
|
+
);
|
|
869
903
|
}
|
|
870
904
|
if ("unitExponent" in extractionResult && extractionResult.unitExponent !== void 0 && typeof extractionResult.unitExponent !== "string") {
|
|
871
|
-
throw new Error(
|
|
905
|
+
throw new Error(
|
|
906
|
+
"validateExtractionResult: For matchType 'unit', ExtractionResult 'unitExponent' property must be a string if present."
|
|
907
|
+
);
|
|
872
908
|
}
|
|
873
909
|
if ("unitExponent" in extractionResult && extractionResult.unitExponent !== void 0 && !isValidIntegerString(extractionResult.unitExponent, true)) {
|
|
874
|
-
throw new Error(
|
|
910
|
+
throw new Error(
|
|
911
|
+
"validateExtractionResult: For matchType 'unit', ExtractionResult 'unitExponent' property must contain only integers or superscript integers (and their respective negative symbol - and \u207B)."
|
|
912
|
+
);
|
|
875
913
|
}
|
|
876
914
|
break;
|
|
877
915
|
case "unitOnly":
|
|
878
916
|
if (!("unit" in extractionResult)) {
|
|
879
|
-
throw new Error(
|
|
917
|
+
throw new Error(
|
|
918
|
+
"validateExtractionResult: For matchType 'unitOnly', ExtractionResult is missing the 'unit' property."
|
|
919
|
+
);
|
|
880
920
|
}
|
|
881
921
|
if (typeof extractionResult.unit !== "string") {
|
|
882
|
-
throw new Error(
|
|
922
|
+
throw new Error(
|
|
923
|
+
"validateExtractionResult: For matchType 'unitOnly', ExtractionResult 'unit' property must be a string."
|
|
924
|
+
);
|
|
883
925
|
}
|
|
884
926
|
if ("unitExponent" in extractionResult && extractionResult.unitExponent !== void 0 && typeof extractionResult.unitExponent !== "string") {
|
|
885
|
-
throw new Error(
|
|
927
|
+
throw new Error(
|
|
928
|
+
"validateExtractionResult: For matchType 'unitOnly', ExtractionResult 'unitExponent' property must be a string if present."
|
|
929
|
+
);
|
|
886
930
|
}
|
|
887
931
|
if ("unitExponent" in extractionResult && extractionResult.unitExponent !== void 0 && !isValidIntegerString(extractionResult.unitExponent, true)) {
|
|
888
|
-
throw new Error(
|
|
932
|
+
throw new Error(
|
|
933
|
+
"validateExtractionResult: For matchType 'unitOnly', ExtractionResult 'unitExponent' property must contain only integers or superscript integers (and their respective negative symbol - and \u207B)."
|
|
934
|
+
);
|
|
889
935
|
}
|
|
890
936
|
break;
|
|
891
937
|
case "operator":
|
|
@@ -893,34 +939,54 @@ function validateExtractionResult(extractionResult) {
|
|
|
893
939
|
// No specific properties to validate for operator
|
|
894
940
|
case "scientific":
|
|
895
941
|
if (!("integer" in extractionResult)) {
|
|
896
|
-
throw new Error(
|
|
942
|
+
throw new Error(
|
|
943
|
+
"validateExtractionResult: For matchType 'scientific', ExtractionResult is missing the 'integer' property."
|
|
944
|
+
);
|
|
897
945
|
}
|
|
898
946
|
if (typeof extractionResult.integer !== "string") {
|
|
899
|
-
throw new Error(
|
|
947
|
+
throw new Error(
|
|
948
|
+
"validateExtractionResult: For matchType 'scientific', ExtractionResult 'integer' property must be a string."
|
|
949
|
+
);
|
|
900
950
|
}
|
|
901
951
|
if (!isValidIntegerString(extractionResult.integer)) {
|
|
902
|
-
throw new Error(
|
|
952
|
+
throw new Error(
|
|
953
|
+
"validateExtractionResult: For matchType 'scientific', ExtractionResult 'integer' property must contain only integers."
|
|
954
|
+
);
|
|
903
955
|
}
|
|
904
956
|
if ("decimal" in extractionResult && extractionResult.decimal !== void 0 && typeof extractionResult.decimal !== "string") {
|
|
905
|
-
throw new Error(
|
|
957
|
+
throw new Error(
|
|
958
|
+
"validateExtractionResult: For matchType 'scientific', ExtractionResult 'decimal' property must be a string if present."
|
|
959
|
+
);
|
|
906
960
|
}
|
|
907
961
|
if ("decimal" in extractionResult && extractionResult.decimal !== void 0 && !isValidIntegerString(extractionResult.decimal)) {
|
|
908
|
-
throw new Error(
|
|
962
|
+
throw new Error(
|
|
963
|
+
"validateExtractionResult: For matchType 'scientific', ExtractionResult 'decimal' property must contain only integers."
|
|
964
|
+
);
|
|
909
965
|
}
|
|
910
966
|
if (!("negativeInt" in extractionResult)) {
|
|
911
|
-
throw new Error(
|
|
967
|
+
throw new Error(
|
|
968
|
+
"validateExtractionResult: For matchType 'scientific', ExtractionResult is missing the 'negativeInt' property."
|
|
969
|
+
);
|
|
912
970
|
}
|
|
913
971
|
if (typeof extractionResult.negativeInt !== "boolean") {
|
|
914
|
-
throw new Error(
|
|
972
|
+
throw new Error(
|
|
973
|
+
"validateExtractionResult: For matchType 'scientific', ExtractionResult 'negativeInt' property must be a boolean."
|
|
974
|
+
);
|
|
915
975
|
}
|
|
916
976
|
if (!("exponent" in extractionResult)) {
|
|
917
|
-
throw new Error(
|
|
977
|
+
throw new Error(
|
|
978
|
+
"validateExtractionResult: For matchType 'scientific', ExtractionResult is missing the 'exponent' property."
|
|
979
|
+
);
|
|
918
980
|
}
|
|
919
981
|
if (extractionResult.exponent !== void 0 && typeof extractionResult.exponent !== "string") {
|
|
920
|
-
throw new Error(
|
|
982
|
+
throw new Error(
|
|
983
|
+
"validateExtractionResult: For matchType 'scientific', ExtractionResult 'exponent' property must be a string."
|
|
984
|
+
);
|
|
921
985
|
}
|
|
922
986
|
if (extractionResult.exponent !== void 0 && !isValidIntegerString(extractionResult.exponent, true)) {
|
|
923
|
-
throw new Error(
|
|
987
|
+
throw new Error(
|
|
988
|
+
"validateExtractionResult: For matchType 'scientific', ExtractionResult 'exponent' property must contain only integers or superscript integers (and their respective negative symbol - and \u207B)."
|
|
989
|
+
);
|
|
924
990
|
}
|
|
925
991
|
break;
|
|
926
992
|
default:
|
|
@@ -944,12 +1010,6 @@ var extractQuantities = {
|
|
|
944
1010
|
allMatches: extractAllMatches
|
|
945
1011
|
};
|
|
946
1012
|
var convertQuantities = {
|
|
947
|
-
/**
|
|
948
|
-
* Translates an ExtractionResult object (number || currency || unit || operator || scientific expression) into its spoken word equivalent.
|
|
949
|
-
*
|
|
950
|
-
* @param {ExtractionResult} extractionResult - The ExtractionResult object to translate.
|
|
951
|
-
* @returns {string} The spoken word equivalent of the ExtractionResult.
|
|
952
|
-
*/
|
|
953
1013
|
/**
|
|
954
1014
|
* Translates an ExtractionResult object (number || currency || unit || operator || scientific expression) into its spoken word equivalent.
|
|
955
1015
|
*
|
|
@@ -980,8 +1040,6 @@ var convertQuantities = {
|
|
|
980
1040
|
case "scientific":
|
|
981
1041
|
result = convertScientificExpressionToSpokenWord(extractionResult);
|
|
982
1042
|
break;
|
|
983
|
-
default:
|
|
984
|
-
break;
|
|
985
1043
|
}
|
|
986
1044
|
return result;
|
|
987
1045
|
},
|
|
@@ -1021,9 +1079,7 @@ var convertQuantities = {
|
|
|
1021
1079
|
return output.replace(/\s+/g, " ").trim();
|
|
1022
1080
|
}
|
|
1023
1081
|
};
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
validateExtractionResult
|
|
1028
|
-
};
|
|
1082
|
+
|
|
1083
|
+
export { convertQuantities, extractQuantities, validateExtractionResult };
|
|
1084
|
+
//# sourceMappingURL=index.js.map
|
|
1029
1085
|
//# sourceMappingURL=index.js.map
|