numeric-quantity 1.0.2 → 1.0.3

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 CHANGED
@@ -1,6 +1,6 @@
1
- /**
2
- * Converts a string to a number. The string can include mixed numbers
3
- * or vulgar fractions.
4
- */
5
- declare function numericQuantity(qty: string): number;
6
- export default numericQuantity;
1
+ /**
2
+ * Converts a string to a number. The string can include mixed numbers
3
+ * or vulgar fractions.
4
+ */
5
+ declare function numericQuantity(qty: string): number;
6
+ export default numericQuantity;
@@ -0,0 +1,2 @@
1
+ "use strict";var m=(e=>(e["\xBC"]="1/4",e["\xBD"]="1/2",e["\xBE"]="3/4",e["\u2150"]="1/7",e["\u2151"]="1/9",e["\u2152"]="1/10",e["\u2153"]="1/3",e["\u2154"]="2/3",e["\u2155"]="1/5",e["\u2156"]="2/5",e["\u2157"]="3/5",e["\u2158"]="4/5",e["\u2159"]="1/6",e["\u215A"]="5/6",e["\u215B"]="1/8",e["\u215C"]="3/8",e["\u215D"]="5/8",e["\u215E"]="7/8",e))(m||{});function R(e){let t=NaN;const o=/(¼|½|¾|⅐|⅑|⅒|⅓|⅔|⅕|⅖|⅗|⅘|⅙|⅚|⅛|⅜|⅝|⅞)/,f=`${e}`.replace(o,(u,n)=>` ${m[n]}`).replace(/⁄/g,"/").trim(),d=/^(-)?\s*(\d*)(\.\d+|(\s+\d*\s*)?\s*\/\s*\d+)?$/.exec(f);if(!d)return NaN;const[,p,r,s]=d;if(!r&&!s)return NaN;if(!r&&s&&s.search(/^\./)!==-1?t=0:t=parseInt(r),isNaN(t))return NaN;if(!s)return t*(p==="-"?-1:1);if(s.search(/^\./)!==-1){const u=parseFloat(s);t+=Math.round(u*1e3)/1e3}else if(s.search(/^\s*\//)!==-1){const u=parseInt(r),n=parseInt(s.replace("/",""));t=Math.round(u*1e3/n)/1e3}else{const u=s.split("/"),[n,b]=u.map(h=>parseInt(h));t+=Math.round(n*1e3/b)/1e3}return t*(p==="-"?-1:1)}module.exports=R;
2
+ //# sourceMappingURL=numeric-quantity.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"numeric-quantity.esm.js","sources":["../src/index.ts"],"sourcesContent":["enum VulgarFraction {\n '¼' = '1/4',\n '½' = '1/2',\n '¾' = '3/4',\n '⅐' = '1/7',\n '⅑' = '1/9',\n '⅒' = '1/10',\n '⅓' = '1/3',\n '⅔' = '2/3',\n '⅕' = '1/5',\n '⅖' = '2/5',\n '⅗' = '3/5',\n '⅘' = '4/5',\n '⅙' = '1/6',\n '⅚' = '5/6',\n '⅛' = '1/8',\n '⅜' = '3/8',\n '⅝' = '5/8',\n '⅞' = '7/8',\n}\n\n/**\n * Converts a string to a number. The string can include mixed numbers\n * or vulgar fractions.\n */\nfunction numericQuantity(qty: string) {\n const badResult = NaN;\n let finalResult = badResult;\n\n // Resolve any unicode vulgar fractions\n const vulgarFractionsRegex = /(¼|½|¾|⅐|⅑|⅒|⅓|⅔|⅕|⅖|⅗|⅘|⅙|⅚|⅛|⅜|⅝|⅞)/;\n\n const sQty = `${qty}`\n .replace(\n vulgarFractionsRegex,\n (_m, vf: keyof typeof VulgarFraction) => ` ${VulgarFraction[vf]}`\n )\n .replace(/⁄/g, '/')\n .trim();\n\n /**\n * Regex captures\n *\n * +=====+====================+========================+\n * | # | Description | Example |\n * +=====+====================+========================+\n * | 0 | entire string | \"2 2/3\" from \"2 2/3\" |\n * +-----+--------------------+------------------------+\n * | 1 | the dash | \"-\" from \"-2 2/3\" |\n * +-----+--------------------+------------------------+\n * | 2 | the whole number | \"2\" from \"2 2/3\" |\n * | | - OR - | |\n * | | the numerator | \"2\" from \"2/3\" |\n * +-----+--------------------+------------------------+\n * | 3 | entire fraction | \"2/3\" from \"2 2/3\" |\n * | | - OR - | |\n * | | decimal portion | \".66\" from \"2.66\" |\n * | | - OR - | |\n * | | denominator | \"/3\" from \"2/3\" |\n * +=====+====================+========================+\n *\n * re.exec(\"1\") // [ \"1\", \"1\", null, null ]\n * re.exec(\"1.23\") // [ \"1.23\", \"1\", \".23\", null ]\n * re.exec(\"1 2/3\") // [ \"1 2/3\", \"1\", \" 2/3\", \" 2\" ]\n * re.exec(\"2/3\") // [ \"2/3\", \"2\", \"/3\", null ]\n * re.exec(\"2 / 3\") // [ \"2 / 3\", \"2\", \"/ 3\", null ]\n */\n const re = /^(-)?\\s*(\\d*)(\\.\\d+|(\\s+\\d*\\s*)?\\s*\\/\\s*\\d+)?$/;\n\n const ar = re.exec(sQty);\n\n // If the regex fails, give up\n if (!ar) {\n return badResult;\n }\n\n // Store the capture groups so we don't have to access the array\n // elements over and over\n const [, dash, numberGroup1, numberGroup2] = ar;\n\n // The regex can pass and still capture nothing in the relevant groups,\n // which means it failed for our purposes\n if (!numberGroup1 && !numberGroup2) {\n return badResult;\n }\n\n // Numerify capture group 1\n if (!numberGroup1 && numberGroup2 && numberGroup2.search(/^\\./) !== -1) {\n finalResult = 0;\n } else {\n finalResult = parseInt(numberGroup1);\n }\n\n if (isNaN(finalResult)) {\n return badResult;\n }\n\n // If capture group 2 is null, then we're dealing with an integer\n // and there is nothing left to process\n if (!numberGroup2) {\n return finalResult * (dash === '-' ? -1 : 1);\n }\n\n if (numberGroup2.search(/^\\./) !== -1) {\n // If first char is \".\" it's a decimal so just trim to 3 decimal places\n const numerator = parseFloat(numberGroup2);\n finalResult += Math.round(numerator * 1000) / 1000;\n } else if (numberGroup2.search(/^\\s*\\//) !== -1) {\n // If the first non-space char is \"/\" it's a pure fraction (e.g. \"1/2\")\n const numerator = parseInt(numberGroup1);\n const denominator = parseInt(numberGroup2.replace('/', ''));\n finalResult = Math.round((numerator * 1000) / denominator) / 1000;\n } else {\n // Otherwise it's a mixed fraction (e.g. \"1 2/3\")\n const fractionArray = numberGroup2.split('/');\n const [numerator, denominator] = fractionArray.map(v => parseInt(v));\n finalResult += Math.round((numerator * 1000) / denominator) / 1000;\n }\n\n return finalResult * (dash === '-' ? -1 : 1);\n}\n\nexport default numericQuantity;\n"],"names":["VulgarFraction","numericQuantity","qty","badResult","NaN","finalResult","vulgarFractionsRegex","sQty","replace","_m","vf","trim","re","ar","exec","dash","numberGroup1","numberGroup2","search","parseInt","isNaN","numerator","parseFloat","Math","round","denominator","fractionArray","split","map","v"],"mappings":"AAAA,IAAKA,cAAL;;AAAA,WAAKA;AACHA,EAAAA,sBAAA,QAAA;AACAA,EAAAA,sBAAA,QAAA;AACAA,EAAAA,sBAAA,QAAA;AACAA,EAAAA,wBAAA,QAAA;AACAA,EAAAA,wBAAA,QAAA;AACAA,EAAAA,wBAAA,SAAA;AACAA,EAAAA,wBAAA,QAAA;AACAA,EAAAA,wBAAA,QAAA;AACAA,EAAAA,wBAAA,QAAA;AACAA,EAAAA,wBAAA,QAAA;AACAA,EAAAA,wBAAA,QAAA;AACAA,EAAAA,wBAAA,QAAA;AACAA,EAAAA,wBAAA,QAAA;AACAA,EAAAA,wBAAA,QAAA;AACAA,EAAAA,wBAAA,QAAA;AACAA,EAAAA,wBAAA,QAAA;AACAA,EAAAA,wBAAA,QAAA;AACAA,EAAAA,wBAAA,QAAA;AACD,CAnBD,EAAKA,cAAc,KAAdA,cAAc,KAAA,CAAnB;AAqBA;;;;;;AAIA,SAASC,eAAT,CAAyBC,GAAzB;AACE,MAAMC,SAAS,GAAGC,GAAlB;AACA,MAAIC,WAAW,GAAGF,SAAlB;;AAGA,MAAMG,oBAAoB,GAAG,uCAA7B;AAEA,MAAMC,IAAI,GAAG,MAAGL,GAAH,EACVM,OADU,CAETF,oBAFS,EAGT,UAACG,EAAD,EAAKC,EAAL;AAAA,iBAA6CV,cAAc,CAACU,EAAD,CAA3D;AAAA,GAHS,EAKVF,OALU,CAKF,IALE,EAKI,GALJ,EAMVG,IANU,EAAb;AAQA;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,MAAMC,EAAE,GAAG,gDAAX;AAEA,MAAMC,EAAE,GAAGD,EAAE,CAACE,IAAH,CAAQP,IAAR,CAAX;;AAG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GAAnB,CAAtB;;AAFK,6BAG4BD,aAAa,CAACE,GAAd,CAAkB,UAAAC,CAAC;AAAA,aAAIV,QAAQ,CAACU,CAAD,CAAZ;AAAA,KAAnB,CAH5B;AAAA,QAGER,WAHF;AAAA,QAGaI,YAHb;;AAILpB,IAAAA,WAAW,IAAIkB,IAAI,CAACC,KAAL,CAAYH,WAAS,GAAG,IAAb,GAAqBI,YAAhC,IAA+C,IAA9D;AACD;;AAED,SAAOpB,WAAW,IAAIU,IAAI,KAAK,GAAT,GAAe,CAAC,CAAhB,GAAoB,CAAxB,CAAlB;AACD;;;;"}
1
+ {"version":3,"file":"numeric-quantity.cjs.js","sources":["../src/index.ts"],"sourcesContent":["enum VulgarFraction {\n '¼' = '1/4',\n '½' = '1/2',\n '¾' = '3/4',\n '⅐' = '1/7',\n '⅑' = '1/9',\n '⅒' = '1/10',\n '⅓' = '1/3',\n '⅔' = '2/3',\n '⅕' = '1/5',\n '⅖' = '2/5',\n '⅗' = '3/5',\n '⅘' = '4/5',\n '⅙' = '1/6',\n '⅚' = '5/6',\n '⅛' = '1/8',\n '⅜' = '3/8',\n '⅝' = '5/8',\n '⅞' = '7/8',\n}\n\n/**\n * Converts a string to a number. The string can include mixed numbers\n * or vulgar fractions.\n */\nfunction numericQuantity(qty: string) {\n const badResult = NaN;\n let finalResult = badResult;\n\n // Resolve any unicode vulgar fractions\n const vulgarFractionsRegex = /(¼|½|¾|⅐|⅑|⅒|⅓|⅔|⅕|⅖|⅗|⅘|⅙|⅚|⅛|⅜|⅝|⅞)/;\n\n const sQty = `${qty}`\n .replace(\n vulgarFractionsRegex,\n (_m, vf: keyof typeof VulgarFraction) => ` ${VulgarFraction[vf]}`\n )\n .replace(/⁄/g, '/')\n .trim();\n\n /**\n * Regex captures\n *\n * +=====+====================+========================+\n * | # | Description | Example |\n * +=====+====================+========================+\n * | 0 | entire string | \"2 2/3\" from \"2 2/3\" |\n * +-----+--------------------+------------------------+\n * | 1 | the dash | \"-\" from \"-2 2/3\" |\n * +-----+--------------------+------------------------+\n * | 2 | the whole number | \"2\" from \"2 2/3\" |\n * | | - OR - | |\n * | | the numerator | \"2\" from \"2/3\" |\n * +-----+--------------------+------------------------+\n * | 3 | entire fraction | \"2/3\" from \"2 2/3\" |\n * | | - OR - | |\n * | | decimal portion | \".66\" from \"2.66\" |\n * | | - OR - | |\n * | | denominator | \"/3\" from \"2/3\" |\n * +=====+====================+========================+\n *\n * re.exec(\"1\") // [ \"1\", \"1\", null, null ]\n * re.exec(\"1.23\") // [ \"1.23\", \"1\", \".23\", null ]\n * re.exec(\"1 2/3\") // [ \"1 2/3\", \"1\", \" 2/3\", \" 2\" ]\n * re.exec(\"2/3\") // [ \"2/3\", \"2\", \"/3\", null ]\n * re.exec(\"2 / 3\") // [ \"2 / 3\", \"2\", \"/ 3\", null ]\n */\n const re = /^(-)?\\s*(\\d*)(\\.\\d+|(\\s+\\d*\\s*)?\\s*\\/\\s*\\d+)?$/;\n\n const ar = re.exec(sQty);\n\n // If the regex fails, give up\n if (!ar) {\n return badResult;\n }\n\n // Store the capture groups so we don't have to access the array\n // elements over and over\n const [, dash, numberGroup1, numberGroup2] = ar;\n\n // The regex can pass and still capture nothing in the relevant groups,\n // which means it failed for our purposes\n if (!numberGroup1 && !numberGroup2) {\n return badResult;\n }\n\n // Numerify capture group 1\n if (!numberGroup1 && numberGroup2 && numberGroup2.search(/^\\./) !== -1) {\n finalResult = 0;\n } else {\n finalResult = parseInt(numberGroup1);\n }\n\n if (isNaN(finalResult)) {\n return badResult;\n }\n\n // If capture group 2 is null, then we're dealing with an integer\n // and there is nothing left to process\n if (!numberGroup2) {\n return finalResult * (dash === '-' ? -1 : 1);\n }\n\n if (numberGroup2.search(/^\\./) !== -1) {\n // If first char is \".\" it's a decimal so just trim to 3 decimal places\n const numerator = parseFloat(numberGroup2);\n finalResult += Math.round(numerator * 1000) / 1000;\n } else if (numberGroup2.search(/^\\s*\\//) !== -1) {\n // If the first non-space char is \"/\" it's a pure fraction (e.g. \"1/2\")\n const numerator = parseInt(numberGroup1);\n const denominator = parseInt(numberGroup2.replace('/', ''));\n finalResult = Math.round((numerator * 1000) / denominator) / 1000;\n } else {\n // Otherwise it's a mixed fraction (e.g. \"1 2/3\")\n const fractionArray = numberGroup2.split('/');\n const [numerator, denominator] = fractionArray.map(v => parseInt(v));\n finalResult += Math.round((numerator * 1000) / denominator) / 1000;\n }\n\n return finalResult * (dash === '-' ? -1 : 1);\n}\n\nexport default numericQuantity;\n"],"names":[],"mappings":"aAAA,GAAK,IAAA,GACG,GAAA,QAAA,MACA,EAAA,QAAA,MACA,EAAA,QAAA,MACA,EAAA,UAAA,MACA,EAAA,UAAA,MACA,EAAA,UAAA,OACA,EAAA,UAAA,MACA,EAAA,UAAA,MACA,EAAA,UAAA,MACA,EAAA,UAAA,MACA,EAAA,UAAA,MACA,EAAA,UAAA,MACA,EAAA,UAAA,MACA,EAAA,UAAA,MACA,EAAA,UAAA,MACA,EAAA,UAAA,MACA,EAAA,UAAA,MACA,EAAA,UAAA,MAlBH,IAAA,GAAA,CAAA,CAAA,EAyBL,WAAyB,EAAa,CAEpC,GAAI,GAAc,IAGlB,KAAM,GAAuB,wCAEvB,EAAO,GAAG,IACb,QACC,EACA,CAAC,EAAI,IAAoC,IAAI,EAAe,IAC9D,EACC,QAAQ,KAAM,GAAG,EACjB,OA+BG,EAAK,AAFA,iDAEG,KAAK,CAAI,EAGvB,GAAI,CAAC,EACI,MAAA,KAKT,KAAM,CAAG,CAAA,EAAM,EAAc,GAAgB,EAIzC,GAAA,CAAC,GAAgB,CAAC,EACb,MAAA,KAUL,GANJ,AAAI,CAAC,GAAgB,GAAgB,EAAa,OAAO,KAAK,IAAM,GACpD,EAAA,EAEd,EAAc,SAAS,CAAY,EAGjC,MAAM,CAAW,EACZ,MAAA,KAKT,GAAI,CAAC,EACI,MAAA,GAAwB,KAAA,IAAM,GAAK,GAG5C,GAAI,EAAa,OAAO,KAAK,IAAM,GAAI,CAE/B,KAAA,GAAY,WAAW,CAAY,EACzC,GAAe,KAAK,MAAM,EAAY,GAAI,EAAI,GACrC,SAAA,EAAa,OAAO,QAAQ,IAAM,GAAI,CAEzC,KAAA,GAAY,SAAS,CAAY,EACjC,EAAc,SAAS,EAAa,QAAQ,IAAK,EAAE,CAAC,EAC1D,EAAc,KAAK,MAAO,EAAY,IAAQ,CAAW,EAAI,GAAA,KACxD,CAEC,KAAA,GAAgB,EAAa,MAAM,GAAG,EACtC,CAAC,EAAW,GAAe,EAAc,IAAI,AAAK,GAAA,SAAS,CAAC,CAAC,EACnE,GAAe,KAAK,MAAO,EAAY,IAAQ,CAAW,EAAI,GAChE,CAEO,MAAA,GAAwB,KAAA,IAAM,GAAK,EAC5C"}
@@ -0,0 +1,62 @@
1
+ var VulgarFraction = /* @__PURE__ */ ((VulgarFraction2) => {
2
+ VulgarFraction2["\xBC"] = "1/4";
3
+ VulgarFraction2["\xBD"] = "1/2";
4
+ VulgarFraction2["\xBE"] = "3/4";
5
+ VulgarFraction2["\u2150"] = "1/7";
6
+ VulgarFraction2["\u2151"] = "1/9";
7
+ VulgarFraction2["\u2152"] = "1/10";
8
+ VulgarFraction2["\u2153"] = "1/3";
9
+ VulgarFraction2["\u2154"] = "2/3";
10
+ VulgarFraction2["\u2155"] = "1/5";
11
+ VulgarFraction2["\u2156"] = "2/5";
12
+ VulgarFraction2["\u2157"] = "3/5";
13
+ VulgarFraction2["\u2158"] = "4/5";
14
+ VulgarFraction2["\u2159"] = "1/6";
15
+ VulgarFraction2["\u215A"] = "5/6";
16
+ VulgarFraction2["\u215B"] = "1/8";
17
+ VulgarFraction2["\u215C"] = "3/8";
18
+ VulgarFraction2["\u215D"] = "5/8";
19
+ VulgarFraction2["\u215E"] = "7/8";
20
+ return VulgarFraction2;
21
+ })(VulgarFraction || {});
22
+ function numericQuantity(qty) {
23
+ const badResult = NaN;
24
+ let finalResult = badResult;
25
+ const vulgarFractionsRegex = /(¼|½|¾|⅐|⅑|⅒|⅓|⅔|⅕|⅖|⅗|⅘|⅙|⅚|⅛|⅜|⅝|⅞)/;
26
+ const sQty = `${qty}`.replace(vulgarFractionsRegex, (_m, vf) => ` ${VulgarFraction[vf]}`).replace(/⁄/g, "/").trim();
27
+ const re = /^(-)?\s*(\d*)(\.\d+|(\s+\d*\s*)?\s*\/\s*\d+)?$/;
28
+ const ar = re.exec(sQty);
29
+ if (!ar) {
30
+ return badResult;
31
+ }
32
+ const [, dash, numberGroup1, numberGroup2] = ar;
33
+ if (!numberGroup1 && !numberGroup2) {
34
+ return badResult;
35
+ }
36
+ if (!numberGroup1 && numberGroup2 && numberGroup2.search(/^\./) !== -1) {
37
+ finalResult = 0;
38
+ } else {
39
+ finalResult = parseInt(numberGroup1);
40
+ }
41
+ if (isNaN(finalResult)) {
42
+ return badResult;
43
+ }
44
+ if (!numberGroup2) {
45
+ return finalResult * (dash === "-" ? -1 : 1);
46
+ }
47
+ if (numberGroup2.search(/^\./) !== -1) {
48
+ const numerator = parseFloat(numberGroup2);
49
+ finalResult += Math.round(numerator * 1e3) / 1e3;
50
+ } else if (numberGroup2.search(/^\s*\//) !== -1) {
51
+ const numerator = parseInt(numberGroup1);
52
+ const denominator = parseInt(numberGroup2.replace("/", ""));
53
+ finalResult = Math.round(numerator * 1e3 / denominator) / 1e3;
54
+ } else {
55
+ const fractionArray = numberGroup2.split("/");
56
+ const [numerator, denominator] = fractionArray.map((v) => parseInt(v));
57
+ finalResult += Math.round(numerator * 1e3 / denominator) / 1e3;
58
+ }
59
+ return finalResult * (dash === "-" ? -1 : 1);
60
+ }
61
+ export { numericQuantity as default };
62
+ //# sourceMappingURL=numeric-quantity.es.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"numeric-quantity.es.js","sources":["../src/index.ts"],"sourcesContent":["enum VulgarFraction {\n '¼' = '1/4',\n '½' = '1/2',\n '¾' = '3/4',\n '⅐' = '1/7',\n '⅑' = '1/9',\n '⅒' = '1/10',\n '⅓' = '1/3',\n '⅔' = '2/3',\n '⅕' = '1/5',\n '⅖' = '2/5',\n '⅗' = '3/5',\n '⅘' = '4/5',\n '⅙' = '1/6',\n '⅚' = '5/6',\n '⅛' = '1/8',\n '⅜' = '3/8',\n '⅝' = '5/8',\n '⅞' = '7/8',\n}\n\n/**\n * Converts a string to a number. The string can include mixed numbers\n * or vulgar fractions.\n */\nfunction numericQuantity(qty: string) {\n const badResult = NaN;\n let finalResult = badResult;\n\n // Resolve any unicode vulgar fractions\n const vulgarFractionsRegex = /(¼|½|¾|⅐|⅑|⅒|⅓|⅔|⅕|⅖|⅗|⅘|⅙|⅚|⅛|⅜|⅝|⅞)/;\n\n const sQty = `${qty}`\n .replace(\n vulgarFractionsRegex,\n (_m, vf: keyof typeof VulgarFraction) => ` ${VulgarFraction[vf]}`\n )\n .replace(/⁄/g, '/')\n .trim();\n\n /**\n * Regex captures\n *\n * +=====+====================+========================+\n * | # | Description | Example |\n * +=====+====================+========================+\n * | 0 | entire string | \"2 2/3\" from \"2 2/3\" |\n * +-----+--------------------+------------------------+\n * | 1 | the dash | \"-\" from \"-2 2/3\" |\n * +-----+--------------------+------------------------+\n * | 2 | the whole number | \"2\" from \"2 2/3\" |\n * | | - OR - | |\n * | | the numerator | \"2\" from \"2/3\" |\n * +-----+--------------------+------------------------+\n * | 3 | entire fraction | \"2/3\" from \"2 2/3\" |\n * | | - OR - | |\n * | | decimal portion | \".66\" from \"2.66\" |\n * | | - OR - | |\n * | | denominator | \"/3\" from \"2/3\" |\n * +=====+====================+========================+\n *\n * re.exec(\"1\") // [ \"1\", \"1\", null, null ]\n * re.exec(\"1.23\") // [ \"1.23\", \"1\", \".23\", null ]\n * re.exec(\"1 2/3\") // [ \"1 2/3\", \"1\", \" 2/3\", \" 2\" ]\n * re.exec(\"2/3\") // [ \"2/3\", \"2\", \"/3\", null ]\n * re.exec(\"2 / 3\") // [ \"2 / 3\", \"2\", \"/ 3\", null ]\n */\n const re = /^(-)?\\s*(\\d*)(\\.\\d+|(\\s+\\d*\\s*)?\\s*\\/\\s*\\d+)?$/;\n\n const ar = re.exec(sQty);\n\n // If the regex fails, give up\n if (!ar) {\n return badResult;\n }\n\n // Store the capture groups so we don't have to access the array\n // elements over and over\n const [, dash, numberGroup1, numberGroup2] = ar;\n\n // The regex can pass and still capture nothing in the relevant groups,\n // which means it failed for our purposes\n if (!numberGroup1 && !numberGroup2) {\n return badResult;\n }\n\n // Numerify capture group 1\n if (!numberGroup1 && numberGroup2 && numberGroup2.search(/^\\./) !== -1) {\n finalResult = 0;\n } else {\n finalResult = parseInt(numberGroup1);\n }\n\n if (isNaN(finalResult)) {\n return badResult;\n }\n\n // If capture group 2 is null, then we're dealing with an integer\n // and there is nothing left to process\n if (!numberGroup2) {\n return finalResult * (dash === '-' ? -1 : 1);\n }\n\n if (numberGroup2.search(/^\\./) !== -1) {\n // If first char is \".\" it's a decimal so just trim to 3 decimal places\n const numerator = parseFloat(numberGroup2);\n finalResult += Math.round(numerator * 1000) / 1000;\n } else if (numberGroup2.search(/^\\s*\\//) !== -1) {\n // If the first non-space char is \"/\" it's a pure fraction (e.g. \"1/2\")\n const numerator = parseInt(numberGroup1);\n const denominator = parseInt(numberGroup2.replace('/', ''));\n finalResult = Math.round((numerator * 1000) / denominator) / 1000;\n } else {\n // Otherwise it's a mixed fraction (e.g. \"1 2/3\")\n const fractionArray = numberGroup2.split('/');\n const [numerator, denominator] = fractionArray.map(v => parseInt(v));\n finalResult += Math.round((numerator * 1000) / denominator) / 1000;\n }\n\n return finalResult * (dash === '-' ? -1 : 1);\n}\n\nexport default numericQuantity;\n"],"names":[],"mappings":"AAAA,IAAK,mCAAA,oBAAL;AACQ,kBAAA,UAAA;AACA,kBAAA,UAAA;AACA,kBAAA,UAAA;AACA,kBAAA,YAAA;AACA,kBAAA,YAAA;AACA,kBAAA,YAAA;AACA,kBAAA,YAAA;AACA,kBAAA,YAAA;AACA,kBAAA,YAAA;AACA,kBAAA,YAAA;AACA,kBAAA,YAAA;AACA,kBAAA,YAAA;AACA,kBAAA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ACnE,mBAAe,KAAK,MAAO,YAAY,MAAQ,WAAW,IAAI;AAAA,EAChE;AAEO,SAAA,cAAwB,UAAA,MAAM,KAAK;AAC5C;;"}
@@ -0,0 +1,2 @@
1
+ (function(n,d){typeof exports=="object"&&typeof module!="undefined"?module.exports=d():typeof define=="function"&&define.amd?define(d):(n=typeof globalThis!="undefined"?globalThis:n||self,n.numericQuantity=d())})(this,function(){"use strict";var n=(e=>(e["\xBC"]="1/4",e["\xBD"]="1/2",e["\xBE"]="3/4",e["\u2150"]="1/7",e["\u2151"]="1/9",e["\u2152"]="1/10",e["\u2153"]="1/3",e["\u2154"]="2/3",e["\u2155"]="1/5",e["\u2156"]="2/5",e["\u2157"]="3/5",e["\u2158"]="4/5",e["\u2159"]="1/6",e["\u215A"]="5/6",e["\u215B"]="1/8",e["\u215C"]="3/8",e["\u215D"]="5/8",e["\u215E"]="7/8",e))(n||{});function d(e){let t=NaN;const i=/(¼|½|¾|⅐|⅑|⅒|⅓|⅔|⅕|⅖|⅗|⅘|⅙|⅚|⅛|⅜|⅝|⅞)/,m=`${e}`.replace(i,(u,f)=>` ${n[f]}`).replace(/⁄/g,"/").trim(),r=/^(-)?\s*(\d*)(\.\d+|(\s+\d*\s*)?\s*\/\s*\d+)?$/.exec(m);if(!r)return NaN;const[,p,o,s]=r;if(!o&&!s)return NaN;if(!o&&s&&s.search(/^\./)!==-1?t=0:t=parseInt(o),isNaN(t))return NaN;if(!s)return t*(p==="-"?-1:1);if(s.search(/^\./)!==-1){const u=parseFloat(s);t+=Math.round(u*1e3)/1e3}else if(s.search(/^\s*\//)!==-1){const u=parseInt(o),f=parseInt(s.replace("/",""));t=Math.round(u*1e3/f)/1e3}else{const u=s.split("/"),[f,h]=u.map(c=>parseInt(c));t+=Math.round(f*1e3/h)/1e3}return t*(p==="-"?-1:1)}return d});
2
+ //# sourceMappingURL=numeric-quantity.umd.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"numeric-quantity.umd.js","sources":["../src/index.ts"],"sourcesContent":["enum VulgarFraction {\n '¼' = '1/4',\n '½' = '1/2',\n '¾' = '3/4',\n '⅐' = '1/7',\n '⅑' = '1/9',\n '⅒' = '1/10',\n '⅓' = '1/3',\n '⅔' = '2/3',\n '⅕' = '1/5',\n '⅖' = '2/5',\n '⅗' = '3/5',\n '⅘' = '4/5',\n '⅙' = '1/6',\n '⅚' = '5/6',\n '⅛' = '1/8',\n '⅜' = '3/8',\n '⅝' = '5/8',\n '⅞' = '7/8',\n}\n\n/**\n * Converts a string to a number. The string can include mixed numbers\n * or vulgar fractions.\n */\nfunction numericQuantity(qty: string) {\n const badResult = NaN;\n let finalResult = badResult;\n\n // Resolve any unicode vulgar fractions\n const vulgarFractionsRegex = /(¼|½|¾|⅐|⅑|⅒|⅓|⅔|⅕|⅖|⅗|⅘|⅙|⅚|⅛|⅜|⅝|⅞)/;\n\n const sQty = `${qty}`\n .replace(\n vulgarFractionsRegex,\n (_m, vf: keyof typeof VulgarFraction) => ` ${VulgarFraction[vf]}`\n )\n .replace(/⁄/g, '/')\n .trim();\n\n /**\n * Regex captures\n *\n * +=====+====================+========================+\n * | # | Description | Example |\n * +=====+====================+========================+\n * | 0 | entire string | \"2 2/3\" from \"2 2/3\" |\n * +-----+--------------------+------------------------+\n * | 1 | the dash | \"-\" from \"-2 2/3\" |\n * +-----+--------------------+------------------------+\n * | 2 | the whole number | \"2\" from \"2 2/3\" |\n * | | - OR - | |\n * | | the numerator | \"2\" from \"2/3\" |\n * +-----+--------------------+------------------------+\n * | 3 | entire fraction | \"2/3\" from \"2 2/3\" |\n * | | - OR - | |\n * | | decimal portion | \".66\" from \"2.66\" |\n * | | - OR - | |\n * | | denominator | \"/3\" from \"2/3\" |\n * +=====+====================+========================+\n *\n * re.exec(\"1\") // [ \"1\", \"1\", null, null ]\n * re.exec(\"1.23\") // [ \"1.23\", \"1\", \".23\", null ]\n * re.exec(\"1 2/3\") // [ \"1 2/3\", \"1\", \" 2/3\", \" 2\" ]\n * re.exec(\"2/3\") // [ \"2/3\", \"2\", \"/3\", null ]\n * re.exec(\"2 / 3\") // [ \"2 / 3\", \"2\", \"/ 3\", null ]\n */\n const re = /^(-)?\\s*(\\d*)(\\.\\d+|(\\s+\\d*\\s*)?\\s*\\/\\s*\\d+)?$/;\n\n const ar = re.exec(sQty);\n\n // If the regex fails, give up\n if (!ar) {\n return badResult;\n }\n\n // Store the capture groups so we don't have to access the array\n // elements over and over\n const [, dash, numberGroup1, numberGroup2] = ar;\n\n // The regex can pass and still capture nothing in the relevant groups,\n // which means it failed for our purposes\n if (!numberGroup1 && !numberGroup2) {\n return badResult;\n }\n\n // Numerify capture group 1\n if (!numberGroup1 && numberGroup2 && numberGroup2.search(/^\\./) !== -1) {\n finalResult = 0;\n } else {\n finalResult = parseInt(numberGroup1);\n }\n\n if (isNaN(finalResult)) {\n return badResult;\n }\n\n // If capture group 2 is null, then we're dealing with an integer\n // and there is nothing left to process\n if (!numberGroup2) {\n return finalResult * (dash === '-' ? -1 : 1);\n }\n\n if (numberGroup2.search(/^\\./) !== -1) {\n // If first char is \".\" it's a decimal so just trim to 3 decimal places\n const numerator = parseFloat(numberGroup2);\n finalResult += Math.round(numerator * 1000) / 1000;\n } else if (numberGroup2.search(/^\\s*\\//) !== -1) {\n // If the first non-space char is \"/\" it's a pure fraction (e.g. \"1/2\")\n const numerator = parseInt(numberGroup1);\n const denominator = parseInt(numberGroup2.replace('/', ''));\n finalResult = Math.round((numerator * 1000) / denominator) / 1000;\n } else {\n // Otherwise it's a mixed fraction (e.g. \"1 2/3\")\n const fractionArray = numberGroup2.split('/');\n const [numerator, denominator] = fractionArray.map(v => parseInt(v));\n finalResult += Math.round((numerator * 1000) / denominator) / 1000;\n }\n\n return finalResult * (dash === '-' ? -1 : 1);\n}\n\nexport default numericQuantity;\n"],"names":[],"mappings":"kPAAA,GAAK,IAAA,GACG,GAAA,QAAA,MACA,EAAA,QAAA,MACA,EAAA,QAAA,MACA,EAAA,UAAA,MACA,EAAA,UAA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AwB,KAAA,IAAM,GAAK,EAC5C"}
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
- "version": "1.0.2",
2
+ "version": "1.0.3",
3
3
  "license": "MIT",
4
4
  "name": "numeric-quantity",
5
5
  "author": "Jake Boone <jakeboone02@gmail.com>",
6
6
  "description": "Number parser with support for mixed numbers and vulgar fractions",
7
- "main": "dist/index.js",
8
- "typings": "dist/index.d.ts",
9
- "module": "dist/numeric-quantity.esm.js",
10
- "unpkg": "dist/numeric-quantity.umd.production.min.js",
11
7
  "files": [
12
8
  "dist"
13
9
  ],
10
+ "main": "./dist/format-quantity.cjs.js",
11
+ "module": "./dist/format-quantity.es.js",
12
+ "unpkg": "./dist/format-quantity.umd.js",
13
+ "typings": "dist/index.d.ts",
14
14
  "bugs": {
15
15
  "url": "https://github.com/jakeboone02/numeric-quantity/issues"
16
16
  },
@@ -29,25 +29,21 @@
29
29
  "decimal"
30
30
  ],
31
31
  "scripts": {
32
- "start": "tsdx watch --format cjs,esm,system,umd",
33
- "build": "tsdx build --format cjs,esm,system,umd",
34
- "test": "tsdx test",
35
- "lint": "tsdx lint",
36
- "prepare": "npm run build",
32
+ "start": "vite",
33
+ "build": "vite build && tsc",
34
+ "test": "jest --coverage",
37
35
  "publish:npm": "np"
38
36
  },
39
- "prettier": {
40
- "printWidth": 80,
41
- "semi": true,
42
- "singleQuote": true,
43
- "trailingComma": "es5",
44
- "arrowParens": "avoid",
45
- "tabWidth": 2
46
- },
47
37
  "devDependencies": {
38
+ "@babel/core": "^7.17.8",
39
+ "@babel/preset-env": "^7.16.11",
40
+ "@babel/preset-typescript": "^7.16.7",
41
+ "@types/jest": "^27.4.1",
42
+ "gh-pages": "^3.1.0",
43
+ "jest": "^27.5.1",
48
44
  "np": "^7.3.0",
49
- "tsdx": "^0.14.1",
50
- "tslib": "^2.1.0",
51
- "typescript": "^4.1.5"
45
+ "prettier": "^2.6.0",
46
+ "typescript": "^4.1.5",
47
+ "vite": "^2.8.6"
52
48
  }
53
49
  }
package/dist/index.js DELETED
@@ -1,8 +0,0 @@
1
-
2
- 'use strict'
3
-
4
- if (process.env.NODE_ENV === 'production') {
5
- module.exports = require('./numeric-quantity.cjs.production.min.js')
6
- } else {
7
- module.exports = require('./numeric-quantity.cjs.development.js')
8
- }
@@ -1,129 +0,0 @@
1
- 'use strict';
2
-
3
- var VulgarFraction;
4
-
5
- (function (VulgarFraction) {
6
- VulgarFraction["\xBC"] = "1/4";
7
- VulgarFraction["\xBD"] = "1/2";
8
- VulgarFraction["\xBE"] = "3/4";
9
- VulgarFraction["\u2150"] = "1/7";
10
- VulgarFraction["\u2151"] = "1/9";
11
- VulgarFraction["\u2152"] = "1/10";
12
- VulgarFraction["\u2153"] = "1/3";
13
- VulgarFraction["\u2154"] = "2/3";
14
- VulgarFraction["\u2155"] = "1/5";
15
- VulgarFraction["\u2156"] = "2/5";
16
- VulgarFraction["\u2157"] = "3/5";
17
- VulgarFraction["\u2158"] = "4/5";
18
- VulgarFraction["\u2159"] = "1/6";
19
- VulgarFraction["\u215A"] = "5/6";
20
- VulgarFraction["\u215B"] = "1/8";
21
- VulgarFraction["\u215C"] = "3/8";
22
- VulgarFraction["\u215D"] = "5/8";
23
- VulgarFraction["\u215E"] = "7/8";
24
- })(VulgarFraction || (VulgarFraction = {}));
25
- /**
26
- * Converts a string to a number. The string can include mixed numbers
27
- * or vulgar fractions.
28
- */
29
-
30
-
31
- function numericQuantity(qty) {
32
- var badResult = NaN;
33
- var finalResult = badResult; // Resolve any unicode vulgar fractions
34
-
35
- var vulgarFractionsRegex = /(¼|½|¾|⅐|⅑|⅒|⅓|⅔|⅕|⅖|⅗|⅘|⅙|⅚|⅛|⅜|⅝|⅞)/;
36
- var sQty = ("" + qty).replace(vulgarFractionsRegex, function (_m, vf) {
37
- return " " + VulgarFraction[vf];
38
- }).replace(/⁄/g, '/').trim();
39
- /**
40
- * Regex captures
41
- *
42
- * +=====+====================+========================+
43
- * | # | Description | Example |
44
- * +=====+====================+========================+
45
- * | 0 | entire string | "2 2/3" from "2 2/3" |
46
- * +-----+--------------------+------------------------+
47
- * | 1 | the dash | "-" from "-2 2/3" |
48
- * +-----+--------------------+------------------------+
49
- * | 2 | the whole number | "2" from "2 2/3" |
50
- * | | - OR - | |
51
- * | | the numerator | "2" from "2/3" |
52
- * +-----+--------------------+------------------------+
53
- * | 3 | entire fraction | "2/3" from "2 2/3" |
54
- * | | - OR - | |
55
- * | | decimal portion | ".66" from "2.66" |
56
- * | | - OR - | |
57
- * | | denominator | "/3" from "2/3" |
58
- * +=====+====================+========================+
59
- *
60
- * re.exec("1") // [ "1", "1", null, null ]
61
- * re.exec("1.23") // [ "1.23", "1", ".23", null ]
62
- * re.exec("1 2/3") // [ "1 2/3", "1", " 2/3", " 2" ]
63
- * re.exec("2/3") // [ "2/3", "2", "/3", null ]
64
- * re.exec("2 / 3") // [ "2 / 3", "2", "/ 3", null ]
65
- */
66
-
67
- var re = /^(-)?\s*(\d*)(\.\d+|(\s+\d*\s*)?\s*\/\s*\d+)?$/;
68
- var ar = re.exec(sQty); // If the regex fails, give up
69
-
70
- if (!ar) {
71
- return badResult;
72
- } // Store the capture groups so we don't have to access the array
73
- // elements over and over
74
-
75
-
76
- var dash = ar[1],
77
- numberGroup1 = ar[2],
78
- numberGroup2 = ar[3]; // The regex can pass and still capture nothing in the relevant groups,
79
- // which means it failed for our purposes
80
-
81
- if (!numberGroup1 && !numberGroup2) {
82
- return badResult;
83
- } // Numerify capture group 1
84
-
85
-
86
- if (!numberGroup1 && numberGroup2 && numberGroup2.search(/^\./) !== -1) {
87
- finalResult = 0;
88
- } else {
89
- finalResult = parseInt(numberGroup1);
90
- }
91
-
92
- if (isNaN(finalResult)) {
93
- return badResult;
94
- } // If capture group 2 is null, then we're dealing with an integer
95
- // and there is nothing left to process
96
-
97
-
98
- if (!numberGroup2) {
99
- return finalResult * (dash === '-' ? -1 : 1);
100
- }
101
-
102
- if (numberGroup2.search(/^\./) !== -1) {
103
- // If first char is "." it's a decimal so just trim to 3 decimal places
104
- var numerator = parseFloat(numberGroup2);
105
- finalResult += Math.round(numerator * 1000) / 1000;
106
- } else if (numberGroup2.search(/^\s*\//) !== -1) {
107
- // If the first non-space char is "/" it's a pure fraction (e.g. "1/2")
108
- var _numerator = parseInt(numberGroup1);
109
-
110
- var denominator = parseInt(numberGroup2.replace('/', ''));
111
- finalResult = Math.round(_numerator * 1000 / denominator) / 1000;
112
- } else {
113
- // Otherwise it's a mixed fraction (e.g. "1 2/3")
114
- var fractionArray = numberGroup2.split('/');
115
-
116
- var _fractionArray$map = fractionArray.map(function (v) {
117
- return parseInt(v);
118
- }),
119
- _numerator2 = _fractionArray$map[0],
120
- _denominator = _fractionArray$map[1];
121
-
122
- finalResult += Math.round(_numerator2 * 1000 / _denominator) / 1000;
123
- }
124
-
125
- return finalResult * (dash === '-' ? -1 : 1);
126
- }
127
-
128
- module.exports = numericQuantity;
129
- //# sourceMappingURL=numeric-quantity.cjs.development.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"numeric-quantity.cjs.development.js","sources":["../src/index.ts"],"sourcesContent":["enum VulgarFraction {\n '¼' = '1/4',\n '½' = '1/2',\n '¾' = '3/4',\n '⅐' = '1/7',\n '⅑' = '1/9',\n '⅒' = '1/10',\n '⅓' = '1/3',\n '⅔' = '2/3',\n '⅕' = '1/5',\n '⅖' = '2/5',\n '⅗' = '3/5',\n '⅘' = '4/5',\n '⅙' = '1/6',\n '⅚' = '5/6',\n '⅛' = '1/8',\n '⅜' = '3/8',\n '⅝' = '5/8',\n '⅞' = '7/8',\n}\n\n/**\n * Converts a string to a number. The string can include mixed numbers\n * or vulgar fractions.\n */\nfunction numericQuantity(qty: string) {\n const badResult = NaN;\n let finalResult = badResult;\n\n // Resolve any unicode vulgar fractions\n const vulgarFractionsRegex = /(¼|½|¾|⅐|⅑|⅒|⅓|⅔|⅕|⅖|⅗|⅘|⅙|⅚|⅛|⅜|⅝|⅞)/;\n\n const sQty = `${qty}`\n .replace(\n vulgarFractionsRegex,\n (_m, vf: keyof typeof VulgarFraction) => ` ${VulgarFraction[vf]}`\n )\n .replace(/⁄/g, '/')\n .trim();\n\n /**\n * Regex captures\n *\n * +=====+====================+========================+\n * | # | Description | Example |\n * +=====+====================+========================+\n * | 0 | entire string | \"2 2/3\" from \"2 2/3\" |\n * +-----+--------------------+------------------------+\n * | 1 | the dash | \"-\" from \"-2 2/3\" |\n * +-----+--------------------+------------------------+\n * | 2 | the whole number | \"2\" from \"2 2/3\" |\n * | | - OR - | |\n * | | the numerator | \"2\" from \"2/3\" |\n * +-----+--------------------+------------------------+\n * | 3 | entire fraction | \"2/3\" from \"2 2/3\" |\n * | | - OR - | |\n * | | decimal portion | \".66\" from \"2.66\" |\n * | | - OR - | |\n * | | denominator | \"/3\" from \"2/3\" |\n * +=====+====================+========================+\n *\n * re.exec(\"1\") // [ \"1\", \"1\", null, null ]\n * re.exec(\"1.23\") // [ \"1.23\", \"1\", \".23\", null ]\n * re.exec(\"1 2/3\") // [ \"1 2/3\", \"1\", \" 2/3\", \" 2\" ]\n * re.exec(\"2/3\") // [ \"2/3\", \"2\", \"/3\", null ]\n * re.exec(\"2 / 3\") // [ \"2 / 3\", \"2\", \"/ 3\", null ]\n */\n const re = /^(-)?\\s*(\\d*)(\\.\\d+|(\\s+\\d*\\s*)?\\s*\\/\\s*\\d+)?$/;\n\n const ar = re.exec(sQty);\n\n // If the regex fails, give up\n if (!ar) {\n return badResult;\n }\n\n // Store the capture groups so we don't have to access the array\n // elements over and over\n const [, dash, numberGroup1, numberGroup2] = ar;\n\n // The regex can pass and still capture nothing in the relevant groups,\n // which means it failed for our purposes\n if (!numberGroup1 && !numberGroup2) {\n return badResult;\n }\n\n // Numerify capture group 1\n if (!numberGroup1 && numberGroup2 && numberGroup2.search(/^\\./) !== -1) {\n finalResult = 0;\n } else {\n finalResult = parseInt(numberGroup1);\n }\n\n if (isNaN(finalResult)) {\n return badResult;\n }\n\n // If capture group 2 is null, then we're dealing with an integer\n // and there is nothing left to process\n if (!numberGroup2) {\n return finalResult * (dash === '-' ? -1 : 1);\n }\n\n if (numberGroup2.search(/^\\./) !== -1) {\n // If first char is \".\" it's a decimal so just trim to 3 decimal places\n const numerator = parseFloat(numberGroup2);\n finalResult += Math.round(numerator * 1000) / 1000;\n } else if (numberGroup2.search(/^\\s*\\//) !== -1) {\n // If the first non-space char is \"/\" it's a pure fraction (e.g. \"1/2\")\n const numerator = parseInt(numberGroup1);\n const denominator = parseInt(numberGroup2.replace('/', ''));\n finalResult = Math.round((numerator * 1000) / denominator) / 1000;\n } else {\n // Otherwise it's a mixed fraction (e.g. \"1 2/3\")\n const fractionArray = numberGroup2.split('/');\n const [numerator, denominator] = fractionArray.map(v => parseInt(v));\n finalResult += Math.round((numerator * 1000) / denominator) / 1000;\n }\n\n return finalResult * (dash === '-' ? -1 : 1);\n}\n\nexport default numericQuantity;\n"],"names":["VulgarFraction","numericQuantity","qty","badResult","NaN","finalResult","vulgarFractionsRegex","sQty","replace","_m","vf","trim","re","ar","exec","dash","numberGroup1","numberGroup2","search","parseInt","isNaN","numerator","parseFloat","Math","round","denominator","fractionArray","split","map","v"],"mappings":";;AAAA,IAAKA,cAAL;;AAAA,WAAKA;AACHA,EAAAA,sBAAA,QAAA;AACAA,EAAAA,sBAAA,QAAA;AACAA,EAAAA,sBAAA,QAAA;AACAA,EAAAA,wBAAA,QAAA;AACAA,EAAAA,wBAAA,QAAA;AACAA,EAAAA,wBAAA,SAAA;AACAA,EAAAA,wBAAA,QAAA;AACAA,EAAAA,wBAAA,QAAA;AACAA,EAAAA,wBAAA,QAAA;AACAA,EAAAA,wBAAA,QAAA;AACAA,EAAAA,wBAAA,QAAA;AACAA,EAAAA,wBAAA,QAAA;AACAA,EAAAA,wBAAA,QAAA;AACAA,EAAAA,wBAAA,QAAA;AACAA,EAAAA,wBAAA,QAAA;AACAA,EAAAA,wBAAA,QAAA;AACAA,EAAAA,wBAAA,QAAA;AACAA,EAAAA,wBAAA,QAAA;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,SAAS,GAAGC,UAAU,CAACL,YAAD,CAA5B;AACAZ,IAAAA,WAAW,IAAIkB,IAAI,CAACC,KAAL,CAAWH,SAAS,GAAG,IAAvB,IAA+B,IAA9C;AACD,GAJD,MAIO,IAAIJ,YAAY,CAACC,MAAb,CAAoB,QAApB,MAAkC,CAAC,CAAvC,EAA0C;AAC/C;AACA,QAAMG,UAAS,GAAGF,QAAQ,CAACH,YAAD,CAA1B;;AACA,QAAMS,WAAW,GAAGN,QAAQ,CAACF,YAAY,CAACT,OAAb,CAAqB,GAArB,EAA0B,EAA1B,CAAD,CAA5B;AACAH,IAAAA,WAAW,GAAGkB,IAAI,CAACC,KAAL,CAAYH,UAAS,GAAG,IAAb,GAAqBI,WAAhC,IAA+C,IAA7D;AACD,GALM,MAKA;AACL;AACA,QAAMC,aAAa,GAAGT,YAAY,CAACU,KAAb,CAAmB,GAAnB,CAAtB;;AAFK,6BAG4BD,aAAa,CAACE,GAAd,CAAkB,UAAAC,CAAC;AAAA,aAAIV,QAAQ,CAACU,CAAD,CAAZ;AAAA,KAAnB,CAH5B;AAAA,QAGER,WAHF;AAAA,QAGaI,YAHb;;AAILpB,IAAAA,WAAW,IAAIkB,IAAI,CAACC,KAAL,CAAYH,WAAS,GAAG,IAAb,GAAqBI,YAAhC,IAA+C,IAA9D;AACD;;AAED,SAAOpB,WAAW,IAAIU,IAAI,KAAK,GAAT,GAAe,CAAC,CAAhB,GAAoB,CAAxB,CAAlB;AACD;;;;"}
@@ -1,2 +0,0 @@
1
- "use strict";var r;!function(r){r["¼"]="1/4",r["½"]="1/2",r["¾"]="3/4",r["⅐"]="1/7",r["⅑"]="1/9",r["⅒"]="1/10",r["⅓"]="1/3",r["⅔"]="2/3",r["⅕"]="1/5",r["⅖"]="2/5",r["⅗"]="3/5",r["⅘"]="4/5",r["⅙"]="1/6",r["⅚"]="5/6",r["⅛"]="1/8",r["⅜"]="3/8",r["⅝"]="5/8",r["⅞"]="7/8"}(r||(r={})),module.exports=function(e){var a=NaN,t=(""+e).replace(/(¼|½|¾|⅐|⅑|⅒|⅓|⅔|⅕|⅖|⅗|⅘|⅙|⅚|⅛|⅜|⅝|⅞)/,(function(e,a){return" "+r[a]})).replace(/⁄/g,"/").trim(),n=/^(-)?\s*(\d*)(\.\d+|(\s+\d*\s*)?\s*\/\s*\d+)?$/.exec(t);if(!n)return NaN;var s=n[1],u=n[2],i=n[3];if(!u&&!i)return NaN;if(a=!u&&i&&-1!==i.search(/^\./)?0:parseInt(u),isNaN(a))return NaN;if(!i)return a*("-"===s?-1:1);if(-1!==i.search(/^\./)){var c=parseFloat(i);a+=Math.round(1e3*c)/1e3}else if(-1!==i.search(/^\s*\//)){var p=parseInt(u),f=parseInt(i.replace("/",""));a=Math.round(1e3*p/f)/1e3}else{var o=i.split("/").map((function(r){return parseInt(r)}));a+=Math.round(1e3*o[0]/o[1])/1e3}return a*("-"===s?-1:1)};
2
- //# sourceMappingURL=numeric-quantity.cjs.production.min.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"numeric-quantity.cjs.production.min.js","sources":["../src/index.ts"],"sourcesContent":["enum VulgarFraction {\n '¼' = '1/4',\n '½' = '1/2',\n '¾' = '3/4',\n '⅐' = '1/7',\n '⅑' = '1/9',\n '⅒' = '1/10',\n '⅓' = '1/3',\n '⅔' = '2/3',\n '⅕' = '1/5',\n '⅖' = '2/5',\n '⅗' = '3/5',\n '⅘' = '4/5',\n '⅙' = '1/6',\n '⅚' = '5/6',\n '⅛' = '1/8',\n '⅜' = '3/8',\n '⅝' = '5/8',\n '⅞' = '7/8',\n}\n\n/**\n * Converts a string to a number. The string can include mixed numbers\n * or vulgar fractions.\n */\nfunction numericQuantity(qty: string) {\n const badResult = NaN;\n let finalResult = badResult;\n\n // Resolve any unicode vulgar fractions\n const vulgarFractionsRegex = /(¼|½|¾|⅐|⅑|⅒|⅓|⅔|⅕|⅖|⅗|⅘|⅙|⅚|⅛|⅜|⅝|⅞)/;\n\n const sQty = `${qty}`\n .replace(\n vulgarFractionsRegex,\n (_m, vf: keyof typeof VulgarFraction) => ` ${VulgarFraction[vf]}`\n )\n .replace(/⁄/g, '/')\n .trim();\n\n /**\n * Regex captures\n *\n * +=====+====================+========================+\n * | # | Description | Example |\n * +=====+====================+========================+\n * | 0 | entire string | \"2 2/3\" from \"2 2/3\" |\n * +-----+--------------------+------------------------+\n * | 1 | the dash | \"-\" from \"-2 2/3\" |\n * +-----+--------------------+------------------------+\n * | 2 | the whole number | \"2\" from \"2 2/3\" |\n * | | - OR - | |\n * | | the numerator | \"2\" from \"2/3\" |\n * +-----+--------------------+------------------------+\n * | 3 | entire fraction | \"2/3\" from \"2 2/3\" |\n * | | - OR - | |\n * | | decimal portion | \".66\" from \"2.66\" |\n * | | - OR - | |\n * | | denominator | \"/3\" from \"2/3\" |\n * +=====+====================+========================+\n *\n * re.exec(\"1\") // [ \"1\", \"1\", null, null ]\n * re.exec(\"1.23\") // [ \"1.23\", \"1\", \".23\", null ]\n * re.exec(\"1 2/3\") // [ \"1 2/3\", \"1\", \" 2/3\", \" 2\" ]\n * re.exec(\"2/3\") // [ \"2/3\", \"2\", \"/3\", null ]\n * re.exec(\"2 / 3\") // [ \"2 / 3\", \"2\", \"/ 3\", null ]\n */\n const re = /^(-)?\\s*(\\d*)(\\.\\d+|(\\s+\\d*\\s*)?\\s*\\/\\s*\\d+)?$/;\n\n const ar = re.exec(sQty);\n\n // If the regex fails, give up\n if (!ar) {\n return badResult;\n }\n\n // Store the capture groups so we don't have to access the array\n // elements over and over\n const [, dash, numberGroup1, numberGroup2] = ar;\n\n // The regex can pass and still capture nothing in the relevant groups,\n // which means it failed for our purposes\n if (!numberGroup1 && !numberGroup2) {\n return badResult;\n }\n\n // Numerify capture group 1\n if (!numberGroup1 && numberGroup2 && numberGroup2.search(/^\\./) !== -1) {\n finalResult = 0;\n } else {\n finalResult = parseInt(numberGroup1);\n }\n\n if (isNaN(finalResult)) {\n return badResult;\n }\n\n // If capture group 2 is null, then we're dealing with an integer\n // and there is nothing left to process\n if (!numberGroup2) {\n return finalResult * (dash === '-' ? -1 : 1);\n }\n\n if (numberGroup2.search(/^\\./) !== -1) {\n // If first char is \".\" it's a decimal so just trim to 3 decimal places\n const numerator = parseFloat(numberGroup2);\n finalResult += Math.round(numerator * 1000) / 1000;\n } else if (numberGroup2.search(/^\\s*\\//) !== -1) {\n // If the first non-space char is \"/\" it's a pure fraction (e.g. \"1/2\")\n const numerator = parseInt(numberGroup1);\n const denominator = parseInt(numberGroup2.replace('/', ''));\n finalResult = Math.round((numerator * 1000) / denominator) / 1000;\n } else {\n // Otherwise it's a mixed fraction (e.g. \"1 2/3\")\n const fractionArray = numberGroup2.split('/');\n const [numerator, denominator] = fractionArray.map(v => parseInt(v));\n finalResult += Math.round((numerator * 1000) / denominator) / 1000;\n }\n\n return finalResult * (dash === '-' ? -1 : 1);\n}\n\nexport default numericQuantity;\n"],"names":["VulgarFraction","qty","finalResult","NaN","sQty","replace","_m","vf","trim","ar","exec","dash","numberGroup1","numberGroup2","search","parseInt","isNaN","numerator","parseFloat","Math","round","denominator","split","map","v"],"mappings":"aAAA,IAAKA,GAAL,SAAKA,GACHA,aACAA,aACAA,aACAA,aACAA,aACAA,cACAA,aACAA,aACAA,aACAA,aACAA,aACAA,aACAA,aACAA,aACAA,aACAA,aACAA,aACAA,aAlBF,CAAKA,IAAAA,sBAyBL,SAAyBC,OAEnBC,EADcC,IAMZC,MAAUH,GACbI,QAH0B,yCAKzB,SAACC,EAAIC,aAAwCP,EAAeO,MAE7DF,QAAQ,KAAM,KACdG,OA+BGC,EAFK,iDAEGC,KAAKN,OAGdK,SA9CaN,QAoDTQ,EAAoCF,KAA9BG,EAA8BH,KAAhBI,EAAgBJ,SAIxCG,IAAiBC,SAxDJV,OA8DhBD,GADGU,GAAgBC,IAAgD,IAAhCA,EAAaC,OAAO,OACzC,EAEAC,SAASH,GAGrBI,MAAMd,UAnEQC,QAyEbU,SACIX,GAAwB,MAATS,GAAgB,EAAI,OAGR,IAAhCE,EAAaC,OAAO,OAAe,KAE/BG,EAAYC,WAAWL,GAC7BX,GAAeiB,KAAKC,MAAkB,IAAZH,GAAoB,SACzC,IAAuC,IAAnCJ,EAAaC,OAAO,UAAkB,KAEzCG,EAAYF,SAASH,GACrBS,EAAcN,SAASF,EAAaR,QAAQ,IAAK,KACvDH,EAAciB,KAAKC,MAAmB,IAAZH,EAAoBI,GAAe,QACxD,OAEiBR,EAAaS,MAAM,KACMC,KAAI,SAAAC,UAAKT,SAASS,MACjEtB,GAAeiB,KAAKC,MAAmB,eAAuB,WAGzDlB,GAAwB,MAATS,GAAgB,EAAI"}
@@ -1,127 +0,0 @@
1
- var VulgarFraction;
2
-
3
- (function (VulgarFraction) {
4
- VulgarFraction["\xBC"] = "1/4";
5
- VulgarFraction["\xBD"] = "1/2";
6
- VulgarFraction["\xBE"] = "3/4";
7
- VulgarFraction["\u2150"] = "1/7";
8
- VulgarFraction["\u2151"] = "1/9";
9
- VulgarFraction["\u2152"] = "1/10";
10
- VulgarFraction["\u2153"] = "1/3";
11
- VulgarFraction["\u2154"] = "2/3";
12
- VulgarFraction["\u2155"] = "1/5";
13
- VulgarFraction["\u2156"] = "2/5";
14
- VulgarFraction["\u2157"] = "3/5";
15
- VulgarFraction["\u2158"] = "4/5";
16
- VulgarFraction["\u2159"] = "1/6";
17
- VulgarFraction["\u215A"] = "5/6";
18
- VulgarFraction["\u215B"] = "1/8";
19
- VulgarFraction["\u215C"] = "3/8";
20
- VulgarFraction["\u215D"] = "5/8";
21
- VulgarFraction["\u215E"] = "7/8";
22
- })(VulgarFraction || (VulgarFraction = {}));
23
- /**
24
- * Converts a string to a number. The string can include mixed numbers
25
- * or vulgar fractions.
26
- */
27
-
28
-
29
- function numericQuantity(qty) {
30
- var badResult = NaN;
31
- var finalResult = badResult; // Resolve any unicode vulgar fractions
32
-
33
- var vulgarFractionsRegex = /(¼|½|¾|⅐|⅑|⅒|⅓|⅔|⅕|⅖|⅗|⅘|⅙|⅚|⅛|⅜|⅝|⅞)/;
34
- var sQty = ("" + qty).replace(vulgarFractionsRegex, function (_m, vf) {
35
- return " " + VulgarFraction[vf];
36
- }).replace(/⁄/g, '/').trim();
37
- /**
38
- * Regex captures
39
- *
40
- * +=====+====================+========================+
41
- * | # | Description | Example |
42
- * +=====+====================+========================+
43
- * | 0 | entire string | "2 2/3" from "2 2/3" |
44
- * +-----+--------------------+------------------------+
45
- * | 1 | the dash | "-" from "-2 2/3" |
46
- * +-----+--------------------+------------------------+
47
- * | 2 | the whole number | "2" from "2 2/3" |
48
- * | | - OR - | |
49
- * | | the numerator | "2" from "2/3" |
50
- * +-----+--------------------+------------------------+
51
- * | 3 | entire fraction | "2/3" from "2 2/3" |
52
- * | | - OR - | |
53
- * | | decimal portion | ".66" from "2.66" |
54
- * | | - OR - | |
55
- * | | denominator | "/3" from "2/3" |
56
- * +=====+====================+========================+
57
- *
58
- * re.exec("1") // [ "1", "1", null, null ]
59
- * re.exec("1.23") // [ "1.23", "1", ".23", null ]
60
- * re.exec("1 2/3") // [ "1 2/3", "1", " 2/3", " 2" ]
61
- * re.exec("2/3") // [ "2/3", "2", "/3", null ]
62
- * re.exec("2 / 3") // [ "2 / 3", "2", "/ 3", null ]
63
- */
64
-
65
- var re = /^(-)?\s*(\d*)(\.\d+|(\s+\d*\s*)?\s*\/\s*\d+)?$/;
66
- var ar = re.exec(sQty); // If the regex fails, give up
67
-
68
- if (!ar) {
69
- return badResult;
70
- } // Store the capture groups so we don't have to access the array
71
- // elements over and over
72
-
73
-
74
- var dash = ar[1],
75
- numberGroup1 = ar[2],
76
- numberGroup2 = ar[3]; // The regex can pass and still capture nothing in the relevant groups,
77
- // which means it failed for our purposes
78
-
79
- if (!numberGroup1 && !numberGroup2) {
80
- return badResult;
81
- } // Numerify capture group 1
82
-
83
-
84
- if (!numberGroup1 && numberGroup2 && numberGroup2.search(/^\./) !== -1) {
85
- finalResult = 0;
86
- } else {
87
- finalResult = parseInt(numberGroup1);
88
- }
89
-
90
- if (isNaN(finalResult)) {
91
- return badResult;
92
- } // If capture group 2 is null, then we're dealing with an integer
93
- // and there is nothing left to process
94
-
95
-
96
- if (!numberGroup2) {
97
- return finalResult * (dash === '-' ? -1 : 1);
98
- }
99
-
100
- if (numberGroup2.search(/^\./) !== -1) {
101
- // If first char is "." it's a decimal so just trim to 3 decimal places
102
- var numerator = parseFloat(numberGroup2);
103
- finalResult += Math.round(numerator * 1000) / 1000;
104
- } else if (numberGroup2.search(/^\s*\//) !== -1) {
105
- // If the first non-space char is "/" it's a pure fraction (e.g. "1/2")
106
- var _numerator = parseInt(numberGroup1);
107
-
108
- var denominator = parseInt(numberGroup2.replace('/', ''));
109
- finalResult = Math.round(_numerator * 1000 / denominator) / 1000;
110
- } else {
111
- // Otherwise it's a mixed fraction (e.g. "1 2/3")
112
- var fractionArray = numberGroup2.split('/');
113
-
114
- var _fractionArray$map = fractionArray.map(function (v) {
115
- return parseInt(v);
116
- }),
117
- _numerator2 = _fractionArray$map[0],
118
- _denominator = _fractionArray$map[1];
119
-
120
- finalResult += Math.round(_numerator2 * 1000 / _denominator) / 1000;
121
- }
122
-
123
- return finalResult * (dash === '-' ? -1 : 1);
124
- }
125
-
126
- export default numericQuantity;
127
- //# sourceMappingURL=numeric-quantity.esm.js.map
@@ -1,135 +0,0 @@
1
- System.register('numericQuantity', [], function (exports) {
2
- 'use strict';
3
- return {
4
- execute: function () {
5
-
6
- var VulgarFraction;
7
-
8
- (function (VulgarFraction) {
9
- VulgarFraction["\xBC"] = "1/4";
10
- VulgarFraction["\xBD"] = "1/2";
11
- VulgarFraction["\xBE"] = "3/4";
12
- VulgarFraction["\u2150"] = "1/7";
13
- VulgarFraction["\u2151"] = "1/9";
14
- VulgarFraction["\u2152"] = "1/10";
15
- VulgarFraction["\u2153"] = "1/3";
16
- VulgarFraction["\u2154"] = "2/3";
17
- VulgarFraction["\u2155"] = "1/5";
18
- VulgarFraction["\u2156"] = "2/5";
19
- VulgarFraction["\u2157"] = "3/5";
20
- VulgarFraction["\u2158"] = "4/5";
21
- VulgarFraction["\u2159"] = "1/6";
22
- VulgarFraction["\u215A"] = "5/6";
23
- VulgarFraction["\u215B"] = "1/8";
24
- VulgarFraction["\u215C"] = "3/8";
25
- VulgarFraction["\u215D"] = "5/8";
26
- VulgarFraction["\u215E"] = "7/8";
27
- })(VulgarFraction || (VulgarFraction = {}));
28
- /**
29
- * Converts a string to a number. The string can include mixed numbers
30
- * or vulgar fractions.
31
- */
32
-
33
-
34
- function numericQuantity(qty) {
35
- var badResult = NaN;
36
- var finalResult = badResult; // Resolve any unicode vulgar fractions
37
-
38
- var vulgarFractionsRegex = /(¼|½|¾|⅐|⅑|⅒|⅓|⅔|⅕|⅖|⅗|⅘|⅙|⅚|⅛|⅜|⅝|⅞)/;
39
- var sQty = ("" + qty).replace(vulgarFractionsRegex, function (_m, vf) {
40
- return " " + VulgarFraction[vf];
41
- }).replace(/⁄/g, '/').trim();
42
- /**
43
- * Regex captures
44
- *
45
- * +=====+====================+========================+
46
- * | # | Description | Example |
47
- * +=====+====================+========================+
48
- * | 0 | entire string | "2 2/3" from "2 2/3" |
49
- * +-----+--------------------+------------------------+
50
- * | 1 | the dash | "-" from "-2 2/3" |
51
- * +-----+--------------------+------------------------+
52
- * | 2 | the whole number | "2" from "2 2/3" |
53
- * | | - OR - | |
54
- * | | the numerator | "2" from "2/3" |
55
- * +-----+--------------------+------------------------+
56
- * | 3 | entire fraction | "2/3" from "2 2/3" |
57
- * | | - OR - | |
58
- * | | decimal portion | ".66" from "2.66" |
59
- * | | - OR - | |
60
- * | | denominator | "/3" from "2/3" |
61
- * +=====+====================+========================+
62
- *
63
- * re.exec("1") // [ "1", "1", null, null ]
64
- * re.exec("1.23") // [ "1.23", "1", ".23", null ]
65
- * re.exec("1 2/3") // [ "1 2/3", "1", " 2/3", " 2" ]
66
- * re.exec("2/3") // [ "2/3", "2", "/3", null ]
67
- * re.exec("2 / 3") // [ "2 / 3", "2", "/ 3", null ]
68
- */
69
-
70
- var re = /^(-)?\s*(\d*)(\.\d+|(\s+\d*\s*)?\s*\/\s*\d+)?$/;
71
- var ar = re.exec(sQty); // If the regex fails, give up
72
-
73
- if (!ar) {
74
- return badResult;
75
- } // Store the capture groups so we don't have to access the array
76
- // elements over and over
77
-
78
-
79
- var dash = ar[1],
80
- numberGroup1 = ar[2],
81
- numberGroup2 = ar[3]; // The regex can pass and still capture nothing in the relevant groups,
82
- // which means it failed for our purposes
83
-
84
- if (!numberGroup1 && !numberGroup2) {
85
- return badResult;
86
- } // Numerify capture group 1
87
-
88
-
89
- if (!numberGroup1 && numberGroup2 && numberGroup2.search(/^\./) !== -1) {
90
- finalResult = 0;
91
- } else {
92
- finalResult = parseInt(numberGroup1);
93
- }
94
-
95
- if (isNaN(finalResult)) {
96
- return badResult;
97
- } // If capture group 2 is null, then we're dealing with an integer
98
- // and there is nothing left to process
99
-
100
-
101
- if (!numberGroup2) {
102
- return finalResult * (dash === '-' ? -1 : 1);
103
- }
104
-
105
- if (numberGroup2.search(/^\./) !== -1) {
106
- // If first char is "." it's a decimal so just trim to 3 decimal places
107
- var numerator = parseFloat(numberGroup2);
108
- finalResult += Math.round(numerator * 1000) / 1000;
109
- } else if (numberGroup2.search(/^\s*\//) !== -1) {
110
- // If the first non-space char is "/" it's a pure fraction (e.g. "1/2")
111
- var _numerator = parseInt(numberGroup1);
112
-
113
- var denominator = parseInt(numberGroup2.replace('/', ''));
114
- finalResult = Math.round(_numerator * 1000 / denominator) / 1000;
115
- } else {
116
- // Otherwise it's a mixed fraction (e.g. "1 2/3")
117
- var fractionArray = numberGroup2.split('/');
118
-
119
- var _fractionArray$map = fractionArray.map(function (v) {
120
- return parseInt(v);
121
- }),
122
- _numerator2 = _fractionArray$map[0],
123
- _denominator = _fractionArray$map[1];
124
-
125
- finalResult += Math.round(_numerator2 * 1000 / _denominator) / 1000;
126
- }
127
-
128
- return finalResult * (dash === '-' ? -1 : 1);
129
- }
130
- exports('default', numericQuantity);
131
-
132
- }
133
- };
134
- });
135
- //# sourceMappingURL=numeric-quantity.system.development.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"numeric-quantity.system.development.js","sources":["../src/index.ts"],"sourcesContent":["enum VulgarFraction {\n '¼' = '1/4',\n '½' = '1/2',\n '¾' = '3/4',\n '⅐' = '1/7',\n '⅑' = '1/9',\n '⅒' = '1/10',\n '⅓' = '1/3',\n '⅔' = '2/3',\n '⅕' = '1/5',\n '⅖' = '2/5',\n '⅗' = '3/5',\n '⅘' = '4/5',\n '⅙' = '1/6',\n '⅚' = '5/6',\n '⅛' = '1/8',\n '⅜' = '3/8',\n '⅝' = '5/8',\n '⅞' = '7/8',\n}\n\n/**\n * Converts a string to a number. The string can include mixed numbers\n * or vulgar fractions.\n */\nfunction numericQuantity(qty: string) {\n const badResult = NaN;\n let finalResult = badResult;\n\n // Resolve any unicode vulgar fractions\n const vulgarFractionsRegex = /(¼|½|¾|⅐|⅑|⅒|⅓|⅔|⅕|⅖|⅗|⅘|⅙|⅚|⅛|⅜|⅝|⅞)/;\n\n const sQty = `${qty}`\n .replace(\n vulgarFractionsRegex,\n (_m, vf: keyof typeof VulgarFraction) => ` ${VulgarFraction[vf]}`\n )\n .replace(/⁄/g, '/')\n .trim();\n\n /**\n * Regex captures\n *\n * +=====+====================+========================+\n * | # | Description | Example |\n * +=====+====================+========================+\n * | 0 | entire string | \"2 2/3\" from \"2 2/3\" |\n * +-----+--------------------+------------------------+\n * | 1 | the dash | \"-\" from \"-2 2/3\" |\n * +-----+--------------------+------------------------+\n * | 2 | the whole number | \"2\" from \"2 2/3\" |\n * | | - OR - | |\n * | | the numerator | \"2\" from \"2/3\" |\n * +-----+--------------------+------------------------+\n * | 3 | entire fraction | \"2/3\" from \"2 2/3\" |\n * | | - OR - | |\n * | | decimal portion | \".66\" from \"2.66\" |\n * | | - OR - | |\n * | | denominator | \"/3\" from \"2/3\" |\n * +=====+====================+========================+\n *\n * re.exec(\"1\") // [ \"1\", \"1\", null, null ]\n * re.exec(\"1.23\") // [ \"1.23\", \"1\", \".23\", null ]\n * re.exec(\"1 2/3\") // [ \"1 2/3\", \"1\", \" 2/3\", \" 2\" ]\n * re.exec(\"2/3\") // [ \"2/3\", \"2\", \"/3\", null ]\n * re.exec(\"2 / 3\") // [ \"2 / 3\", \"2\", \"/ 3\", null ]\n */\n const re = /^(-)?\\s*(\\d*)(\\.\\d+|(\\s+\\d*\\s*)?\\s*\\/\\s*\\d+)?$/;\n\n const ar = re.exec(sQty);\n\n // If the regex fails, give up\n if (!ar) {\n return badResult;\n }\n\n // Store the capture groups so we don't have to access the array\n // elements over and over\n const [, dash, numberGroup1, numberGroup2] = ar;\n\n // The regex can pass and still capture nothing in the relevant groups,\n // which means it failed for our purposes\n if (!numberGroup1 && !numberGroup2) {\n return badResult;\n }\n\n // Numerify capture group 1\n if (!numberGroup1 && numberGroup2 && numberGroup2.search(/^\\./) !== -1) {\n finalResult = 0;\n } else {\n finalResult = parseInt(numberGroup1);\n }\n\n if (isNaN(finalResult)) {\n return badResult;\n }\n\n // If capture group 2 is null, then we're dealing with an integer\n // and there is nothing left to process\n if (!numberGroup2) {\n return finalResult * (dash === '-' ? -1 : 1);\n }\n\n if (numberGroup2.search(/^\\./) !== -1) {\n // If first char is \".\" it's a decimal so just trim to 3 decimal places\n const numerator = parseFloat(numberGroup2);\n finalResult += Math.round(numerator * 1000) / 1000;\n } else if (numberGroup2.search(/^\\s*\\//) !== -1) {\n // If the first non-space char is \"/\" it's a pure fraction (e.g. \"1/2\")\n const numerator = parseInt(numberGroup1);\n const denominator = parseInt(numberGroup2.replace('/', ''));\n finalResult = Math.round((numerator * 1000) / denominator) / 1000;\n } else {\n // Otherwise it's a mixed fraction (e.g. \"1 2/3\")\n const fractionArray = numberGroup2.split('/');\n const [numerator, denominator] = fractionArray.map(v => parseInt(v));\n finalResult += Math.round((numerator * 1000) / denominator) / 1000;\n }\n\n return finalResult * (dash === '-' ? -1 : 1);\n}\n\nexport default numericQuantity;\n"],"names":["VulgarFraction","numericQuantity","qty","badResult","NaN","finalResult","vulgarFractionsRegex","sQty","replace","_m","vf","trim","re","ar","exec","dash","numberGroup1","numberGroup2","search","parseInt","isNaN","numerator","parseFloat","Math","round","denominator","fractionArray","split","map","v"],"mappings":";;;;;MAAA,IAAKA,cAAL;;MAAA,WAAKA;MACHA,EAAAA,sBAAA,QAAA;MACAA,EAAAA,sBAAA,QAAA;MACAA,EAAAA,sBAAA,QAAA;MACAA,EAAAA,wBAAA,QAAA;MACAA,EAAAA,wBAAA,QAAA;MACAA,EAAAA,wBAAA,SAAA;MACAA,EAAAA,wBAAA,QAAA;MACAA,EAAAA,wBAAA,QAAA;MACAA,EAAAA,wBAAA,QAAA;MACAA,EAAAA,wBAAA,QAAA;MACAA,EAAAA,wBAAA,QAAA;MACAA,EAAAA,wBAAA,QAAA;MACAA,EAAAA,wBAAA,QAAA;MACAA,EAAAA,wBAAA,QAAA;MACAA,EAAAA,wBAAA,QAAA;MACAA,EAAAA,wBAAA,QAAA;MACAA,EAAAA,wBAAA,QAAA;MACAA,EAAAA,wBAAA,QAAA;MACD,CAnBD,EAAKA,cAAc,KAAdA,cAAc,KAAA,CAAnB;MAqBA;;;;;;MAIA,SAASC,eAAT,CAAyBC,GAAzB;MACE,MAAMC,SAAS,GAAGC,GAAlB;MACA,MAAIC,WAAW,GAAGF,SAAlB;;MAGA,MAAMG,oBAAoB,GAAG,uCAA7B;MAEA,MAAMC,IAAI,GAAG,MAAGL,GAAH,EACVM,OADU,CAETF,oBAFS,EAGT,UAACG,EAAD,EAAKC,EAAL;MAAA,iBAA6CV,cAAc,CAACU,EAAD,CAA3D;MAAA,GAHS,EAKVF,OALU,CAKF,IALE,EAKI,GALJ,EAMVG,IANU,EAAb;MAQA;;;;;;;;;;;;;;;;;;;;;;;;;;;;MA2BA,MAAMC,EAAE,GAAG,gDAAX;MAEA,MAAMC,EAAE,GAAGD,EAAE,CAACE,IAAH,CAAQP,IAAR,CAAX;;MAGA,MAAI,CAACM,EAAL,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,6BAG4BD,aAAa,CAACE,GAAd,CAAkB,UAAAC,CAAC;MAAA,aAAIV,QAAQ,CAACU,CAAD,CAAZ;MAAA,KAAnB,CAH5B;MAAA,QAGER,WAHF;MAAA,QAGaI,YAHb;;MAILpB,IAAAA,WAAW,IAAIkB,IAAI,CAACC,KAAL,CAAYH,WAAS,GAAG,IAAb,GAAqBI,YAAhC,IAA+C,IAA9D;MACD;;MAED,SAAOpB,WAAW,IAAIU,IAAI,KAAK,GAAT,GAAe,CAAC,CAAhB,GAAoB,CAAxB,CAAlB;MACD;;;;;;;"}
@@ -1,2 +0,0 @@
1
- System.register("numericQuantity",[],(function(e){"use strict";return{execute:function(){var r;!function(e){e["¼"]="1/4",e["½"]="1/2",e["¾"]="3/4",e["⅐"]="1/7",e["⅑"]="1/9",e["⅒"]="1/10",e["⅓"]="1/3",e["⅔"]="2/3",e["⅕"]="1/5",e["⅖"]="2/5",e["⅗"]="3/5",e["⅘"]="4/5",e["⅙"]="1/6",e["⅚"]="5/6",e["⅛"]="1/8",e["⅜"]="3/8",e["⅝"]="5/8",e["⅞"]="7/8"}(r||(r={})),e("default",(function(e){var t=NaN,a=(""+e).replace(/(¼|½|¾|⅐|⅑|⅒|⅓|⅔|⅕|⅖|⅗|⅘|⅙|⅚|⅛|⅜|⅝|⅞)/,(function(e,t){return" "+r[t]})).replace(/⁄/g,"/").trim(),n=/^(-)?\s*(\d*)(\.\d+|(\s+\d*\s*)?\s*\/\s*\d+)?$/.exec(a);if(!n)return NaN;var s=n[1],u=n[2],i=n[3];if(!u&&!i)return NaN;if(t=!u&&i&&-1!==i.search(/^\./)?0:parseInt(u),isNaN(t))return NaN;if(!i)return t*("-"===s?-1:1);if(-1!==i.search(/^\./)){var c=parseFloat(i);t+=Math.round(1e3*c)/1e3}else if(-1!==i.search(/^\s*\//)){var f=parseInt(u),o=parseInt(i.replace("/",""));t=Math.round(1e3*f/o)/1e3}else{var p=i.split("/").map((function(e){return parseInt(e)}));t+=Math.round(1e3*p[0]/p[1])/1e3}return t*("-"===s?-1:1)}))}}}));
2
- //# sourceMappingURL=numeric-quantity.system.production.min.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"numeric-quantity.system.production.min.js","sources":["../src/index.ts"],"sourcesContent":["enum VulgarFraction {\n '¼' = '1/4',\n '½' = '1/2',\n '¾' = '3/4',\n '⅐' = '1/7',\n '⅑' = '1/9',\n '⅒' = '1/10',\n '⅓' = '1/3',\n '⅔' = '2/3',\n '⅕' = '1/5',\n '⅖' = '2/5',\n '⅗' = '3/5',\n '⅘' = '4/5',\n '⅙' = '1/6',\n '⅚' = '5/6',\n '⅛' = '1/8',\n '⅜' = '3/8',\n '⅝' = '5/8',\n '⅞' = '7/8',\n}\n\n/**\n * Converts a string to a number. The string can include mixed numbers\n * or vulgar fractions.\n */\nfunction numericQuantity(qty: string) {\n const badResult = NaN;\n let finalResult = badResult;\n\n // Resolve any unicode vulgar fractions\n const vulgarFractionsRegex = /(¼|½|¾|⅐|⅑|⅒|⅓|⅔|⅕|⅖|⅗|⅘|⅙|⅚|⅛|⅜|⅝|⅞)/;\n\n const sQty = `${qty}`\n .replace(\n vulgarFractionsRegex,\n (_m, vf: keyof typeof VulgarFraction) => ` ${VulgarFraction[vf]}`\n )\n .replace(/⁄/g, '/')\n .trim();\n\n /**\n * Regex captures\n *\n * +=====+====================+========================+\n * | # | Description | Example |\n * +=====+====================+========================+\n * | 0 | entire string | \"2 2/3\" from \"2 2/3\" |\n * +-----+--------------------+------------------------+\n * | 1 | the dash | \"-\" from \"-2 2/3\" |\n * +-----+--------------------+------------------------+\n * | 2 | the whole number | \"2\" from \"2 2/3\" |\n * | | - OR - | |\n * | | the numerator | \"2\" from \"2/3\" |\n * +-----+--------------------+------------------------+\n * | 3 | entire fraction | \"2/3\" from \"2 2/3\" |\n * | | - OR - | |\n * | | decimal portion | \".66\" from \"2.66\" |\n * | | - OR - | |\n * | | denominator | \"/3\" from \"2/3\" |\n * +=====+====================+========================+\n *\n * re.exec(\"1\") // [ \"1\", \"1\", null, null ]\n * re.exec(\"1.23\") // [ \"1.23\", \"1\", \".23\", null ]\n * re.exec(\"1 2/3\") // [ \"1 2/3\", \"1\", \" 2/3\", \" 2\" ]\n * re.exec(\"2/3\") // [ \"2/3\", \"2\", \"/3\", null ]\n * re.exec(\"2 / 3\") // [ \"2 / 3\", \"2\", \"/ 3\", null ]\n */\n const re = /^(-)?\\s*(\\d*)(\\.\\d+|(\\s+\\d*\\s*)?\\s*\\/\\s*\\d+)?$/;\n\n const ar = re.exec(sQty);\n\n // If the regex fails, give up\n if (!ar) {\n return badResult;\n }\n\n // Store the capture groups so we don't have to access the array\n // elements over and over\n const [, dash, numberGroup1, numberGroup2] = ar;\n\n // The regex can pass and still capture nothing in the relevant groups,\n // which means it failed for our purposes\n if (!numberGroup1 && !numberGroup2) {\n return badResult;\n }\n\n // Numerify capture group 1\n if (!numberGroup1 && numberGroup2 && numberGroup2.search(/^\\./) !== -1) {\n finalResult = 0;\n } else {\n finalResult = parseInt(numberGroup1);\n }\n\n if (isNaN(finalResult)) {\n return badResult;\n }\n\n // If capture group 2 is null, then we're dealing with an integer\n // and there is nothing left to process\n if (!numberGroup2) {\n return finalResult * (dash === '-' ? -1 : 1);\n }\n\n if (numberGroup2.search(/^\\./) !== -1) {\n // If first char is \".\" it's a decimal so just trim to 3 decimal places\n const numerator = parseFloat(numberGroup2);\n finalResult += Math.round(numerator * 1000) / 1000;\n } else if (numberGroup2.search(/^\\s*\\//) !== -1) {\n // If the first non-space char is \"/\" it's a pure fraction (e.g. \"1/2\")\n const numerator = parseInt(numberGroup1);\n const denominator = parseInt(numberGroup2.replace('/', ''));\n finalResult = Math.round((numerator * 1000) / denominator) / 1000;\n } else {\n // Otherwise it's a mixed fraction (e.g. \"1 2/3\")\n const fractionArray = numberGroup2.split('/');\n const [numerator, denominator] = fractionArray.map(v => parseInt(v));\n finalResult += Math.round((numerator * 1000) / denominator) / 1000;\n }\n\n return finalResult * (dash === '-' ? -1 : 1);\n}\n\nexport default numericQuantity;\n"],"names":["VulgarFraction","qty","finalResult","NaN","sQty","replace","_m","vf","trim","ar","exec","dash","numberGroup1","numberGroup2","search","parseInt","isNaN","numerator","parseFloat","Math","round","denominator","split","map","v"],"mappings":"yFAAA,IAAKA,GAAL,SAAKA,GACHA,aACAA,aACAA,aACAA,aACAA,aACAA,cACAA,aACAA,aACAA,aACAA,aACAA,aACAA,aACAA,aACAA,aACAA,aACAA,aACAA,aACAA,aAlBF,CAAKA,IAAAA,oBAyBL,SAAyBC,OAEnBC,EADcC,IAMZC,MAAUH,GACbI,QAH0B,yCAKzB,SAACC,EAAIC,aAAwCP,EAAeO,MAE7DF,QAAQ,KAAM,KACdG,OA+BGC,EAFK,iDAEGC,KAAKN,OAGdK,SA9CaN,QAoDTQ,EAAoCF,KAA9BG,EAA8BH,KAAhBI,EAAgBJ,SAIxCG,IAAiBC,SAxDJV,OA8DhBD,GADGU,GAAgBC,IAAgD,IAAhCA,EAAaC,OAAO,OACzC,EAEAC,SAASH,GAGrBI,MAAMd,UAnEQC,QAyEbU,SACIX,GAAwB,MAATS,GAAgB,EAAI,OAGR,IAAhCE,EAAaC,OAAO,OAAe,KAE/BG,EAAYC,WAAWL,GAC7BX,GAAeiB,KAAKC,MAAkB,IAAZH,GAAoB,SACzC,IAAuC,IAAnCJ,EAAaC,OAAO,UAAkB,KAEzCG,EAAYF,SAASH,GACrBS,EAAcN,SAASF,EAAaR,QAAQ,IAAK,KACvDH,EAAciB,KAAKC,MAAmB,IAAZH,EAAoBI,GAAe,QACxD,OAEiBR,EAAaS,MAAM,KACMC,KAAI,SAAAC,UAAKT,SAASS,MACjEtB,GAAeiB,KAAKC,MAAmB,eAAuB,WAGzDlB,GAAwB,MAATS,GAAgB,EAAI"}
@@ -1,135 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
3
- typeof define === 'function' && define.amd ? define(factory) :
4
- (global = global || self, global.numericQuantity = factory());
5
- }(this, (function () { 'use strict';
6
-
7
- var VulgarFraction;
8
-
9
- (function (VulgarFraction) {
10
- VulgarFraction["\xBC"] = "1/4";
11
- VulgarFraction["\xBD"] = "1/2";
12
- VulgarFraction["\xBE"] = "3/4";
13
- VulgarFraction["\u2150"] = "1/7";
14
- VulgarFraction["\u2151"] = "1/9";
15
- VulgarFraction["\u2152"] = "1/10";
16
- VulgarFraction["\u2153"] = "1/3";
17
- VulgarFraction["\u2154"] = "2/3";
18
- VulgarFraction["\u2155"] = "1/5";
19
- VulgarFraction["\u2156"] = "2/5";
20
- VulgarFraction["\u2157"] = "3/5";
21
- VulgarFraction["\u2158"] = "4/5";
22
- VulgarFraction["\u2159"] = "1/6";
23
- VulgarFraction["\u215A"] = "5/6";
24
- VulgarFraction["\u215B"] = "1/8";
25
- VulgarFraction["\u215C"] = "3/8";
26
- VulgarFraction["\u215D"] = "5/8";
27
- VulgarFraction["\u215E"] = "7/8";
28
- })(VulgarFraction || (VulgarFraction = {}));
29
- /**
30
- * Converts a string to a number. The string can include mixed numbers
31
- * or vulgar fractions.
32
- */
33
-
34
-
35
- function numericQuantity(qty) {
36
- var badResult = NaN;
37
- var finalResult = badResult; // Resolve any unicode vulgar fractions
38
-
39
- var vulgarFractionsRegex = /(¼|½|¾|⅐|⅑|⅒|⅓|⅔|⅕|⅖|⅗|⅘|⅙|⅚|⅛|⅜|⅝|⅞)/;
40
- var sQty = ("" + qty).replace(vulgarFractionsRegex, function (_m, vf) {
41
- return " " + VulgarFraction[vf];
42
- }).replace(/⁄/g, '/').trim();
43
- /**
44
- * Regex captures
45
- *
46
- * +=====+====================+========================+
47
- * | # | Description | Example |
48
- * +=====+====================+========================+
49
- * | 0 | entire string | "2 2/3" from "2 2/3" |
50
- * +-----+--------------------+------------------------+
51
- * | 1 | the dash | "-" from "-2 2/3" |
52
- * +-----+--------------------+------------------------+
53
- * | 2 | the whole number | "2" from "2 2/3" |
54
- * | | - OR - | |
55
- * | | the numerator | "2" from "2/3" |
56
- * +-----+--------------------+------------------------+
57
- * | 3 | entire fraction | "2/3" from "2 2/3" |
58
- * | | - OR - | |
59
- * | | decimal portion | ".66" from "2.66" |
60
- * | | - OR - | |
61
- * | | denominator | "/3" from "2/3" |
62
- * +=====+====================+========================+
63
- *
64
- * re.exec("1") // [ "1", "1", null, null ]
65
- * re.exec("1.23") // [ "1.23", "1", ".23", null ]
66
- * re.exec("1 2/3") // [ "1 2/3", "1", " 2/3", " 2" ]
67
- * re.exec("2/3") // [ "2/3", "2", "/3", null ]
68
- * re.exec("2 / 3") // [ "2 / 3", "2", "/ 3", null ]
69
- */
70
-
71
- var re = /^(-)?\s*(\d*)(\.\d+|(\s+\d*\s*)?\s*\/\s*\d+)?$/;
72
- var ar = re.exec(sQty); // If the regex fails, give up
73
-
74
- if (!ar) {
75
- return badResult;
76
- } // Store the capture groups so we don't have to access the array
77
- // elements over and over
78
-
79
-
80
- var dash = ar[1],
81
- numberGroup1 = ar[2],
82
- numberGroup2 = ar[3]; // The regex can pass and still capture nothing in the relevant groups,
83
- // which means it failed for our purposes
84
-
85
- if (!numberGroup1 && !numberGroup2) {
86
- return badResult;
87
- } // Numerify capture group 1
88
-
89
-
90
- if (!numberGroup1 && numberGroup2 && numberGroup2.search(/^\./) !== -1) {
91
- finalResult = 0;
92
- } else {
93
- finalResult = parseInt(numberGroup1);
94
- }
95
-
96
- if (isNaN(finalResult)) {
97
- return badResult;
98
- } // If capture group 2 is null, then we're dealing with an integer
99
- // and there is nothing left to process
100
-
101
-
102
- if (!numberGroup2) {
103
- return finalResult * (dash === '-' ? -1 : 1);
104
- }
105
-
106
- if (numberGroup2.search(/^\./) !== -1) {
107
- // If first char is "." it's a decimal so just trim to 3 decimal places
108
- var numerator = parseFloat(numberGroup2);
109
- finalResult += Math.round(numerator * 1000) / 1000;
110
- } else if (numberGroup2.search(/^\s*\//) !== -1) {
111
- // If the first non-space char is "/" it's a pure fraction (e.g. "1/2")
112
- var _numerator = parseInt(numberGroup1);
113
-
114
- var denominator = parseInt(numberGroup2.replace('/', ''));
115
- finalResult = Math.round(_numerator * 1000 / denominator) / 1000;
116
- } else {
117
- // Otherwise it's a mixed fraction (e.g. "1 2/3")
118
- var fractionArray = numberGroup2.split('/');
119
-
120
- var _fractionArray$map = fractionArray.map(function (v) {
121
- return parseInt(v);
122
- }),
123
- _numerator2 = _fractionArray$map[0],
124
- _denominator = _fractionArray$map[1];
125
-
126
- finalResult += Math.round(_numerator2 * 1000 / _denominator) / 1000;
127
- }
128
-
129
- return finalResult * (dash === '-' ? -1 : 1);
130
- }
131
-
132
- return numericQuantity;
133
-
134
- })));
135
- //# sourceMappingURL=numeric-quantity.umd.development.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"numeric-quantity.umd.development.js","sources":["../src/index.ts"],"sourcesContent":["enum VulgarFraction {\n '¼' = '1/4',\n '½' = '1/2',\n '¾' = '3/4',\n '⅐' = '1/7',\n '⅑' = '1/9',\n '⅒' = '1/10',\n '⅓' = '1/3',\n '⅔' = '2/3',\n '⅕' = '1/5',\n '⅖' = '2/5',\n '⅗' = '3/5',\n '⅘' = '4/5',\n '⅙' = '1/6',\n '⅚' = '5/6',\n '⅛' = '1/8',\n '⅜' = '3/8',\n '⅝' = '5/8',\n '⅞' = '7/8',\n}\n\n/**\n * Converts a string to a number. The string can include mixed numbers\n * or vulgar fractions.\n */\nfunction numericQuantity(qty: string) {\n const badResult = NaN;\n let finalResult = badResult;\n\n // Resolve any unicode vulgar fractions\n const vulgarFractionsRegex = /(¼|½|¾|⅐|⅑|⅒|⅓|⅔|⅕|⅖|⅗|⅘|⅙|⅚|⅛|⅜|⅝|⅞)/;\n\n const sQty = `${qty}`\n .replace(\n vulgarFractionsRegex,\n (_m, vf: keyof typeof VulgarFraction) => ` ${VulgarFraction[vf]}`\n )\n .replace(/⁄/g, '/')\n .trim();\n\n /**\n * Regex captures\n *\n * +=====+====================+========================+\n * | # | Description | Example |\n * +=====+====================+========================+\n * | 0 | entire string | \"2 2/3\" from \"2 2/3\" |\n * +-----+--------------------+------------------------+\n * | 1 | the dash | \"-\" from \"-2 2/3\" |\n * +-----+--------------------+------------------------+\n * | 2 | the whole number | \"2\" from \"2 2/3\" |\n * | | - OR - | |\n * | | the numerator | \"2\" from \"2/3\" |\n * +-----+--------------------+------------------------+\n * | 3 | entire fraction | \"2/3\" from \"2 2/3\" |\n * | | - OR - | |\n * | | decimal portion | \".66\" from \"2.66\" |\n * | | - OR - | |\n * | | denominator | \"/3\" from \"2/3\" |\n * +=====+====================+========================+\n *\n * re.exec(\"1\") // [ \"1\", \"1\", null, null ]\n * re.exec(\"1.23\") // [ \"1.23\", \"1\", \".23\", null ]\n * re.exec(\"1 2/3\") // [ \"1 2/3\", \"1\", \" 2/3\", \" 2\" ]\n * re.exec(\"2/3\") // [ \"2/3\", \"2\", \"/3\", null ]\n * re.exec(\"2 / 3\") // [ \"2 / 3\", \"2\", \"/ 3\", null ]\n */\n const re = /^(-)?\\s*(\\d*)(\\.\\d+|(\\s+\\d*\\s*)?\\s*\\/\\s*\\d+)?$/;\n\n const ar = re.exec(sQty);\n\n // If the regex fails, give up\n if (!ar) {\n return badResult;\n }\n\n // Store the capture groups so we don't have to access the array\n // elements over and over\n const [, dash, numberGroup1, numberGroup2] = ar;\n\n // The regex can pass and still capture nothing in the relevant groups,\n // which means it failed for our purposes\n if (!numberGroup1 && !numberGroup2) {\n return badResult;\n }\n\n // Numerify capture group 1\n if (!numberGroup1 && numberGroup2 && numberGroup2.search(/^\\./) !== -1) {\n finalResult = 0;\n } else {\n finalResult = parseInt(numberGroup1);\n }\n\n if (isNaN(finalResult)) {\n return badResult;\n }\n\n // If capture group 2 is null, then we're dealing with an integer\n // and there is nothing left to process\n if (!numberGroup2) {\n return finalResult * (dash === '-' ? -1 : 1);\n }\n\n if (numberGroup2.search(/^\\./) !== -1) {\n // If first char is \".\" it's a decimal so just trim to 3 decimal places\n const numerator = parseFloat(numberGroup2);\n finalResult += Math.round(numerator * 1000) / 1000;\n } else if (numberGroup2.search(/^\\s*\\//) !== -1) {\n // If the first non-space char is \"/\" it's a pure fraction (e.g. \"1/2\")\n const numerator = parseInt(numberGroup1);\n const denominator = parseInt(numberGroup2.replace('/', ''));\n finalResult = Math.round((numerator * 1000) / denominator) / 1000;\n } else {\n // Otherwise it's a mixed fraction (e.g. \"1 2/3\")\n const fractionArray = numberGroup2.split('/');\n const [numerator, denominator] = fractionArray.map(v => parseInt(v));\n finalResult += Math.round((numerator * 1000) / denominator) / 1000;\n }\n\n return finalResult * (dash === '-' ? -1 : 1);\n}\n\nexport default numericQuantity;\n"],"names":["VulgarFraction","numericQuantity","qty","badResult","NaN","finalResult","vulgarFractionsRegex","sQty","replace","_m","vf","trim","re","ar","exec","dash","numberGroup1","numberGroup2","search","parseInt","isNaN","numerator","parseFloat","Math","round","denominator","fractionArray","split","map","v"],"mappings":";;;;;;EAAA,IAAKA,cAAL;;EAAA,WAAKA;EACHA,EAAAA,sBAAA,QAAA;EACAA,EAAAA,sBAAA,QAAA;EACAA,EAAAA,sBAAA,QAAA;EACAA,EAAAA,wBAAA,QAAA;EACAA,EAAAA,wBAAA,QAAA;EACAA,EAAAA,wBAAA,SAAA;EACAA,EAAAA,wBAAA,QAAA;EACAA,EAAAA,wBAAA,QAAA;EACAA,EAAAA,wBAAA,QAAA;EACAA,EAAAA,wBAAA,QAAA;EACAA,EAAAA,wBAAA,QAAA;EACAA,EAAAA,wBAAA,QAAA;EACAA,EAAAA,wBAAA,QAAA;EACAA,EAAAA,wBAAA,QAAA;EACAA,EAAAA,wBAAA,QAAA;EACAA,EAAAA,wBAAA,QAAA;EACAA,EAAAA,wBAAA,QAAA;EACAA,EAAAA,wBAAA,QAAA;EACD,CAnBD,EAAKA,cAAc,KAAdA,cAAc,KAAA,CAAnB;EAqBA;;;;;;EAIA,SAASC,eAAT,CAAyBC,GAAzB;EACE,MAAMC,SAAS,GAAGC,GAAlB;EACA,MAAIC,WAAW,GAAGF,SAAlB;;EAGA,MAAMG,o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AApB,MAAkC,CAAC,CAAvC,EAA0C;EAC/C;EACA,QAAMG,UAAS,GAAGF,QAAQ,CAACH,YAAD,CAA1B;;EACA,QAAMS,WAAW,GAAGN,QAAQ,CAACF,YAAY,CAACT,OAAb,CAAqB,GAArB,EAA0B,EAA1B,CAAD,CAA5B;EACAH,IAAAA,WAAW,GAAGkB,IAAI,CAACC,KAAL,CAAYH,UAAS,GAAG,IAAb,GAAqBI,WAAhC,IAA+C,IAA7D;EACD,GALM,MAKA;EACL;EACA,QAAMC,aAAa,GAAGT,YAAY,CAACU,KAAb,CAAmB,GAAnB,CAAtB;;EAFK,6BAG4BD,aAAa,CAACE,GAAd,CAAkB,UAAAC,CAAC;EAAA,aAAIV,QAAQ,CAACU,CAAD,CAAZ;EAAA,KAAnB,CAH5B;EAAA,QAGER,WAHF;EAAA,QAGaI,YAHb;;EAILpB,IAAAA,WAAW,IAAIkB,IAAI,CAACC,KAAL,CAAYH,WAAS,GAAG,IAAb,GAAqBI,YAAhC,IAA+C,IAA9D;EACD;;EAED,SAAOpB,WAAW,IAAIU,IAAI,KAAK,GAAT,GAAe,CAAC,CAAhB,GAAoB,CAAxB,CAAlB;EACD;;;;;;;;"}
@@ -1,2 +0,0 @@
1
- !function(e,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(e=e||self).numericQuantity=r()}(this,(function(){"use strict";var e;return function(e){e["¼"]="1/4",e["½"]="1/2",e["¾"]="3/4",e["⅐"]="1/7",e["⅑"]="1/9",e["⅒"]="1/10",e["⅓"]="1/3",e["⅔"]="2/3",e["⅕"]="1/5",e["⅖"]="2/5",e["⅗"]="3/5",e["⅘"]="4/5",e["⅙"]="1/6",e["⅚"]="5/6",e["⅛"]="1/8",e["⅜"]="3/8",e["⅝"]="5/8",e["⅞"]="7/8"}(e||(e={})),function(r){var n=NaN,t=(""+r).replace(/(¼|½|¾|⅐|⅑|⅒|⅓|⅔|⅕|⅖|⅗|⅘|⅙|⅚|⅛|⅜|⅝|⅞)/,(function(r,n){return" "+e[n]})).replace(/⁄/g,"/").trim(),a=/^(-)?\s*(\d*)(\.\d+|(\s+\d*\s*)?\s*\/\s*\d+)?$/.exec(t);if(!a)return NaN;var i=a[1],s=a[2],u=a[3];if(!s&&!u)return NaN;if(n=!s&&u&&-1!==u.search(/^\./)?0:parseInt(s),isNaN(n))return NaN;if(!u)return n*("-"===i?-1:1);if(-1!==u.search(/^\./)){var f=parseFloat(u);n+=Math.round(1e3*f)/1e3}else if(-1!==u.search(/^\s*\//)){var o=parseInt(s),c=parseInt(u.replace("/",""));n=Math.round(1e3*o/c)/1e3}else{var d=u.split("/").map((function(e){return parseInt(e)}));n+=Math.round(1e3*d[0]/d[1])/1e3}return n*("-"===i?-1:1)}}));
2
- //# sourceMappingURL=numeric-quantity.umd.production.min.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"numeric-quantity.umd.production.min.js","sources":["../src/index.ts"],"sourcesContent":["enum VulgarFraction {\n '¼' = '1/4',\n '½' = '1/2',\n '¾' = '3/4',\n '⅐' = '1/7',\n '⅑' = '1/9',\n '⅒' = '1/10',\n '⅓' = '1/3',\n '⅔' = '2/3',\n '⅕' = '1/5',\n '⅖' = '2/5',\n '⅗' = '3/5',\n '⅘' = '4/5',\n '⅙' = '1/6',\n '⅚' = '5/6',\n '⅛' = '1/8',\n '⅜' = '3/8',\n '⅝' = '5/8',\n '⅞' = '7/8',\n}\n\n/**\n * Converts a string to a number. The string can include mixed numbers\n * or vulgar fractions.\n */\nfunction numericQuantity(qty: string) {\n const badResult = NaN;\n let finalResult = badResult;\n\n // Resolve any unicode vulgar fractions\n const vulgarFractionsRegex = /(¼|½|¾|⅐|⅑|⅒|⅓|⅔|⅕|⅖|⅗|⅘|⅙|⅚|⅛|⅜|⅝|⅞)/;\n\n const sQty = `${qty}`\n .replace(\n vulgarFractionsRegex,\n (_m, vf: keyof typeof VulgarFraction) => ` ${VulgarFraction[vf]}`\n )\n .replace(/⁄/g, '/')\n .trim();\n\n /**\n * Regex captures\n *\n * +=====+====================+========================+\n * | # | Description | Example |\n * +=====+====================+========================+\n * | 0 | entire string | \"2 2/3\" from \"2 2/3\" |\n * +-----+--------------------+------------------------+\n * | 1 | the dash | \"-\" from \"-2 2/3\" |\n * +-----+--------------------+------------------------+\n * | 2 | the whole number | \"2\" from \"2 2/3\" |\n * | | - OR - | |\n * | | the numerator | \"2\" from \"2/3\" |\n * +-----+--------------------+------------------------+\n * | 3 | entire fraction | \"2/3\" from \"2 2/3\" |\n * | | - OR - | |\n * | | decimal portion | \".66\" from \"2.66\" |\n * | | - OR - | |\n * | | denominator | \"/3\" from \"2/3\" |\n * +=====+====================+========================+\n *\n * re.exec(\"1\") // [ \"1\", \"1\", null, null ]\n * re.exec(\"1.23\") // [ \"1.23\", \"1\", \".23\", null ]\n * re.exec(\"1 2/3\") // [ \"1 2/3\", \"1\", \" 2/3\", \" 2\" ]\n * re.exec(\"2/3\") // [ \"2/3\", \"2\", \"/3\", null ]\n * re.exec(\"2 / 3\") // [ \"2 / 3\", \"2\", \"/ 3\", null ]\n */\n const re = /^(-)?\\s*(\\d*)(\\.\\d+|(\\s+\\d*\\s*)?\\s*\\/\\s*\\d+)?$/;\n\n const ar = re.exec(sQty);\n\n // If the regex fails, give up\n if (!ar) {\n return badResult;\n }\n\n // Store the capture groups so we don't have to access the array\n // elements over and over\n const [, dash, numberGroup1, numberGroup2] = ar;\n\n // The regex can pass and still capture nothing in the relevant groups,\n // which means it failed for our purposes\n if (!numberGroup1 && !numberGroup2) {\n return badResult;\n }\n\n // Numerify capture group 1\n if (!numberGroup1 && numberGroup2 && numberGroup2.search(/^\\./) !== -1) {\n finalResult = 0;\n } else {\n finalResult = parseInt(numberGroup1);\n }\n\n if (isNaN(finalResult)) {\n return badResult;\n }\n\n // If capture group 2 is null, then we're dealing with an integer\n // and there is nothing left to process\n if (!numberGroup2) {\n return finalResult * (dash === '-' ? -1 : 1);\n }\n\n if (numberGroup2.search(/^\\./) !== -1) {\n // If first char is \".\" it's a decimal so just trim to 3 decimal places\n const numerator = parseFloat(numberGroup2);\n finalResult += Math.round(numerator * 1000) / 1000;\n } else if (numberGroup2.search(/^\\s*\\//) !== -1) {\n // If the first non-space char is \"/\" it's a pure fraction (e.g. \"1/2\")\n const numerator = parseInt(numberGroup1);\n const denominator = parseInt(numberGroup2.replace('/', ''));\n finalResult = Math.round((numerator * 1000) / denominator) / 1000;\n } else {\n // Otherwise it's a mixed fraction (e.g. \"1 2/3\")\n const fractionArray = numberGroup2.split('/');\n const [numerator, denominator] = fractionArray.map(v => parseInt(v));\n finalResult += Math.round((numerator * 1000) / denominator) / 1000;\n }\n\n return finalResult * (dash === '-' ? -1 : 1);\n}\n\nexport default numericQuantity;\n"],"names":["VulgarFraction","qty","finalResult","NaN","sQty","replace","_m","vf","trim","ar","exec","dash","numberGroup1","numberGroup2","search","parseInt","isNaN","numerator","parseFloat","Math","round","denominator","split","map","v"],"mappings":"sMAAA,IAAKA,SAAL,SAAKA,GACHA,aACAA,aACAA,aACAA,aACAA,aACAA,cACAA,aACAA,aACAA,aACAA,aACAA,aACAA,aACAA,aACAA,aACAA,aACAA,aACAA,aACAA,aAlBF,CAAKA,IAAAA,OAyBL,SAAyBC,OAEnBC,EADcC,IAMZC,MAAUH,GACbI,QAH0B,yCAKzB,SAACC,EAAIC,aAAwCP,EAAeO,MAE7DF,QAAQ,KAAM,KACdG,OA+BGC,EAFK,iDAEGC,KAAKN,OAGdK,SA9CaN,QAoDTQ,EAAoCF,KAA9BG,EAA8BH,KAAhBI,EAAgBJ,SAIxCG,IAAiBC,SAxDJV,OA8DhBD,GADGU,GAAgBC,IAAgD,IAAhCA,EAAaC,OAAO,OACzC,EAEAC,SAASH,GAGrBI,MAAMd,UAnEQC,QAyEbU,SACIX,GAAwB,MAATS,GAAgB,EAAI,OAGR,IAAhCE,EAAaC,OAAO,OAAe,KAE/BG,EAAYC,WAAWL,GAC7BX,GAAeiB,KAAKC,MAAkB,IAAZH,GAAoB,SACzC,IAAuC,IAAnCJ,EAAaC,OAAO,UAAkB,KAEzCG,EAAYF,SAASH,GACrBS,EAAcN,SAASF,EAAaR,QAAQ,IAAK,KACvDH,EAAciB,KAAKC,MAAmB,IAAZH,EAAoBI,GAAe,QACxD,OAEiBR,EAAaS,MAAM,KACMC,KAAI,SAAAC,UAAKT,SAASS,MACjEtB,GAAeiB,KAAKC,MAAmB,eAAuB,WAGzDlB,GAAwB,MAATS,GAAgB,EAAI"}