quantible 0.1.9-alpha → 0.1.12-alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,30 +1,4 @@
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);
1
+ 'use strict';
28
2
 
29
3
  // src/config/default.ts
30
4
  var units = {
@@ -325,17 +299,7 @@ var numbers = {
325
299
  ones: ["", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"],
326
300
  teens: ["ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"],
327
301
  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
- };
302
+ scales: ["", "thousand", "million", "billion", "trillion", "quadrillion", "quintillion"]};
339
303
  var currencySymbols = {
340
304
  $: {
341
305
  singular: "dollar",
@@ -499,8 +463,6 @@ function extractFirstMatch(input) {
499
463
  extractedGroup.exponent = matchedGroup["integerSuperExponent"] || matchedGroup["integerCaretExponent"];
500
464
  extractedGroup.negativeInt = matchedGroup["negativeSignInteger"] !== void 0;
501
465
  break;
502
- default:
503
- break;
504
466
  }
505
467
  extractedGroup.matchType = matchType;
506
468
  extractedGroup.input = matchedGroup[matchType];
@@ -683,11 +645,7 @@ function convertNumericUnitToSpokenWord(numericUnit) {
683
645
  let sentence = convertNumberToSpokenWord({
684
646
  integer,
685
647
  decimal,
686
- negativeInt,
687
- matchType: "number",
688
- input: "",
689
- index: 0
690
- });
648
+ negativeInt});
691
649
  let spokenUnit;
692
650
  let directUnitKey = unit + (unitExponent !== void 0 ? unitExponent : "");
693
651
  let directUnit = units[directUnitKey];
@@ -730,18 +688,10 @@ function convertScientificExpressionToSpokenWord(expression) {
730
688
  let sentence = convertNumberToSpokenWord({
731
689
  integer,
732
690
  decimal,
733
- negativeInt,
734
- matchType: "number",
735
- input: "",
736
- index: 0
737
- }) + " " + E + convertNumberToSpokenWord({
691
+ negativeInt}) + " " + E + convertNumberToSpokenWord({
738
692
  decimal: void 0,
739
693
  negativeInt: isNegativeExponent,
740
- integer: toRegularInteger(isNegativeExponent ? exponent.slice(1) : exponent),
741
- matchType: "number",
742
- input: "",
743
- index: 0
744
- });
694
+ integer: toRegularInteger(isNegativeExponent ? exponent.slice(1) : exponent)});
745
695
  return sentence.trim();
746
696
  }
747
697
 
@@ -804,116 +754,186 @@ function validateExtractionResult(extractionResult) {
804
754
  switch (matchType) {
805
755
  case "number":
806
756
  if (!("integer" in extractionResult)) {
807
- throw new Error("validateExtractionResult: For matchType 'number', ExtractionResult is missing the 'integer' property.");
757
+ throw new Error(
758
+ "validateExtractionResult: For matchType 'number', ExtractionResult is missing the 'integer' property."
759
+ );
808
760
  }
809
761
  if (typeof extractionResult.integer !== "string") {
810
- throw new Error("validateExtractionResult: For matchType 'number', ExtractionResult 'integer' property must be a string.");
762
+ throw new Error(
763
+ "validateExtractionResult: For matchType 'number', ExtractionResult 'integer' property must be a string."
764
+ );
811
765
  }
812
766
  if (!isValidIntegerString(extractionResult.integer)) {
813
- throw new Error("validateExtractionResult: For matchType 'number', ExtractionResult 'integer' property must contain only integers.");
767
+ throw new Error(
768
+ "validateExtractionResult: For matchType 'number', ExtractionResult 'integer' property must contain only integers."
769
+ );
814
770
  }
815
771
  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.");
772
+ throw new Error(
773
+ "validateExtractionResult: For matchType 'number', ExtractionResult 'decimal' property must be a string if present."
774
+ );
817
775
  }
818
776
  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.");
777
+ throw new Error(
778
+ "validateExtractionResult: For matchType 'number', ExtractionResult 'decimal' property must contain only integers."
779
+ );
820
780
  }
821
781
  if (!("negativeInt" in extractionResult)) {
822
- throw new Error("validateExtractionResult: For matchType 'number', ExtractionResult is missing the 'negativeInt' property.");
782
+ throw new Error(
783
+ "validateExtractionResult: For matchType 'number', ExtractionResult is missing the 'negativeInt' property."
784
+ );
823
785
  }
824
786
  if (typeof extractionResult.negativeInt !== "boolean") {
825
- throw new Error("validateExtractionResult: For matchType 'number', ExtractionResult 'negativeInt' property must be a boolean.");
787
+ throw new Error(
788
+ "validateExtractionResult: For matchType 'number', ExtractionResult 'negativeInt' property must be a boolean."
789
+ );
826
790
  }
827
791
  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.");
792
+ throw new Error(
793
+ "validateExtractionResult: For matchType 'number', ExtractionResult 'exponent' property must be a string if present."
794
+ );
829
795
  }
830
796
  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).");
797
+ throw new Error(
798
+ "validateExtractionResult: For matchType 'number', ExtractionResult 'exponent' property must contain only integers or superscript integers (and their respective negative symbol - and \u207B)."
799
+ );
832
800
  }
833
801
  break;
834
802
  case "symbolCurrency":
835
803
  case "codeCurrency":
836
804
  if (!("integer" in extractionResult)) {
837
- throw new Error(`validateExtractionResult: For matchType '${matchType}', ExtractionResult is missing the 'integer' property.`);
805
+ throw new Error(
806
+ `validateExtractionResult: For matchType '${matchType}', ExtractionResult is missing the 'integer' property.`
807
+ );
838
808
  }
839
809
  if (typeof extractionResult.integer !== "string") {
840
- throw new Error(`validateExtractionResult: For matchType '${matchType}', ExtractionResult 'integer' property must be a string.`);
810
+ throw new Error(
811
+ `validateExtractionResult: For matchType '${matchType}', ExtractionResult 'integer' property must be a string.`
812
+ );
841
813
  }
842
814
  if (!isValidIntegerString(extractionResult.integer)) {
843
- throw new Error(`validateExtractionResult: For matchType '${matchType}', ExtractionResult 'integer' property must contain only integers.`);
815
+ throw new Error(
816
+ `validateExtractionResult: For matchType '${matchType}', ExtractionResult 'integer' property must contain only integers.`
817
+ );
844
818
  }
845
819
  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.`);
820
+ throw new Error(
821
+ `validateExtractionResult: For matchType '${matchType}', ExtractionResult 'decimal' property must be a string if present.`
822
+ );
847
823
  }
848
824
  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.`);
825
+ throw new Error(
826
+ `validateExtractionResult: For matchType '${matchType}', ExtractionResult 'decimal' property must contain only integers.`
827
+ );
850
828
  }
851
829
  if (!("negativeInt" in extractionResult)) {
852
- throw new Error(`validateExtractionResult: For matchType '${matchType}', ExtractionResult is missing the 'negativeInt' property.`);
830
+ throw new Error(
831
+ `validateExtractionResult: For matchType '${matchType}', ExtractionResult is missing the 'negativeInt' property.`
832
+ );
853
833
  }
854
834
  if (typeof extractionResult.negativeInt !== "boolean") {
855
- throw new Error(`validateExtractionResult: For matchType '${matchType}', ExtractionResult 'negativeInt' property must be a boolean.`);
835
+ throw new Error(
836
+ `validateExtractionResult: For matchType '${matchType}', ExtractionResult 'negativeInt' property must be a boolean.`
837
+ );
856
838
  }
857
839
  if (!("currency" in extractionResult)) {
858
- throw new Error(`validateExtractionResult: For matchType '${matchType}', ExtractionResult is missing the 'currency' property.`);
840
+ throw new Error(
841
+ `validateExtractionResult: For matchType '${matchType}', ExtractionResult is missing the 'currency' property.`
842
+ );
859
843
  }
860
844
  if (typeof extractionResult.currency !== "string") {
861
- throw new Error(`validateExtractionResult: For matchType '${matchType}', ExtractionResult 'currency' property must be a string.`);
845
+ throw new Error(
846
+ `validateExtractionResult: For matchType '${matchType}', ExtractionResult 'currency' property must be a string.`
847
+ );
862
848
  }
863
849
  break;
864
850
  case "unit":
865
851
  if (!("integer" in extractionResult)) {
866
- throw new Error("validateExtractionResult: For matchType 'unit', ExtractionResult is missing the 'integer' property.");
852
+ throw new Error(
853
+ "validateExtractionResult: For matchType 'unit', ExtractionResult is missing the 'integer' property."
854
+ );
867
855
  }
868
856
  if (typeof extractionResult.integer !== "string") {
869
- throw new Error("validateExtractionResult: For matchType 'unit', ExtractionResult 'integer' property must be a string.");
857
+ throw new Error(
858
+ "validateExtractionResult: For matchType 'unit', ExtractionResult 'integer' property must be a string."
859
+ );
870
860
  }
871
861
  if (!isValidIntegerString(extractionResult.integer)) {
872
- throw new Error("validateExtractionResult: For matchType 'unit', ExtractionResult 'integer' property must contain only integers.");
862
+ throw new Error(
863
+ "validateExtractionResult: For matchType 'unit', ExtractionResult 'integer' property must contain only integers."
864
+ );
873
865
  }
874
866
  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.");
867
+ throw new Error(
868
+ "validateExtractionResult: For matchType 'unit', ExtractionResult 'decimal' property must be a string if present."
869
+ );
876
870
  }
877
871
  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.");
872
+ throw new Error(
873
+ "validateExtractionResult: For matchType 'unit', ExtractionResult 'decimal' property must contain only integers."
874
+ );
879
875
  }
880
876
  if (!("negativeInt" in extractionResult)) {
881
- throw new Error("validateExtractionResult: For matchType 'unit', ExtractionResult is missing the 'negativeInt' property.");
877
+ throw new Error(
878
+ "validateExtractionResult: For matchType 'unit', ExtractionResult is missing the 'negativeInt' property."
879
+ );
882
880
  }
883
881
  if (typeof extractionResult.negativeInt !== "boolean") {
884
- throw new Error("validateExtractionResult: For matchType 'unit', ExtractionResult 'negativeInt' property must be a boolean.");
882
+ throw new Error(
883
+ "validateExtractionResult: For matchType 'unit', ExtractionResult 'negativeInt' property must be a boolean."
884
+ );
885
885
  }
886
886
  if (!("unit" in extractionResult)) {
887
- throw new Error("validateExtractionResult: For matchType 'unit', ExtractionResult is missing the 'unit' property.");
887
+ throw new Error(
888
+ "validateExtractionResult: For matchType 'unit', ExtractionResult is missing the 'unit' property."
889
+ );
888
890
  }
889
891
  if (typeof extractionResult.unit !== "string") {
890
- throw new Error("validateExtractionResult: For matchType 'unit', ExtractionResult 'unit' property must be a string.");
892
+ throw new Error(
893
+ "validateExtractionResult: For matchType 'unit', ExtractionResult 'unit' property must be a string."
894
+ );
891
895
  }
892
896
  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.");
897
+ throw new Error(
898
+ "validateExtractionResult: For matchType 'unit', ExtractionResult 'exponent' property must be a string if present."
899
+ );
894
900
  }
895
901
  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).");
902
+ throw new Error(
903
+ "validateExtractionResult: For matchType 'unit', ExtractionResult 'exponent' property must contain only integers or superscript integers (and their respective negative symbol - and \u207B)."
904
+ );
897
905
  }
898
906
  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.");
907
+ throw new Error(
908
+ "validateExtractionResult: For matchType 'unit', ExtractionResult 'unitExponent' property must be a string if present."
909
+ );
900
910
  }
901
911
  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).");
912
+ throw new Error(
913
+ "validateExtractionResult: For matchType 'unit', ExtractionResult 'unitExponent' property must contain only integers or superscript integers (and their respective negative symbol - and \u207B)."
914
+ );
903
915
  }
904
916
  break;
905
917
  case "unitOnly":
906
918
  if (!("unit" in extractionResult)) {
907
- throw new Error("validateExtractionResult: For matchType 'unitOnly', ExtractionResult is missing the 'unit' property.");
919
+ throw new Error(
920
+ "validateExtractionResult: For matchType 'unitOnly', ExtractionResult is missing the 'unit' property."
921
+ );
908
922
  }
909
923
  if (typeof extractionResult.unit !== "string") {
910
- throw new Error("validateExtractionResult: For matchType 'unitOnly', ExtractionResult 'unit' property must be a string.");
924
+ throw new Error(
925
+ "validateExtractionResult: For matchType 'unitOnly', ExtractionResult 'unit' property must be a string."
926
+ );
911
927
  }
912
928
  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.");
929
+ throw new Error(
930
+ "validateExtractionResult: For matchType 'unitOnly', ExtractionResult 'unitExponent' property must be a string if present."
931
+ );
914
932
  }
915
933
  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).");
934
+ throw new Error(
935
+ "validateExtractionResult: For matchType 'unitOnly', ExtractionResult 'unitExponent' property must contain only integers or superscript integers (and their respective negative symbol - and \u207B)."
936
+ );
917
937
  }
918
938
  break;
919
939
  case "operator":
@@ -921,34 +941,54 @@ function validateExtractionResult(extractionResult) {
921
941
  // No specific properties to validate for operator
922
942
  case "scientific":
923
943
  if (!("integer" in extractionResult)) {
924
- throw new Error("validateExtractionResult: For matchType 'scientific', ExtractionResult is missing the 'integer' property.");
944
+ throw new Error(
945
+ "validateExtractionResult: For matchType 'scientific', ExtractionResult is missing the 'integer' property."
946
+ );
925
947
  }
926
948
  if (typeof extractionResult.integer !== "string") {
927
- throw new Error("validateExtractionResult: For matchType 'scientific', ExtractionResult 'integer' property must be a string.");
949
+ throw new Error(
950
+ "validateExtractionResult: For matchType 'scientific', ExtractionResult 'integer' property must be a string."
951
+ );
928
952
  }
929
953
  if (!isValidIntegerString(extractionResult.integer)) {
930
- throw new Error("validateExtractionResult: For matchType 'scientific', ExtractionResult 'integer' property must contain only integers.");
954
+ throw new Error(
955
+ "validateExtractionResult: For matchType 'scientific', ExtractionResult 'integer' property must contain only integers."
956
+ );
931
957
  }
932
958
  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.");
959
+ throw new Error(
960
+ "validateExtractionResult: For matchType 'scientific', ExtractionResult 'decimal' property must be a string if present."
961
+ );
934
962
  }
935
963
  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.");
964
+ throw new Error(
965
+ "validateExtractionResult: For matchType 'scientific', ExtractionResult 'decimal' property must contain only integers."
966
+ );
937
967
  }
938
968
  if (!("negativeInt" in extractionResult)) {
939
- throw new Error("validateExtractionResult: For matchType 'scientific', ExtractionResult is missing the 'negativeInt' property.");
969
+ throw new Error(
970
+ "validateExtractionResult: For matchType 'scientific', ExtractionResult is missing the 'negativeInt' property."
971
+ );
940
972
  }
941
973
  if (typeof extractionResult.negativeInt !== "boolean") {
942
- throw new Error("validateExtractionResult: For matchType 'scientific', ExtractionResult 'negativeInt' property must be a boolean.");
974
+ throw new Error(
975
+ "validateExtractionResult: For matchType 'scientific', ExtractionResult 'negativeInt' property must be a boolean."
976
+ );
943
977
  }
944
978
  if (!("exponent" in extractionResult)) {
945
- throw new Error("validateExtractionResult: For matchType 'scientific', ExtractionResult is missing the 'exponent' property.");
979
+ throw new Error(
980
+ "validateExtractionResult: For matchType 'scientific', ExtractionResult is missing the 'exponent' property."
981
+ );
946
982
  }
947
983
  if (extractionResult.exponent !== void 0 && typeof extractionResult.exponent !== "string") {
948
- throw new Error("validateExtractionResult: For matchType 'scientific', ExtractionResult 'exponent' property must be a string.");
984
+ throw new Error(
985
+ "validateExtractionResult: For matchType 'scientific', ExtractionResult 'exponent' property must be a string."
986
+ );
949
987
  }
950
988
  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).");
989
+ throw new Error(
990
+ "validateExtractionResult: For matchType 'scientific', ExtractionResult 'exponent' property must contain only integers or superscript integers (and their respective negative symbol - and \u207B)."
991
+ );
952
992
  }
953
993
  break;
954
994
  default:
@@ -972,12 +1012,6 @@ var extractQuantities = {
972
1012
  allMatches: extractAllMatches
973
1013
  };
974
1014
  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
1015
  /**
982
1016
  * Translates an ExtractionResult object (number || currency || unit || operator || scientific expression) into its spoken word equivalent.
983
1017
  *
@@ -1008,8 +1042,6 @@ var convertQuantities = {
1008
1042
  case "scientific":
1009
1043
  result = convertScientificExpressionToSpokenWord(extractionResult);
1010
1044
  break;
1011
- default:
1012
- break;
1013
1045
  }
1014
1046
  return result;
1015
1047
  },
@@ -1049,10 +1081,9 @@ var convertQuantities = {
1049
1081
  return output.replace(/\s+/g, " ").trim();
1050
1082
  }
1051
1083
  };
1052
- // Annotate the CommonJS export names for ESM import in node:
1053
- 0 && (module.exports = {
1054
- convertQuantities,
1055
- extractQuantities,
1056
- validateExtractionResult
1057
- });
1084
+
1085
+ exports.convertQuantities = convertQuantities;
1086
+ exports.extractQuantities = extractQuantities;
1087
+ exports.validateExtractionResult = validateExtractionResult;
1088
+ //# sourceMappingURL=index.cjs.map
1058
1089
  //# sourceMappingURL=index.cjs.map