format-quantity 1.0.1 → 1.0.2

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/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 1.0.1 (2021-02-15)
2
+
3
+ - Added description to package.json
4
+
1
5
  ## 1.0.0 (2021-02-11)
2
6
 
3
7
  - New build system ([tsdx](https://tsdx.io/))
@@ -0,0 +1,2 @@
1
+ "use strict";const r=(f,e)=>Math.abs(f-e)<.009;function c(f,e){const n=typeof f=="string"?parseFloat(f):f;if(isNaN(n)||n===null)return null;if(n===0)return"";const s=Math.abs(n),o=Math.floor(s),u=o===0?"":`${n<0?"-":""}${o} `,t=s-o;if(t===0)return`${n}`;const $=e?u.trim():u;if(r(t,.33))return`${$}${e?"\u2153":"1/3"}`;if(r(t,.66))return`${$}${e?"\u2154":"2/3"}`;if(r(t,.2))return`${$}${e?"\u2155":"1/5"}`;if(r(t,.4))return`${$}${e?"\u2156":"2/5"}`;if(r(t,.6))return`${$}${e?"\u2157":"3/5"}`;if(r(t,.8))return`${$}${e?"\u2158":"4/5"}`;switch(t){case .125:return`${$}${e?"\u215B":"1/8"}`;case .25:return`${$}${e?"\xBC":"1/4"}`;case .375:return`${$}${e?"\u215C":"3/8"}`;case .5:return`${$}${e?"\xBD":"1/2"}`;case .625:return`${$}${e?"\u215D":"5/8"}`;case .75:return`${$}${e?"\xBE":"3/4"}`;case .875:return`${$}${e?"\u215E":"7/8"}`}return`${n}`}module.exports=c;
2
+ //# sourceMappingURL=format-quantity.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"format-quantity.esm.js","sources":["../src/index.ts"],"sourcesContent":["/**\n * Determines if two numbers are close enough to consider\n * them equal for our purposes\n */\nconst closeEnough = (a: number, b: number) => Math.abs(a - b) < 0.009;\n\n/**\n * Formats a number (or string that appears to be a number)\n * as one would see it written in imperial measurements, e.g.\n * \"1 1/2\" instead of \"1.5\". To use vulgar fractions, e.g. \"½\",\n * pass `true` as the second argument.\n */\nfunction formatQuantity(qty: string | number, useVulgarFractions?: boolean) {\n const dQty = typeof qty === 'string' ? parseFloat(qty) : qty;\n\n // Bomb out if not a number\n if (isNaN(dQty) || dQty === null) {\n return null;\n }\n\n // Return an empty string if the value is zero\n if (dQty === 0) {\n return '';\n }\n\n const dQtyAbs = Math.abs(dQty);\n const iFloor = Math.floor(dQtyAbs);\n const sFloor = iFloor === 0.0 ? '' : `${dQty < 0 ? '-' : ''}${iFloor} `;\n const dDecimal = dQtyAbs - iFloor;\n\n // Handle integers first. Just return the given value as a string.\n if (dDecimal === 0) {\n return `${dQty}`;\n }\n\n const sFloorFinal = useVulgarFractions ? sFloor.trim() : sFloor;\n\n // Handle infinitely repeating decimals next, since\n // we'll never get an exact match for a switch case:\n if (closeEnough(dDecimal, 0.33)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅓' : '1/3'}`;\n } else if (closeEnough(dDecimal, 0.66)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅔' : '2/3'}`;\n } else if (closeEnough(dDecimal, 0.2)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅕' : '1/5'}`;\n } else if (closeEnough(dDecimal, 0.4)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅖' : '2/5'}`;\n } else if (closeEnough(dDecimal, 0.6)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅗' : '3/5'}`;\n } else if (closeEnough(dDecimal, 0.8)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅘' : '4/5'}`;\n } else {\n switch (dDecimal) {\n case 0.125:\n return `${sFloorFinal}${useVulgarFractions ? '⅛' : '1/8'}`;\n case 0.25:\n return `${sFloorFinal}${useVulgarFractions ? '¼' : '1/4'}`;\n case 0.375:\n return `${sFloorFinal}${useVulgarFractions ? '⅜' : '3/8'}`;\n case 0.5:\n return `${sFloorFinal}${useVulgarFractions ? '½' : '1/2'}`;\n case 0.625:\n return `${sFloorFinal}${useVulgarFractions ? '⅝' : '5/8'}`;\n case 0.75:\n return `${sFloorFinal}${useVulgarFractions ? '¾' : '3/4'}`;\n case 0.875:\n return `${sFloorFinal}${useVulgarFractions ? '⅞' : '7/8'}`;\n }\n }\n\n return `${dQty}`;\n}\n\nexport default formatQuantity;\n"],"names":["closeEnough","a","b","Math","abs","formatQuantity","qty","useVulgarFractions","dQty","parseFloat","isNaN","dQtyAbs","iFloor","floor","sFloor","dDecimal","sFloorFinal","trim"],"mappings":"AAAA;;;;AAIA,IAAMA,WAAW,GAAG,SAAdA,WAAc,CAACC,CAAD,EAAYC,CAAZ;AAAA,SAA0BC,IAAI,CAACC,GAAL,CAASH,CAAC,GAAGC,CAAb,IAAkB,KAA5C;AAAA,CAApB;AAEA;;;;;;;;AAMA,SAASG,cAAT,CAAwBC,GAAxB,EAA8CC,kBAA9C;AACE,MAAMC,IAAI,GAAG,OAAOF,GAAP,KAAe,QAAf,GAA0BG,UAAU,CAACH,GAAD,CAApC,GAA4CA,GAAzD;;AAGA,MAAII,KAAK,CAACF,IAAD,CAAL,IAAeA,IAAI,KAAK,IAA5B,EAAkC;AAChC,WAAO,IAAP;AACD;;;AAGD,MAAIA,IAAI,KAAK,CAAb,EAAgB;AACd,WAAO,EAAP;AACD;;AAED,MAAMG,OAAO,GAAGR,IAAI,CAACC,GAAL,CAASI,IAAT,CAAhB;AACA,MAAMI,MAAM,GAAGT,IAAI,CAACU,KAAL,CAAWF,OAAX,CAAf;AACA,MAAMG,MAAM,GAAGF,MAAM,KAAK,GAAX,GAAiB,EAAjB,SAAyBJ,IAAI,GAAG,CAAP,GAAW,GAAX,GAAiB,EAA1C,IAA+CI,MAA/C,MAAf;AACA,MAAMG,QAAQ,GAAGJ,OAAO,GAAGC,MAA3B;;AAGA,MAAIG,QAAQ,KAAK,CAAjB,EAAoB;AAClB,gBAAUP,IAAV;AACD;;AAED,MAAMQ,WAAW,GAAGT,kBAAkB,GAAGO,MAAM,CAACG,IAAP,EAAH,GAAmBH,MAAzD;AAGA;;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AAV,IAAwBT,kBAAkB,GAAG,GAAH,GAAS,KAAnD;;AACF,WAAK,KAAL;AACE,oBAAUS,WAAV,IAAwBT,kBAAkB,GAAG,GAAH,GAAS,KAAnD;AAdJ;AAgBD;;AAED,cAAUC,IAAV;AACD;;;;"}
1
+ {"version":3,"file":"format-quantity.cjs.js","sources":["../src/index.ts"],"sourcesContent":["/**\n * Determines if two numbers are close enough to consider\n * them equal for our purposes\n */\nconst closeEnough = (a: number, b: number) => Math.abs(a - b) < 0.009;\n\n/**\n * Formats a number (or string that appears to be a number)\n * as one would see it written in imperial measurements, e.g.\n * \"1 1/2\" instead of \"1.5\". To use vulgar fractions, e.g. \"½\",\n * pass `true` as the second argument.\n */\nfunction formatQuantity(qty: string | number, useVulgarFractions?: boolean) {\n const dQty = typeof qty === 'string' ? parseFloat(qty) : qty;\n\n // Bomb out if not a number\n if (isNaN(dQty) || dQty === null) {\n return null;\n }\n\n // Return an empty string if the value is zero\n if (dQty === 0) {\n return '';\n }\n\n const dQtyAbs = Math.abs(dQty);\n const iFloor = Math.floor(dQtyAbs);\n const sFloor = iFloor === 0.0 ? '' : `${dQty < 0 ? '-' : ''}${iFloor} `;\n const dDecimal = dQtyAbs - iFloor;\n\n // Handle integers first. Just return the given value as a string.\n if (dDecimal === 0) {\n return `${dQty}`;\n }\n\n const sFloorFinal = useVulgarFractions ? sFloor.trim() : sFloor;\n\n // Handle infinitely repeating decimals next, since\n // we'll never get an exact match for a switch case:\n if (closeEnough(dDecimal, 0.33)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅓' : '1/3'}`;\n } else if (closeEnough(dDecimal, 0.66)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅔' : '2/3'}`;\n } else if (closeEnough(dDecimal, 0.2)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅕' : '1/5'}`;\n } else if (closeEnough(dDecimal, 0.4)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅖' : '2/5'}`;\n } else if (closeEnough(dDecimal, 0.6)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅗' : '3/5'}`;\n } else if (closeEnough(dDecimal, 0.8)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅘' : '4/5'}`;\n } else {\n switch (dDecimal) {\n case 0.125:\n return `${sFloorFinal}${useVulgarFractions ? '⅛' : '1/8'}`;\n case 0.25:\n return `${sFloorFinal}${useVulgarFractions ? '¼' : '1/4'}`;\n case 0.375:\n return `${sFloorFinal}${useVulgarFractions ? '⅜' : '3/8'}`;\n case 0.5:\n return `${sFloorFinal}${useVulgarFractions ? '½' : '1/2'}`;\n case 0.625:\n return `${sFloorFinal}${useVulgarFractions ? '⅝' : '5/8'}`;\n case 0.75:\n return `${sFloorFinal}${useVulgarFractions ? '¾' : '3/4'}`;\n case 0.875:\n return `${sFloorFinal}${useVulgarFractions ? '⅞' : '7/8'}`;\n }\n }\n\n return `${dQty}`;\n}\n\nexport default formatQuantity;\n"],"names":[],"mappings":"aAIA,KAAM,GAAc,CAAC,EAAW,IAAc,KAAK,IAAI,EAAI,CAAC,EAAI,KAQhE,WAAwB,EAAsB,EAA8B,CAC1E,KAAM,GAAO,MAAO,IAAQ,SAAW,WAAW,CAAG,EAAI,EAGzD,GAAI,MAAM,CAAI,GAAK,IAAS,KACnB,MAAA,MAIT,GAAI,IAAS,EACJ,MAAA,GAGH,KAAA,GAAU,KAAK,IAAI,CAAI,EACvB,EAAS,KAAK,MAAM,CAAO,EAC3B,EAAS,IAAW,EAAM,GAAK,GAAG,EAAO,EAAI,IAAM,KAAK,KACxD,EAAW,EAAU,EAG3B,GAAI,IAAa,EACf,MAAO,GAAG,IAGZ,KAAM,GAAc,EAAqB,EAAO,KAAA,EAAS,EAIrD,GAAA,EAAY,EAAU,GAAI,EACrB,MAAA,GAAG,IAAc,EAAqB,SAAM,QAC1C,GAAA,EAAY,EAAU,GAAI,EAC5B,MAAA,GAAG,IAAc,EAAqB,SAAM,QAC1C,GAAA,EAAY,EAAU,EAAG,EAC3B,MAAA,GAAG,IAAc,EAAqB,SAAM,QAC1C,GAAA,EAAY,EAAU,EAAG,EAC3B,MAAA,GAAG,IAAc,EAAqB,SAAM,QAC1C,GAAA,EAAY,EAAU,EAAG,EAC3B,MAAA,GAAG,IAAc,EAAqB,SAAM,QAC1C,GAAA,EAAY,EAAU,EAAG,EAC3B,MAAA,GAAG,IAAc,EAAqB,SAAM,QAE3C,OAAA,OACD,MACI,MAAA,GAAG,IAAc,EAAqB,SAAM,YAChD,KACI,MAAA,GAAG,IAAc,EAAqB,OAAM,YAChD,MACI,MAAA,GAAG,IAAc,EAAqB,SAAM,YAChD,IACI,MAAA,GAAG,IAAc,EAAqB,OAAM,YAChD,MACI,MAAA,GAAG,IAAc,EAAqB,SAAM,YAChD,KACI,MAAA,GAAG,IAAc,EAAqB,OAAM,YAChD,MACI,MAAA,GAAG,IAAc,EAAqB,SAAM,QAIzD,MAAO,GAAG,GACZ"}
@@ -0,0 +1,51 @@
1
+ const closeEnough = (a, b) => Math.abs(a - b) < 9e-3;
2
+ function formatQuantity(qty, useVulgarFractions) {
3
+ const dQty = typeof qty === "string" ? parseFloat(qty) : qty;
4
+ if (isNaN(dQty) || dQty === null) {
5
+ return null;
6
+ }
7
+ if (dQty === 0) {
8
+ return "";
9
+ }
10
+ const dQtyAbs = Math.abs(dQty);
11
+ const iFloor = Math.floor(dQtyAbs);
12
+ const sFloor = iFloor === 0 ? "" : `${dQty < 0 ? "-" : ""}${iFloor} `;
13
+ const dDecimal = dQtyAbs - iFloor;
14
+ if (dDecimal === 0) {
15
+ return `${dQty}`;
16
+ }
17
+ const sFloorFinal = useVulgarFractions ? sFloor.trim() : sFloor;
18
+ if (closeEnough(dDecimal, 0.33)) {
19
+ return `${sFloorFinal}${useVulgarFractions ? "\u2153" : "1/3"}`;
20
+ } else if (closeEnough(dDecimal, 0.66)) {
21
+ return `${sFloorFinal}${useVulgarFractions ? "\u2154" : "2/3"}`;
22
+ } else if (closeEnough(dDecimal, 0.2)) {
23
+ return `${sFloorFinal}${useVulgarFractions ? "\u2155" : "1/5"}`;
24
+ } else if (closeEnough(dDecimal, 0.4)) {
25
+ return `${sFloorFinal}${useVulgarFractions ? "\u2156" : "2/5"}`;
26
+ } else if (closeEnough(dDecimal, 0.6)) {
27
+ return `${sFloorFinal}${useVulgarFractions ? "\u2157" : "3/5"}`;
28
+ } else if (closeEnough(dDecimal, 0.8)) {
29
+ return `${sFloorFinal}${useVulgarFractions ? "\u2158" : "4/5"}`;
30
+ } else {
31
+ switch (dDecimal) {
32
+ case 0.125:
33
+ return `${sFloorFinal}${useVulgarFractions ? "\u215B" : "1/8"}`;
34
+ case 0.25:
35
+ return `${sFloorFinal}${useVulgarFractions ? "\xBC" : "1/4"}`;
36
+ case 0.375:
37
+ return `${sFloorFinal}${useVulgarFractions ? "\u215C" : "3/8"}`;
38
+ case 0.5:
39
+ return `${sFloorFinal}${useVulgarFractions ? "\xBD" : "1/2"}`;
40
+ case 0.625:
41
+ return `${sFloorFinal}${useVulgarFractions ? "\u215D" : "5/8"}`;
42
+ case 0.75:
43
+ return `${sFloorFinal}${useVulgarFractions ? "\xBE" : "3/4"}`;
44
+ case 0.875:
45
+ return `${sFloorFinal}${useVulgarFractions ? "\u215E" : "7/8"}`;
46
+ }
47
+ }
48
+ return `${dQty}`;
49
+ }
50
+ export { formatQuantity as default };
51
+ //# sourceMappingURL=format-quantity.es.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format-quantity.es.js","sources":["../src/index.ts"],"sourcesContent":["/**\n * Determines if two numbers are close enough to consider\n * them equal for our purposes\n */\nconst closeEnough = (a: number, b: number) => Math.abs(a - b) < 0.009;\n\n/**\n * Formats a number (or string that appears to be a number)\n * as one would see it written in imperial measurements, e.g.\n * \"1 1/2\" instead of \"1.5\". To use vulgar fractions, e.g. \"½\",\n * pass `true` as the second argument.\n */\nfunction formatQuantity(qty: string | number, useVulgarFractions?: boolean) {\n const dQty = typeof qty === 'string' ? parseFloat(qty) : qty;\n\n // Bomb out if not a number\n if (isNaN(dQty) || dQty === null) {\n return null;\n }\n\n // Return an empty string if the value is zero\n if (dQty === 0) {\n return '';\n }\n\n const dQtyAbs = Math.abs(dQty);\n const iFloor = Math.floor(dQtyAbs);\n const sFloor = iFloor === 0.0 ? '' : `${dQty < 0 ? '-' : ''}${iFloor} `;\n const dDecimal = dQtyAbs - iFloor;\n\n // Handle integers first. Just return the given value as a string.\n if (dDecimal === 0) {\n return `${dQty}`;\n }\n\n const sFloorFinal = useVulgarFractions ? sFloor.trim() : sFloor;\n\n // Handle infinitely repeating decimals next, since\n // we'll never get an exact match for a switch case:\n if (closeEnough(dDecimal, 0.33)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅓' : '1/3'}`;\n } else if (closeEnough(dDecimal, 0.66)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅔' : '2/3'}`;\n } else if (closeEnough(dDecimal, 0.2)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅕' : '1/5'}`;\n } else if (closeEnough(dDecimal, 0.4)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅖' : '2/5'}`;\n } else if (closeEnough(dDecimal, 0.6)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅗' : '3/5'}`;\n } else if (closeEnough(dDecimal, 0.8)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅘' : '4/5'}`;\n } else {\n switch (dDecimal) {\n case 0.125:\n return `${sFloorFinal}${useVulgarFractions ? '⅛' : '1/8'}`;\n case 0.25:\n return `${sFloorFinal}${useVulgarFractions ? '¼' : '1/4'}`;\n case 0.375:\n return `${sFloorFinal}${useVulgarFractions ? '⅜' : '3/8'}`;\n case 0.5:\n return `${sFloorFinal}${useVulgarFractions ? '½' : '1/2'}`;\n case 0.625:\n return `${sFloorFinal}${useVulgarFractions ? '⅝' : '5/8'}`;\n case 0.75:\n return `${sFloorFinal}${useVulgarFractions ? '¾' : '3/4'}`;\n case 0.875:\n return `${sFloorFinal}${useVulgarFractions ? '⅞' : '7/8'}`;\n }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AG,cAAc,qBAAqB,WAAM;AAAA,WAChD;AACI,eAAA,GAAG,cAAc,qBAAqB,SAAM;AAAA,WAChD;AACI,eAAA,GAAG,cAAc,qBAAqB,WAAM;AAAA,WAChD;AACI,eAAA,GAAG,cAAc,qBAAqB,SAAM;AAAA,WAChD;AACI,eAAA,GAAG,cAAc,qBAAqB,WAAM;AAAA;AAAA,EAEzD;AAEA,SAAO,GAAG;AACZ;;"}
@@ -0,0 +1,2 @@
1
+ (function(n,r){typeof exports=="object"&&typeof module!="undefined"?module.exports=r():typeof define=="function"&&define.amd?define(r):(n=typeof globalThis!="undefined"?globalThis:n||self,n.formatQuantity=r())})(this,function(){"use strict";const n=(o,e)=>Math.abs(o-e)<.009;function r(o,e){const f=typeof o=="string"?parseFloat(o):o;if(isNaN(f)||f===null)return null;if(f===0)return"";const u=Math.abs(f),i=Math.floor(u),d=i===0?"":`${f<0?"-":""}${i} `,$=u-i;if($===0)return`${f}`;const t=e?d.trim():d;if(n($,.33))return`${t}${e?"\u2153":"1/3"}`;if(n($,.66))return`${t}${e?"\u2154":"2/3"}`;if(n($,.2))return`${t}${e?"\u2155":"1/5"}`;if(n($,.4))return`${t}${e?"\u2156":"2/5"}`;if(n($,.6))return`${t}${e?"\u2157":"3/5"}`;if(n($,.8))return`${t}${e?"\u2158":"4/5"}`;switch($){case .125:return`${t}${e?"\u215B":"1/8"}`;case .25:return`${t}${e?"\xBC":"1/4"}`;case .375:return`${t}${e?"\u215C":"3/8"}`;case .5:return`${t}${e?"\xBD":"1/2"}`;case .625:return`${t}${e?"\u215D":"5/8"}`;case .75:return`${t}${e?"\xBE":"3/4"}`;case .875:return`${t}${e?"\u215E":"7/8"}`}return`${f}`}return r});
2
+ //# sourceMappingURL=format-quantity.umd.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format-quantity.umd.js","sources":["../src/index.ts"],"sourcesContent":["/**\n * Determines if two numbers are close enough to consider\n * them equal for our purposes\n */\nconst closeEnough = (a: number, b: number) => Math.abs(a - b) < 0.009;\n\n/**\n * Formats a number (or string that appears to be a number)\n * as one would see it written in imperial measurements, e.g.\n * \"1 1/2\" instead of \"1.5\". To use vulgar fractions, e.g. \"½\",\n * pass `true` as the second argument.\n */\nfunction formatQuantity(qty: string | number, useVulgarFractions?: boolean) {\n const dQty = typeof qty === 'string' ? parseFloat(qty) : qty;\n\n // Bomb out if not a number\n if (isNaN(dQty) || dQty === null) {\n return null;\n }\n\n // Return an empty string if the value is zero\n if (dQty === 0) {\n return '';\n }\n\n const dQtyAbs = Math.abs(dQty);\n const iFloor = Math.floor(dQtyAbs);\n const sFloor = iFloor === 0.0 ? '' : `${dQty < 0 ? '-' : ''}${iFloor} `;\n const dDecimal = dQtyAbs - iFloor;\n\n // Handle integers first. Just return the given value as a string.\n if (dDecimal === 0) {\n return `${dQty}`;\n }\n\n const sFloorFinal = useVulgarFractions ? sFloor.trim() : sFloor;\n\n // Handle infinitely repeating decimals next, since\n // we'll never get an exact match for a switch case:\n if (closeEnough(dDecimal, 0.33)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅓' : '1/3'}`;\n } else if (closeEnough(dDecimal, 0.66)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅔' : '2/3'}`;\n } else if (closeEnough(dDecimal, 0.2)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅕' : '1/5'}`;\n } else if (closeEnough(dDecimal, 0.4)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅖' : '2/5'}`;\n } else if (closeEnough(dDecimal, 0.6)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅗' : '3/5'}`;\n } else if (closeEnough(dDecimal, 0.8)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅘' : '4/5'}`;\n } else {\n switch (dDecimal) {\n case 0.125:\n return `${sFloorFinal}${useVulgarFractions ? '⅛' : '1/8'}`;\n case 0.25:\n return `${sFloorFinal}${useVulgarFractions ? '¼' : '1/4'}`;\n case 0.375:\n return `${sFloorFinal}${useVulgarFractions ? '⅜' : '3/8'}`;\n case 0.5:\n return `${sFloorFinal}${useVulgarFractions ? '½' : '1/2'}`;\n case 0.625:\n return `${sFloorFinal}${useVulgarFractions ? '⅝' : '5/8'}`;\n case 0.75:\n return `${sFloorFinal}${useVulgarFractions ? '¾' : '3/4'}`;\n case 0.875:\n return `${sFloorFinal}${useVulgarFractions ? '⅞' : '7/8'}`;\n }\n }\n\n return `${dQty}`;\n}\n\nexport default formatQuantity;\n"],"names":[],"mappings":"iPAIA,KAAM,GAAc,CAAC,EAAW,IAAc,KAAK,IAAI,EAAI,CAAC,EAAI,KAQhE,WAAwB,EAAsB,EAA8B,CAC1E,KAAM,GAAO,MAAO,IAAQ,SAAW,WAAW,CAAG,EAAI,EAGzD,GAAI,MAAM,CAAI,GAAK,IAAS,KACnB,MAAA,MAIT,GAAI,IAAS,EACJ,MAAA,GAGH,KAAA,GAAU,KAAK,IAAI,CAAI,EACvB,EAAS,KAAK,MAAM,CAAO,EAC3B,EAAS,IAAW,EAAM,GAAK,GAAG,EAAO,EAAI,IAAM,KAAK,KACxD,EAAW,EAAU,EAG3B,GAAI,IAAa,EACf,MAAO,GAAG,IAGZ,KAAM,GAAc,EAAqB,EAAO,KAAA,EAAS,EAIrD,GAAA,EAAY,EAAU,GAAI,EACrB,MAAA,GAAG,IAAc,EAAqB,SAAM,QAC1C,GAAA,EAAY,EAAU,GAAI,EAC5B,MAAA,GAAG,IAAc,EAAqB,SAAM,QAC1C,GAAA,EAAY,EAAU,EAAG,EAC3B,MAAA,GAAG,IAAc,EAAqB,SAAM,QAC1C,GAAA,EAAY,EAAU,EAAG,EAC3B,MAAA,GAAG,IAAc,EAAqB,SAAM,QAC1C,GAAA,EAAY,EAAU,EAAG,EAC3B,MAAA,GAAG,IAAc,EAAqB,SAAM,QAC1C,GAAA,EAAY,EAAU,EAAG,EAC3B,MAAA,GAAG,IAAc,EAAqB,SAAM,QAE3C,OAAA,OACD,MACI,MAAA,GAAG,IAAc,EAAqB,SAAM,YAChD,KACI,MAAA,GAAG,IAAc,EAAqB,OAAM,YAChD,MACI,MAAA,GAAG,IAAc,EAAqB,SAAM,YAChD,IACI,MAAA,GAAG,IAAc,EAAqB,OAAM,YAChD,MACI,MAAA,GAAG,IAAc,EAAqB,SAAM,YAChD,KACI,MAAA,GAAG,IAAc,EAAqB,OAAM,YAChD,MACI,MAAA,GAAG,IAAc,EAAqB,SAAM,QAIzD,MAAO,GAAG,GACZ"}
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- /**
2
- * Formats a number (or string that appears to be a number)
3
- * as one would see it written in imperial measurements, e.g.
4
- * "1 1/2" instead of "1.5". To use vulgar fractions, e.g. "½",
5
- * pass `true` as the second argument.
6
- */
7
- declare function formatQuantity(qty: string | number, useVulgarFractions?: boolean): string | null;
8
- export default formatQuantity;
1
+ /**
2
+ * Formats a number (or string that appears to be a number)
3
+ * as one would see it written in imperial measurements, e.g.
4
+ * "1 1/2" instead of "1.5". To use vulgar fractions, e.g. "½",
5
+ * pass `true` as the second argument.
6
+ */
7
+ declare function formatQuantity(qty: string | number, useVulgarFractions?: boolean): string | null;
8
+ export default formatQuantity;
package/package.json CHANGED
@@ -1,8 +1,15 @@
1
1
  {
2
- "version": "1.0.1",
2
+ "version": "1.0.2",
3
3
  "name": "format-quantity",
4
4
  "author": "Jake Boone <jakeboone02@gmail.com>",
5
5
  "description": "Number formatter for imperial measurements with support for vulgar fractions",
6
+ "files": [
7
+ "dist"
8
+ ],
9
+ "main": "./dist/format-quantity.cjs.js",
10
+ "module": "./dist/format-quantity.es.js",
11
+ "unpkg": "./dist/format-quantity.umd.js",
12
+ "typings": "dist/index.d.ts",
6
13
  "license": "MIT",
7
14
  "keywords": [
8
15
  "recipe",
@@ -20,36 +27,25 @@
20
27
  "type": "git",
21
28
  "url": "https://github.com/jakeboone02/format-quantity"
22
29
  },
23
- "main": "dist/index.js",
24
- "typings": "dist/index.d.ts",
25
- "module": "dist/format-quantity.esm.js",
26
- "unpkg": "dist/format-quantity.umd.production.min.js",
27
- "files": [
28
- "dist"
29
- ],
30
30
  "engines": {
31
31
  "node": ">=10"
32
32
  },
33
33
  "scripts": {
34
- "start": "tsdx watch --format cjs,esm,system,umd",
35
- "build": "tsdx build --format cjs,esm,system,umd",
36
- "test": "tsdx test",
37
- "lint": "tsdx lint",
38
- "prepare": "npm run build",
34
+ "start": "vite",
35
+ "build": "vite build && tsc",
36
+ "test": "jest --coverage",
39
37
  "publish:npm": "np"
40
38
  },
41
- "prettier": {
42
- "printWidth": 80,
43
- "semi": true,
44
- "singleQuote": true,
45
- "trailingComma": "es5",
46
- "arrowParens": "avoid",
47
- "tabWidth": 2
48
- },
49
39
  "devDependencies": {
40
+ "@babel/core": "^7.17.8",
41
+ "@babel/preset-env": "^7.16.11",
42
+ "@babel/preset-typescript": "^7.16.7",
43
+ "@types/jest": "^27.4.1",
44
+ "gh-pages": "^3.1.0",
45
+ "jest": "^27.5.1",
50
46
  "np": "^7.3.0",
51
- "tsdx": "^0.14.1",
52
- "tslib": "^2.1.0",
53
- "typescript": "^4.1.3"
47
+ "prettier": "^2.6.0",
48
+ "typescript": "^4.1.5",
49
+ "vite": "^2.8.6"
54
50
  }
55
51
  }
@@ -1,83 +0,0 @@
1
- 'use strict';
2
-
3
- /**
4
- * Determines if two numbers are close enough to consider
5
- * them equal for our purposes
6
- */
7
- var closeEnough = function closeEnough(a, b) {
8
- return Math.abs(a - b) < 0.009;
9
- };
10
- /**
11
- * Formats a number (or string that appears to be a number)
12
- * as one would see it written in imperial measurements, e.g.
13
- * "1 1/2" instead of "1.5". To use vulgar fractions, e.g. "½",
14
- * pass `true` as the second argument.
15
- */
16
-
17
-
18
- function formatQuantity(qty, useVulgarFractions) {
19
- var dQty = typeof qty === 'string' ? parseFloat(qty) : qty; // Bomb out if not a number
20
-
21
- if (isNaN(dQty) || dQty === null) {
22
- return null;
23
- } // Return an empty string if the value is zero
24
-
25
-
26
- if (dQty === 0) {
27
- return '';
28
- }
29
-
30
- var dQtyAbs = Math.abs(dQty);
31
- var iFloor = Math.floor(dQtyAbs);
32
- var sFloor = iFloor === 0.0 ? '' : "" + (dQty < 0 ? '-' : '') + iFloor + " ";
33
- var dDecimal = dQtyAbs - iFloor; // Handle integers first. Just return the given value as a string.
34
-
35
- if (dDecimal === 0) {
36
- return "" + dQty;
37
- }
38
-
39
- var sFloorFinal = useVulgarFractions ? sFloor.trim() : sFloor; // Handle infinitely repeating decimals next, since
40
- // we'll never get an exact match for a switch case:
41
-
42
- if (closeEnough(dDecimal, 0.33)) {
43
- return "" + sFloorFinal + (useVulgarFractions ? '⅓' : '1/3');
44
- } else if (closeEnough(dDecimal, 0.66)) {
45
- return "" + sFloorFinal + (useVulgarFractions ? '⅔' : '2/3');
46
- } else if (closeEnough(dDecimal, 0.2)) {
47
- return "" + sFloorFinal + (useVulgarFractions ? '⅕' : '1/5');
48
- } else if (closeEnough(dDecimal, 0.4)) {
49
- return "" + sFloorFinal + (useVulgarFractions ? '⅖' : '2/5');
50
- } else if (closeEnough(dDecimal, 0.6)) {
51
- return "" + sFloorFinal + (useVulgarFractions ? '⅗' : '3/5');
52
- } else if (closeEnough(dDecimal, 0.8)) {
53
- return "" + sFloorFinal + (useVulgarFractions ? '⅘' : '4/5');
54
- } else {
55
- switch (dDecimal) {
56
- case 0.125:
57
- return "" + sFloorFinal + (useVulgarFractions ? '⅛' : '1/8');
58
-
59
- case 0.25:
60
- return "" + sFloorFinal + (useVulgarFractions ? '¼' : '1/4');
61
-
62
- case 0.375:
63
- return "" + sFloorFinal + (useVulgarFractions ? '⅜' : '3/8');
64
-
65
- case 0.5:
66
- return "" + sFloorFinal + (useVulgarFractions ? '½' : '1/2');
67
-
68
- case 0.625:
69
- return "" + sFloorFinal + (useVulgarFractions ? '⅝' : '5/8');
70
-
71
- case 0.75:
72
- return "" + sFloorFinal + (useVulgarFractions ? '¾' : '3/4');
73
-
74
- case 0.875:
75
- return "" + sFloorFinal + (useVulgarFractions ? '⅞' : '7/8');
76
- }
77
- }
78
-
79
- return "" + dQty;
80
- }
81
-
82
- module.exports = formatQuantity;
83
- //# sourceMappingURL=format-quantity.cjs.development.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"format-quantity.cjs.development.js","sources":["../src/index.ts"],"sourcesContent":["/**\n * Determines if two numbers are close enough to consider\n * them equal for our purposes\n */\nconst closeEnough = (a: number, b: number) => Math.abs(a - b) < 0.009;\n\n/**\n * Formats a number (or string that appears to be a number)\n * as one would see it written in imperial measurements, e.g.\n * \"1 1/2\" instead of \"1.5\". To use vulgar fractions, e.g. \"½\",\n * pass `true` as the second argument.\n */\nfunction formatQuantity(qty: string | number, useVulgarFractions?: boolean) {\n const dQty = typeof qty === 'string' ? parseFloat(qty) : qty;\n\n // Bomb out if not a number\n if (isNaN(dQty) || dQty === null) {\n return null;\n }\n\n // Return an empty string if the value is zero\n if (dQty === 0) {\n return '';\n }\n\n const dQtyAbs = Math.abs(dQty);\n const iFloor = Math.floor(dQtyAbs);\n const sFloor = iFloor === 0.0 ? '' : `${dQty < 0 ? '-' : ''}${iFloor} `;\n const dDecimal = dQtyAbs - iFloor;\n\n // Handle integers first. Just return the given value as a string.\n if (dDecimal === 0) {\n return `${dQty}`;\n }\n\n const sFloorFinal = useVulgarFractions ? sFloor.trim() : sFloor;\n\n // Handle infinitely repeating decimals next, since\n // we'll never get an exact match for a switch case:\n if (closeEnough(dDecimal, 0.33)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅓' : '1/3'}`;\n } else if (closeEnough(dDecimal, 0.66)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅔' : '2/3'}`;\n } else if (closeEnough(dDecimal, 0.2)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅕' : '1/5'}`;\n } else if (closeEnough(dDecimal, 0.4)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅖' : '2/5'}`;\n } else if (closeEnough(dDecimal, 0.6)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅗' : '3/5'}`;\n } else if (closeEnough(dDecimal, 0.8)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅘' : '4/5'}`;\n } else {\n switch (dDecimal) {\n case 0.125:\n return `${sFloorFinal}${useVulgarFractions ? '⅛' : '1/8'}`;\n case 0.25:\n return `${sFloorFinal}${useVulgarFractions ? '¼' : '1/4'}`;\n case 0.375:\n return `${sFloorFinal}${useVulgarFractions ? '⅜' : '3/8'}`;\n case 0.5:\n return `${sFloorFinal}${useVulgarFractions ? '½' : '1/2'}`;\n case 0.625:\n return `${sFloorFinal}${useVulgarFractions ? '⅝' : '5/8'}`;\n case 0.75:\n return `${sFloorFinal}${useVulgarFractions ? '¾' : '3/4'}`;\n case 0.875:\n return `${sFloorFinal}${useVulgarFractions ? '⅞' : '7/8'}`;\n }\n }\n\n return `${dQty}`;\n}\n\nexport default formatQuantity;\n"],"names":["closeEnough","a","b","Math","abs","formatQuantity","qty","useVulgarFractions","dQty","parseFloat","isNaN","dQtyAbs","iFloor","floor","sFloor","dDecimal","sFloorFinal","trim"],"mappings":";;AAAA;;;;AAIA,IAAMA,WAAW,GAAG,SAAdA,WAAc,CAACC,CAAD,EAAYC,CAAZ;AAAA,SAA0BC,IAAI,CAACC,GAAL,CAASH,CAAC,GAAGC,CAAb,IAAkB,KAA5C;AAAA,CAApB;AAEA;;;;;;;;AAMA,SAASG,cAAT,CAAwBC,GAAxB,EAA8CC,kBAA9C;AACE,MAAMC,IAAI,GAAG,OAAOF,GAAP,KAAe,QAAf,GAA0BG,UAAU,CAACH,GAAD,CAApC,GAA4CA,GAAzD;;AAGA,MAAII,KAAK,CAACF,IAAD,CAAL,IAAeA,IAAI,KAAK,IAA5B,EAAkC;AAChC,WAAO,IAAP;AACD;;;AAGD,MAAIA,IAAI,KAAK,CAAb,EAAgB;AACd,WAAO,EAAP;AACD;;AAED,MAAMG,OAAO,GAAGR,IAAI,CAACC,GAAL,CAASI,IAAT,CAAhB;AACA,MAAMI,MAAM,GAAGT,IAAI,CAACU,KAAL,CAAWF,OAAX,CA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AAK,IAAL;AACE,oBAAUS,WAAV,IAAwBT,kBAAkB,GAAG,GAAH,GAAS,KAAnD;;AACF,WAAK,KAAL;AACE,oBAAUS,WAAV,IAAwBT,kBAAkB,GAAG,GAAH,GAAS,KAAnD;;AACF,WAAK,GAAL;AACE,oBAAUS,WAAV,IAAwBT,kBAAkB,GAAG,GAAH,GAAS,KAAnD;;AACF,WAAK,KAAL;AACE,oBAAUS,WAAV,IAAwBT,kBAAkB,GAAG,GAAH,GAAS,KAAnD;;AACF,WAAK,IAAL;AACE,oBAAUS,WAAV,IAAwBT,kBAAkB,GAAG,GAAH,GAAS,KAAnD;;AACF,WAAK,KAAL;AACE,oBAAUS,WAAV,IAAwBT,kBAAkB,GAAG,GAAH,GAAS,KAAnD;AAdJ;AAgBD;;AAED,cAAUC,IAAV;AACD;;;;"}
@@ -1,2 +0,0 @@
1
- "use strict";var r=function(r,t){return Math.abs(r-t)<.009};module.exports=function(t,e){var n="string"==typeof t?parseFloat(t):t;if(isNaN(n)||null===n)return null;if(0===n)return"";var u=Math.abs(n),a=Math.floor(u),i=0===a?"":(n<0?"-":"")+a+" ",s=u-a;if(0===s)return""+n;var f=e?i.trim():i;if(r(s,.33))return f+(e?"⅓":"1/3");if(r(s,.66))return f+(e?"⅔":"2/3");if(r(s,.2))return f+(e?"⅕":"1/5");if(r(s,.4))return f+(e?"⅖":"2/5");if(r(s,.6))return f+(e?"⅗":"3/5");if(r(s,.8))return f+(e?"⅘":"4/5");switch(s){case.125:return f+(e?"⅛":"1/8");case.25:return f+(e?"¼":"1/4");case.375:return f+(e?"⅜":"3/8");case.5:return f+(e?"½":"1/2");case.625:return f+(e?"⅝":"5/8");case.75:return f+(e?"¾":"3/4");case.875:return f+(e?"⅞":"7/8")}return""+n};
2
- //# sourceMappingURL=format-quantity.cjs.production.min.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"format-quantity.cjs.production.min.js","sources":["../src/index.ts"],"sourcesContent":["/**\n * Determines if two numbers are close enough to consider\n * them equal for our purposes\n */\nconst closeEnough = (a: number, b: number) => Math.abs(a - b) < 0.009;\n\n/**\n * Formats a number (or string that appears to be a number)\n * as one would see it written in imperial measurements, e.g.\n * \"1 1/2\" instead of \"1.5\". To use vulgar fractions, e.g. \"½\",\n * pass `true` as the second argument.\n */\nfunction formatQuantity(qty: string | number, useVulgarFractions?: boolean) {\n const dQty = typeof qty === 'string' ? parseFloat(qty) : qty;\n\n // Bomb out if not a number\n if (isNaN(dQty) || dQty === null) {\n return null;\n }\n\n // Return an empty string if the value is zero\n if (dQty === 0) {\n return '';\n }\n\n const dQtyAbs = Math.abs(dQty);\n const iFloor = Math.floor(dQtyAbs);\n const sFloor = iFloor === 0.0 ? '' : `${dQty < 0 ? '-' : ''}${iFloor} `;\n const dDecimal = dQtyAbs - iFloor;\n\n // Handle integers first. Just return the given value as a string.\n if (dDecimal === 0) {\n return `${dQty}`;\n }\n\n const sFloorFinal = useVulgarFractions ? sFloor.trim() : sFloor;\n\n // Handle infinitely repeating decimals next, since\n // we'll never get an exact match for a switch case:\n if (closeEnough(dDecimal, 0.33)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅓' : '1/3'}`;\n } else if (closeEnough(dDecimal, 0.66)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅔' : '2/3'}`;\n } else if (closeEnough(dDecimal, 0.2)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅕' : '1/5'}`;\n } else if (closeEnough(dDecimal, 0.4)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅖' : '2/5'}`;\n } else if (closeEnough(dDecimal, 0.6)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅗' : '3/5'}`;\n } else if (closeEnough(dDecimal, 0.8)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅘' : '4/5'}`;\n } else {\n switch (dDecimal) {\n case 0.125:\n return `${sFloorFinal}${useVulgarFractions ? '⅛' : '1/8'}`;\n case 0.25:\n return `${sFloorFinal}${useVulgarFractions ? '¼' : '1/4'}`;\n case 0.375:\n return `${sFloorFinal}${useVulgarFractions ? '⅜' : '3/8'}`;\n case 0.5:\n return `${sFloorFinal}${useVulgarFractions ? '½' : '1/2'}`;\n case 0.625:\n return `${sFloorFinal}${useVulgarFractions ? '⅝' : '5/8'}`;\n case 0.75:\n return `${sFloorFinal}${useVulgarFractions ? '¾' : '3/4'}`;\n case 0.875:\n return `${sFloorFinal}${useVulgarFractions ? '⅞' : '7/8'}`;\n }\n }\n\n return `${dQty}`;\n}\n\nexport default formatQuantity;\n"],"names":["closeEnough","a","b","Math","abs","qty","useVulgarFractions","dQty","parseFloat","isNaN","dQtyAbs","iFloor","floor","sFloor","dDecimal","sFloorFinal","trim"],"mappings":"aAIA,IAAMA,EAAc,SAACC,EAAWC,UAAcC,KAAKC,IAAIH,EAAIC,GAAK,qBAQhE,SAAwBG,EAAsBC,OACtCC,EAAsB,iBAARF,EAAmBG,WAAWH,GAAOA,KAGrDI,MAAMF,IAAkB,OAATA,SACV,QAII,IAATA,QACK,OAGHG,EAAUP,KAAKC,IAAIG,GACnBI,EAASR,KAAKS,MAAMF,GACpBG,EAAoB,IAAXF,EAAiB,IAAQJ,EAAO,EAAI,IAAM,IAAKI,MACxDG,EAAWJ,EAAUC,KAGV,IAAbG,WACQP,MAGNQ,EAAcT,EAAqBO,EAAOG,OAASH,KAIrDb,EAAYc,EAAU,YACdC,GAAcT,EAAqB,IAAM,OAC9C,GAAIN,EAAYc,EAAU,YACrBC,GAAcT,EAAqB,IAAM,OAC9C,GAAIN,EAAYc,EAAU,WACrBC,GAAcT,EAAqB,IAAM,OAC9C,GAAIN,EAAYc,EAAU,WACrBC,GAAcT,EAAqB,IAAM,OAC9C,GAAIN,EAAYc,EAAU,WACrBC,GAAcT,EAAqB,IAAM,OAC9C,GAAIN,EAAYc,EAAU,WACrBC,GAAcT,EAAqB,IAAM,cAE3CQ,OACD,YACOC,GAAcT,EAAqB,IAAM,WAChD,WACOS,GAAcT,EAAqB,IAAM,WAChD,YACOS,GAAcT,EAAqB,IAAM,WAChD,UACOS,GAAcT,EAAqB,IAAM,WAChD,YACOS,GAAcT,EAAqB,IAAM,WAChD,WACOS,GAAcT,EAAqB,IAAM,WAChD,YACOS,GAAcT,EAAqB,IAAM,gBAI/CC"}
@@ -1,81 +0,0 @@
1
- /**
2
- * Determines if two numbers are close enough to consider
3
- * them equal for our purposes
4
- */
5
- var closeEnough = function closeEnough(a, b) {
6
- return Math.abs(a - b) < 0.009;
7
- };
8
- /**
9
- * Formats a number (or string that appears to be a number)
10
- * as one would see it written in imperial measurements, e.g.
11
- * "1 1/2" instead of "1.5". To use vulgar fractions, e.g. "½",
12
- * pass `true` as the second argument.
13
- */
14
-
15
-
16
- function formatQuantity(qty, useVulgarFractions) {
17
- var dQty = typeof qty === 'string' ? parseFloat(qty) : qty; // Bomb out if not a number
18
-
19
- if (isNaN(dQty) || dQty === null) {
20
- return null;
21
- } // Return an empty string if the value is zero
22
-
23
-
24
- if (dQty === 0) {
25
- return '';
26
- }
27
-
28
- var dQtyAbs = Math.abs(dQty);
29
- var iFloor = Math.floor(dQtyAbs);
30
- var sFloor = iFloor === 0.0 ? '' : "" + (dQty < 0 ? '-' : '') + iFloor + " ";
31
- var dDecimal = dQtyAbs - iFloor; // Handle integers first. Just return the given value as a string.
32
-
33
- if (dDecimal === 0) {
34
- return "" + dQty;
35
- }
36
-
37
- var sFloorFinal = useVulgarFractions ? sFloor.trim() : sFloor; // Handle infinitely repeating decimals next, since
38
- // we'll never get an exact match for a switch case:
39
-
40
- if (closeEnough(dDecimal, 0.33)) {
41
- return "" + sFloorFinal + (useVulgarFractions ? '⅓' : '1/3');
42
- } else if (closeEnough(dDecimal, 0.66)) {
43
- return "" + sFloorFinal + (useVulgarFractions ? '⅔' : '2/3');
44
- } else if (closeEnough(dDecimal, 0.2)) {
45
- return "" + sFloorFinal + (useVulgarFractions ? '⅕' : '1/5');
46
- } else if (closeEnough(dDecimal, 0.4)) {
47
- return "" + sFloorFinal + (useVulgarFractions ? '⅖' : '2/5');
48
- } else if (closeEnough(dDecimal, 0.6)) {
49
- return "" + sFloorFinal + (useVulgarFractions ? '⅗' : '3/5');
50
- } else if (closeEnough(dDecimal, 0.8)) {
51
- return "" + sFloorFinal + (useVulgarFractions ? '⅘' : '4/5');
52
- } else {
53
- switch (dDecimal) {
54
- case 0.125:
55
- return "" + sFloorFinal + (useVulgarFractions ? '⅛' : '1/8');
56
-
57
- case 0.25:
58
- return "" + sFloorFinal + (useVulgarFractions ? '¼' : '1/4');
59
-
60
- case 0.375:
61
- return "" + sFloorFinal + (useVulgarFractions ? '⅜' : '3/8');
62
-
63
- case 0.5:
64
- return "" + sFloorFinal + (useVulgarFractions ? '½' : '1/2');
65
-
66
- case 0.625:
67
- return "" + sFloorFinal + (useVulgarFractions ? '⅝' : '5/8');
68
-
69
- case 0.75:
70
- return "" + sFloorFinal + (useVulgarFractions ? '¾' : '3/4');
71
-
72
- case 0.875:
73
- return "" + sFloorFinal + (useVulgarFractions ? '⅞' : '7/8');
74
- }
75
- }
76
-
77
- return "" + dQty;
78
- }
79
-
80
- export default formatQuantity;
81
- //# sourceMappingURL=format-quantity.esm.js.map
@@ -1,89 +0,0 @@
1
- System.register('formatQuantity', [], function (exports) {
2
- 'use strict';
3
- return {
4
- execute: function () {
5
-
6
- /**
7
- * Determines if two numbers are close enough to consider
8
- * them equal for our purposes
9
- */
10
- var closeEnough = function closeEnough(a, b) {
11
- return Math.abs(a - b) < 0.009;
12
- };
13
- /**
14
- * Formats a number (or string that appears to be a number)
15
- * as one would see it written in imperial measurements, e.g.
16
- * "1 1/2" instead of "1.5". To use vulgar fractions, e.g. "½",
17
- * pass `true` as the second argument.
18
- */
19
-
20
-
21
- function formatQuantity(qty, useVulgarFractions) {
22
- var dQty = typeof qty === 'string' ? parseFloat(qty) : qty; // Bomb out if not a number
23
-
24
- if (isNaN(dQty) || dQty === null) {
25
- return null;
26
- } // Return an empty string if the value is zero
27
-
28
-
29
- if (dQty === 0) {
30
- return '';
31
- }
32
-
33
- var dQtyAbs = Math.abs(dQty);
34
- var iFloor = Math.floor(dQtyAbs);
35
- var sFloor = iFloor === 0.0 ? '' : "" + (dQty < 0 ? '-' : '') + iFloor + " ";
36
- var dDecimal = dQtyAbs - iFloor; // Handle integers first. Just return the given value as a string.
37
-
38
- if (dDecimal === 0) {
39
- return "" + dQty;
40
- }
41
-
42
- var sFloorFinal = useVulgarFractions ? sFloor.trim() : sFloor; // Handle infinitely repeating decimals next, since
43
- // we'll never get an exact match for a switch case:
44
-
45
- if (closeEnough(dDecimal, 0.33)) {
46
- return "" + sFloorFinal + (useVulgarFractions ? '⅓' : '1/3');
47
- } else if (closeEnough(dDecimal, 0.66)) {
48
- return "" + sFloorFinal + (useVulgarFractions ? '⅔' : '2/3');
49
- } else if (closeEnough(dDecimal, 0.2)) {
50
- return "" + sFloorFinal + (useVulgarFractions ? '⅕' : '1/5');
51
- } else if (closeEnough(dDecimal, 0.4)) {
52
- return "" + sFloorFinal + (useVulgarFractions ? '⅖' : '2/5');
53
- } else if (closeEnough(dDecimal, 0.6)) {
54
- return "" + sFloorFinal + (useVulgarFractions ? '⅗' : '3/5');
55
- } else if (closeEnough(dDecimal, 0.8)) {
56
- return "" + sFloorFinal + (useVulgarFractions ? '⅘' : '4/5');
57
- } else {
58
- switch (dDecimal) {
59
- case 0.125:
60
- return "" + sFloorFinal + (useVulgarFractions ? '⅛' : '1/8');
61
-
62
- case 0.25:
63
- return "" + sFloorFinal + (useVulgarFractions ? '¼' : '1/4');
64
-
65
- case 0.375:
66
- return "" + sFloorFinal + (useVulgarFractions ? '⅜' : '3/8');
67
-
68
- case 0.5:
69
- return "" + sFloorFinal + (useVulgarFractions ? '½' : '1/2');
70
-
71
- case 0.625:
72
- return "" + sFloorFinal + (useVulgarFractions ? '⅝' : '5/8');
73
-
74
- case 0.75:
75
- return "" + sFloorFinal + (useVulgarFractions ? '¾' : '3/4');
76
-
77
- case 0.875:
78
- return "" + sFloorFinal + (useVulgarFractions ? '⅞' : '7/8');
79
- }
80
- }
81
-
82
- return "" + dQty;
83
- }
84
- exports('default', formatQuantity);
85
-
86
- }
87
- };
88
- });
89
- //# sourceMappingURL=format-quantity.system.development.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"format-quantity.system.development.js","sources":["../src/index.ts"],"sourcesContent":["/**\n * Determines if two numbers are close enough to consider\n * them equal for our purposes\n */\nconst closeEnough = (a: number, b: number) => Math.abs(a - b) < 0.009;\n\n/**\n * Formats a number (or string that appears to be a number)\n * as one would see it written in imperial measurements, e.g.\n * \"1 1/2\" instead of \"1.5\". To use vulgar fractions, e.g. \"½\",\n * pass `true` as the second argument.\n */\nfunction formatQuantity(qty: string | number, useVulgarFractions?: boolean) {\n const dQty = typeof qty === 'string' ? parseFloat(qty) : qty;\n\n // Bomb out if not a number\n if (isNaN(dQty) || dQty === null) {\n return null;\n }\n\n // Return an empty string if the value is zero\n if (dQty === 0) {\n return '';\n }\n\n const dQtyAbs = Math.abs(dQty);\n const iFloor = Math.floor(dQtyAbs);\n const sFloor = iFloor === 0.0 ? '' : `${dQty < 0 ? '-' : ''}${iFloor} `;\n const dDecimal = dQtyAbs - iFloor;\n\n // Handle integers first. Just return the given value as a string.\n if (dDecimal === 0) {\n return `${dQty}`;\n }\n\n const sFloorFinal = useVulgarFractions ? sFloor.trim() : sFloor;\n\n // Handle infinitely repeating decimals next, since\n // we'll never get an exact match for a switch case:\n if (closeEnough(dDecimal, 0.33)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅓' : '1/3'}`;\n } else if (closeEnough(dDecimal, 0.66)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅔' : '2/3'}`;\n } else if (closeEnough(dDecimal, 0.2)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅕' : '1/5'}`;\n } else if (closeEnough(dDecimal, 0.4)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅖' : '2/5'}`;\n } else if (closeEnough(dDecimal, 0.6)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅗' : '3/5'}`;\n } else if (closeEnough(dDecimal, 0.8)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅘' : '4/5'}`;\n } else {\n switch (dDecimal) {\n case 0.125:\n return `${sFloorFinal}${useVulgarFractions ? '⅛' : '1/8'}`;\n case 0.25:\n return `${sFloorFinal}${useVulgarFractions ? '¼' : '1/4'}`;\n case 0.375:\n return `${sFloorFinal}${useVulgarFractions ? '⅜' : '3/8'}`;\n case 0.5:\n return `${sFloorFinal}${useVulgarFractions ? '½' : '1/2'}`;\n case 0.625:\n return `${sFloorFinal}${useVulgarFractions ? '⅝' : '5/8'}`;\n case 0.75:\n return `${sFloorFinal}${useVulgarFractions ? '¾' : '3/4'}`;\n case 0.875:\n return `${sFloorFinal}${useVulgarFractions ? '⅞' : '7/8'}`;\n }\n }\n\n return `${dQty}`;\n}\n\nexport default formatQuantity;\n"],"names":["closeEnough","a","b","Math","abs","formatQuantity","qty","useVulgarFractions","dQty","parseFloat","isNaN","dQtyAbs","iFloor","floor","sFloor","dDecimal","sFloorFinal","trim"],"mappings":";;;;;MAAA;;;;MAIA,IAAMA,WAAW,GAAG,SAAdA,WAAc,CAACC,CAAD,EAAYC,CAAZ;MAAA,SAA0BC,IAAI,CAACC,GAAL,CAASH,CAAC,GAAGC,CAAb,IAAkB,KAA5C;MAAA,CAApB;MAEA;;;;;;;;MAMA,SAASG,cAAT,CAAwBC,GAAxB,EAA8CC,kBAA9C;MACE,MAAMC,IAAI,GAAG,OAAOF,GAAP,KAAe,QAAf,GAA0BG,UAAU,CAACH,GAAD,CAApC,GAA4CA,GAAzD;;MAGA,MAAII,KAAK,CAACF,IAAD,CAAL,IAAeA,IAAI,KAAK,IAA5B,EAAkC;MAChC,WAAO,IAAP;MACD;;;MAGD,MAAIA,IAAI,KAAK,CAAb,EAAgB;MACd,WAAO,EAAP;MACD;;MAED,MAAMG,OAAO,GAAGR,IAAI,CAACC,GAAL,CAASI,IAAT,CAAhB;MACA,MAAMI,MAAM,GAAG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kB,GAAG,GAAH,GAAS,KAAnD;;MACF,WAAK,IAAL;MACE,oBAAUS,WAAV,IAAwBT,kBAAkB,GAAG,GAAH,GAAS,KAAnD;;MACF,WAAK,KAAL;MACE,oBAAUS,WAAV,IAAwBT,kBAAkB,GAAG,GAAH,GAAS,KAAnD;;MACF,WAAK,GAAL;MACE,oBAAUS,WAAV,IAAwBT,kBAAkB,GAAG,GAAH,GAAS,KAAnD;;MACF,WAAK,KAAL;MACE,oBAAUS,WAAV,IAAwBT,kBAAkB,GAAG,GAAH,GAAS,KAAnD;;MACF,WAAK,IAAL;MACE,oBAAUS,WAAV,IAAwBT,kBAAkB,GAAG,GAAH,GAAS,KAAnD;;MACF,WAAK,KAAL;MACE,oBAAUS,WAAV,IAAwBT,kBAAkB,GAAG,GAAH,GAAS,KAAnD;MAdJ;MAgBD;;MAED,cAAUC,IAAV;MACD;;;;;;;"}
@@ -1,2 +0,0 @@
1
- System.register("formatQuantity",[],(function(r){"use strict";return{execute:function(){var t=function(r,t){return Math.abs(r-t)<.009};r("default",(function(r,e){var n="string"==typeof r?parseFloat(r):r;if(isNaN(n)||null===n)return null;if(0===n)return"";var u=Math.abs(n),a=Math.floor(u),i=0===a?"":(n<0?"-":"")+a+" ",f=u-a;if(0===f)return""+n;var s=e?i.trim():i;if(t(f,.33))return s+(e?"⅓":"1/3");if(t(f,.66))return s+(e?"⅔":"2/3");if(t(f,.2))return s+(e?"⅕":"1/5");if(t(f,.4))return s+(e?"⅖":"2/5");if(t(f,.6))return s+(e?"⅗":"3/5");if(t(f,.8))return s+(e?"⅘":"4/5");switch(f){case.125:return s+(e?"⅛":"1/8");case.25:return s+(e?"¼":"1/4");case.375:return s+(e?"⅜":"3/8");case.5:return s+(e?"½":"1/2");case.625:return s+(e?"⅝":"5/8");case.75:return s+(e?"¾":"3/4");case.875:return s+(e?"⅞":"7/8")}return""+n}))}}}));
2
- //# sourceMappingURL=format-quantity.system.production.min.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"format-quantity.system.production.min.js","sources":["../src/index.ts"],"sourcesContent":["/**\n * Determines if two numbers are close enough to consider\n * them equal for our purposes\n */\nconst closeEnough = (a: number, b: number) => Math.abs(a - b) < 0.009;\n\n/**\n * Formats a number (or string that appears to be a number)\n * as one would see it written in imperial measurements, e.g.\n * \"1 1/2\" instead of \"1.5\". To use vulgar fractions, e.g. \"½\",\n * pass `true` as the second argument.\n */\nfunction formatQuantity(qty: string | number, useVulgarFractions?: boolean) {\n const dQty = typeof qty === 'string' ? parseFloat(qty) : qty;\n\n // Bomb out if not a number\n if (isNaN(dQty) || dQty === null) {\n return null;\n }\n\n // Return an empty string if the value is zero\n if (dQty === 0) {\n return '';\n }\n\n const dQtyAbs = Math.abs(dQty);\n const iFloor = Math.floor(dQtyAbs);\n const sFloor = iFloor === 0.0 ? '' : `${dQty < 0 ? '-' : ''}${iFloor} `;\n const dDecimal = dQtyAbs - iFloor;\n\n // Handle integers first. Just return the given value as a string.\n if (dDecimal === 0) {\n return `${dQty}`;\n }\n\n const sFloorFinal = useVulgarFractions ? sFloor.trim() : sFloor;\n\n // Handle infinitely repeating decimals next, since\n // we'll never get an exact match for a switch case:\n if (closeEnough(dDecimal, 0.33)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅓' : '1/3'}`;\n } else if (closeEnough(dDecimal, 0.66)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅔' : '2/3'}`;\n } else if (closeEnough(dDecimal, 0.2)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅕' : '1/5'}`;\n } else if (closeEnough(dDecimal, 0.4)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅖' : '2/5'}`;\n } else if (closeEnough(dDecimal, 0.6)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅗' : '3/5'}`;\n } else if (closeEnough(dDecimal, 0.8)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅘' : '4/5'}`;\n } else {\n switch (dDecimal) {\n case 0.125:\n return `${sFloorFinal}${useVulgarFractions ? '⅛' : '1/8'}`;\n case 0.25:\n return `${sFloorFinal}${useVulgarFractions ? '¼' : '1/4'}`;\n case 0.375:\n return `${sFloorFinal}${useVulgarFractions ? '⅜' : '3/8'}`;\n case 0.5:\n return `${sFloorFinal}${useVulgarFractions ? '½' : '1/2'}`;\n case 0.625:\n return `${sFloorFinal}${useVulgarFractions ? '⅝' : '5/8'}`;\n case 0.75:\n return `${sFloorFinal}${useVulgarFractions ? '¾' : '3/4'}`;\n case 0.875:\n return `${sFloorFinal}${useVulgarFractions ? '⅞' : '7/8'}`;\n }\n }\n\n return `${dQty}`;\n}\n\nexport default formatQuantity;\n"],"names":["closeEnough","a","b","Math","abs","qty","useVulgarFractions","dQty","parseFloat","isNaN","dQtyAbs","iFloor","floor","sFloor","dDecimal","sFloorFinal","trim"],"mappings":"wFAIA,IAAMA,EAAc,SAACC,EAAWC,UAAcC,KAAKC,IAAIH,EAAIC,GAAK,mBAQhE,SAAwBG,EAAsBC,OACtCC,EAAsB,iBAARF,EAAmBG,WAAWH,GAAOA,KAGrDI,MAAMF,IAAkB,OAATA,SACV,QAII,IAATA,QACK,OAGHG,EAAUP,KAAKC,IAAIG,GACnBI,EAASR,KAAKS,MAAMF,GACpBG,EAAoB,IAAXF,EAAiB,IAAQJ,EAAO,EAAI,IAAM,IAAKI,MACxDG,EAAWJ,EAAUC,KAGV,IAAbG,WACQP,MAGNQ,EAAcT,EAAqBO,EAAOG,OAASH,KAIrDb,EAAYc,EAAU,YACdC,GAAcT,EAAqB,IAAM,OAC9C,GAAIN,EAAYc,EAAU,YACrBC,GAAcT,EAAqB,IAAM,OAC9C,GAAIN,EAAYc,EAAU,WACrBC,GAAcT,EAAqB,IAAM,OAC9C,GAAIN,EAAYc,EAAU,WACrBC,GAAcT,EAAqB,IAAM,OAC9C,GAAIN,EAAYc,EAAU,WACrBC,GAAcT,EAAqB,IAAM,OAC9C,GAAIN,EAAYc,EAAU,WACrBC,GAAcT,EAAqB,IAAM,cAE3CQ,OACD,YACOC,GAAcT,EAAqB,IAAM,WAChD,WACOS,GAAcT,EAAqB,IAAM,WAChD,YACOS,GAAcT,EAAqB,IAAM,WAChD,UACOS,GAAcT,EAAqB,IAAM,WAChD,YACOS,GAAcT,EAAqB,IAAM,WAChD,WACOS,GAAcT,EAAqB,IAAM,WAChD,YACOS,GAAcT,EAAqB,IAAM,gBAI/CC"}
@@ -1,89 +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.formatQuantity = factory());
5
- }(this, (function () { 'use strict';
6
-
7
- /**
8
- * Determines if two numbers are close enough to consider
9
- * them equal for our purposes
10
- */
11
- var closeEnough = function closeEnough(a, b) {
12
- return Math.abs(a - b) < 0.009;
13
- };
14
- /**
15
- * Formats a number (or string that appears to be a number)
16
- * as one would see it written in imperial measurements, e.g.
17
- * "1 1/2" instead of "1.5". To use vulgar fractions, e.g. "½",
18
- * pass `true` as the second argument.
19
- */
20
-
21
-
22
- function formatQuantity(qty, useVulgarFractions) {
23
- var dQty = typeof qty === 'string' ? parseFloat(qty) : qty; // Bomb out if not a number
24
-
25
- if (isNaN(dQty) || dQty === null) {
26
- return null;
27
- } // Return an empty string if the value is zero
28
-
29
-
30
- if (dQty === 0) {
31
- return '';
32
- }
33
-
34
- var dQtyAbs = Math.abs(dQty);
35
- var iFloor = Math.floor(dQtyAbs);
36
- var sFloor = iFloor === 0.0 ? '' : "" + (dQty < 0 ? '-' : '') + iFloor + " ";
37
- var dDecimal = dQtyAbs - iFloor; // Handle integers first. Just return the given value as a string.
38
-
39
- if (dDecimal === 0) {
40
- return "" + dQty;
41
- }
42
-
43
- var sFloorFinal = useVulgarFractions ? sFloor.trim() : sFloor; // Handle infinitely repeating decimals next, since
44
- // we'll never get an exact match for a switch case:
45
-
46
- if (closeEnough(dDecimal, 0.33)) {
47
- return "" + sFloorFinal + (useVulgarFractions ? '⅓' : '1/3');
48
- } else if (closeEnough(dDecimal, 0.66)) {
49
- return "" + sFloorFinal + (useVulgarFractions ? '⅔' : '2/3');
50
- } else if (closeEnough(dDecimal, 0.2)) {
51
- return "" + sFloorFinal + (useVulgarFractions ? '⅕' : '1/5');
52
- } else if (closeEnough(dDecimal, 0.4)) {
53
- return "" + sFloorFinal + (useVulgarFractions ? '⅖' : '2/5');
54
- } else if (closeEnough(dDecimal, 0.6)) {
55
- return "" + sFloorFinal + (useVulgarFractions ? '⅗' : '3/5');
56
- } else if (closeEnough(dDecimal, 0.8)) {
57
- return "" + sFloorFinal + (useVulgarFractions ? '⅘' : '4/5');
58
- } else {
59
- switch (dDecimal) {
60
- case 0.125:
61
- return "" + sFloorFinal + (useVulgarFractions ? '⅛' : '1/8');
62
-
63
- case 0.25:
64
- return "" + sFloorFinal + (useVulgarFractions ? '¼' : '1/4');
65
-
66
- case 0.375:
67
- return "" + sFloorFinal + (useVulgarFractions ? '⅜' : '3/8');
68
-
69
- case 0.5:
70
- return "" + sFloorFinal + (useVulgarFractions ? '½' : '1/2');
71
-
72
- case 0.625:
73
- return "" + sFloorFinal + (useVulgarFractions ? '⅝' : '5/8');
74
-
75
- case 0.75:
76
- return "" + sFloorFinal + (useVulgarFractions ? '¾' : '3/4');
77
-
78
- case 0.875:
79
- return "" + sFloorFinal + (useVulgarFractions ? '⅞' : '7/8');
80
- }
81
- }
82
-
83
- return "" + dQty;
84
- }
85
-
86
- return formatQuantity;
87
-
88
- })));
89
- //# sourceMappingURL=format-quantity.umd.development.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"format-quantity.umd.development.js","sources":["../src/index.ts"],"sourcesContent":["/**\n * Determines if two numbers are close enough to consider\n * them equal for our purposes\n */\nconst closeEnough = (a: number, b: number) => Math.abs(a - b) < 0.009;\n\n/**\n * Formats a number (or string that appears to be a number)\n * as one would see it written in imperial measurements, e.g.\n * \"1 1/2\" instead of \"1.5\". To use vulgar fractions, e.g. \"½\",\n * pass `true` as the second argument.\n */\nfunction formatQuantity(qty: string | number, useVulgarFractions?: boolean) {\n const dQty = typeof qty === 'string' ? parseFloat(qty) : qty;\n\n // Bomb out if not a number\n if (isNaN(dQty) || dQty === null) {\n return null;\n }\n\n // Return an empty string if the value is zero\n if (dQty === 0) {\n return '';\n }\n\n const dQtyAbs = Math.abs(dQty);\n const iFloor = Math.floor(dQtyAbs);\n const sFloor = iFloor === 0.0 ? '' : `${dQty < 0 ? '-' : ''}${iFloor} `;\n const dDecimal = dQtyAbs - iFloor;\n\n // Handle integers first. Just return the given value as a string.\n if (dDecimal === 0) {\n return `${dQty}`;\n }\n\n const sFloorFinal = useVulgarFractions ? sFloor.trim() : sFloor;\n\n // Handle infinitely repeating decimals next, since\n // we'll never get an exact match for a switch case:\n if (closeEnough(dDecimal, 0.33)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅓' : '1/3'}`;\n } else if (closeEnough(dDecimal, 0.66)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅔' : '2/3'}`;\n } else if (closeEnough(dDecimal, 0.2)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅕' : '1/5'}`;\n } else if (closeEnough(dDecimal, 0.4)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅖' : '2/5'}`;\n } else if (closeEnough(dDecimal, 0.6)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅗' : '3/5'}`;\n } else if (closeEnough(dDecimal, 0.8)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅘' : '4/5'}`;\n } else {\n switch (dDecimal) {\n case 0.125:\n return `${sFloorFinal}${useVulgarFractions ? '⅛' : '1/8'}`;\n case 0.25:\n return `${sFloorFinal}${useVulgarFractions ? '¼' : '1/4'}`;\n case 0.375:\n return `${sFloorFinal}${useVulgarFractions ? '⅜' : '3/8'}`;\n case 0.5:\n return `${sFloorFinal}${useVulgarFractions ? '½' : '1/2'}`;\n case 0.625:\n return `${sFloorFinal}${useVulgarFractions ? '⅝' : '5/8'}`;\n case 0.75:\n return `${sFloorFinal}${useVulgarFractions ? '¾' : '3/4'}`;\n case 0.875:\n return `${sFloorFinal}${useVulgarFractions ? '⅞' : '7/8'}`;\n }\n }\n\n return `${dQty}`;\n}\n\nexport default formatQuantity;\n"],"names":["closeEnough","a","b","Math","abs","formatQuantity","qty","useVulgarFractions","dQty","parseFloat","isNaN","dQtyAbs","iFloor","floor","sFloor","dDecimal","sFloorFinal","trim"],"mappings":";;;;;;EAAA;;;;EAIA,IAAMA,WAAW,GAAG,SAAdA,WAAc,CAACC,CAAD,EAAYC,CAAZ;EAAA,SAA0BC,IAAI,CAACC,GAAL,CAASH,CAAC,GAAGC,CAAb,IAAkB,KAA5C;EAAA,CAApB;EAEA;;;;;;;;EAMA,SAASG,cAAT,CAAwBC,GAAxB,EAA8CC,kBAA9C;EACE,MAAMC,IAAI,GAAG,OAAOF,GAAP,KAAe,QAAf,GAA0BG,UAAU,CAACH,GAAD,CAApC,GAA4CA,GAAzD;;EAGA,MAAII,KAAK,CAACF,IAAD,CAAL,IAAeA,IAAI,KAAK,IAA5B,EAAkC;EAChC,WAAO,IAAP;EACD;;;EAGD,MAAIA,IAAI,KAAK,CAAb,EAAgB;EACd,WAAO,EAAP;EACD;;EAED,MAAMG,OAAO,GAAGR,IAAI,CAACC,GAAL,CAASI,IAAT,CAAhB;EACA,MAAMI,MAAM,GAAGT,IAAI,CAACU,KAAL,CAAWF,OAAX,CAAf;EACA,MAAMG,MAAM,GAAGF,MAAM,KAAK,GAAX,GAAiB,EAAjB,SAAyBJ,IAAI,GAAG,CAAP,GAAW,GAAX,GAAiB,EAA1C,IAA+CI,MAA/C,MAAf;EACA,MAAMG,QAAQ,GAAGJ,OAAO,GAAGC,MAA3B;;EAGA,MAAIG,QAAQ,KAAK,CAAjB,EAAoB;EAClB,gBAAUP,IAAV;EACD;;EAED,MAAMQ,WAAW,GAAGT,kBAAkB,GAAGO,MAAM,CAACG,IAAP,EAAH,GAAmBH,MAAzD;EAGA;;EACA,MAAId,WAAW,CAACe,QAA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,GAAH,GAAS,KAAnD;;EACF,WAAK,KAAL;EACE,oBAAUS,WAAV,IAAwBT,kBAAkB,GAAG,GAAH,GAAS,KAAnD;EAdJ;EAgBD;;EAED,cAAUC,IAAV;EACD;;;;;;;;"}
@@ -1,2 +0,0 @@
1
- !function(r,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(r=r||self).formatQuantity=e()}(this,(function(){"use strict";var r=function(r,e){return Math.abs(r-e)<.009};return function(e,t){var n="string"==typeof e?parseFloat(e):e;if(isNaN(n)||null===n)return null;if(0===n)return"";var u=Math.abs(n),f=Math.floor(u),i=0===f?"":(n<0?"-":"")+f+" ",a=u-f;if(0===a)return""+n;var s=t?i.trim():i;if(r(a,.33))return s+(t?"⅓":"1/3");if(r(a,.66))return s+(t?"⅔":"2/3");if(r(a,.2))return s+(t?"⅕":"1/5");if(r(a,.4))return s+(t?"⅖":"2/5");if(r(a,.6))return s+(t?"⅗":"3/5");if(r(a,.8))return s+(t?"⅘":"4/5");switch(a){case.125:return s+(t?"⅛":"1/8");case.25:return s+(t?"¼":"1/4");case.375:return s+(t?"⅜":"3/8");case.5:return s+(t?"½":"1/2");case.625:return s+(t?"⅝":"5/8");case.75:return s+(t?"¾":"3/4");case.875:return s+(t?"⅞":"7/8")}return""+n}}));
2
- //# sourceMappingURL=format-quantity.umd.production.min.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"format-quantity.umd.production.min.js","sources":["../src/index.ts"],"sourcesContent":["/**\n * Determines if two numbers are close enough to consider\n * them equal for our purposes\n */\nconst closeEnough = (a: number, b: number) => Math.abs(a - b) < 0.009;\n\n/**\n * Formats a number (or string that appears to be a number)\n * as one would see it written in imperial measurements, e.g.\n * \"1 1/2\" instead of \"1.5\". To use vulgar fractions, e.g. \"½\",\n * pass `true` as the second argument.\n */\nfunction formatQuantity(qty: string | number, useVulgarFractions?: boolean) {\n const dQty = typeof qty === 'string' ? parseFloat(qty) : qty;\n\n // Bomb out if not a number\n if (isNaN(dQty) || dQty === null) {\n return null;\n }\n\n // Return an empty string if the value is zero\n if (dQty === 0) {\n return '';\n }\n\n const dQtyAbs = Math.abs(dQty);\n const iFloor = Math.floor(dQtyAbs);\n const sFloor = iFloor === 0.0 ? '' : `${dQty < 0 ? '-' : ''}${iFloor} `;\n const dDecimal = dQtyAbs - iFloor;\n\n // Handle integers first. Just return the given value as a string.\n if (dDecimal === 0) {\n return `${dQty}`;\n }\n\n const sFloorFinal = useVulgarFractions ? sFloor.trim() : sFloor;\n\n // Handle infinitely repeating decimals next, since\n // we'll never get an exact match for a switch case:\n if (closeEnough(dDecimal, 0.33)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅓' : '1/3'}`;\n } else if (closeEnough(dDecimal, 0.66)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅔' : '2/3'}`;\n } else if (closeEnough(dDecimal, 0.2)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅕' : '1/5'}`;\n } else if (closeEnough(dDecimal, 0.4)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅖' : '2/5'}`;\n } else if (closeEnough(dDecimal, 0.6)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅗' : '3/5'}`;\n } else if (closeEnough(dDecimal, 0.8)) {\n return `${sFloorFinal}${useVulgarFractions ? '⅘' : '4/5'}`;\n } else {\n switch (dDecimal) {\n case 0.125:\n return `${sFloorFinal}${useVulgarFractions ? '⅛' : '1/8'}`;\n case 0.25:\n return `${sFloorFinal}${useVulgarFractions ? '¼' : '1/4'}`;\n case 0.375:\n return `${sFloorFinal}${useVulgarFractions ? '⅜' : '3/8'}`;\n case 0.5:\n return `${sFloorFinal}${useVulgarFractions ? '½' : '1/2'}`;\n case 0.625:\n return `${sFloorFinal}${useVulgarFractions ? '⅝' : '5/8'}`;\n case 0.75:\n return `${sFloorFinal}${useVulgarFractions ? '¾' : '3/4'}`;\n case 0.875:\n return `${sFloorFinal}${useVulgarFractions ? '⅞' : '7/8'}`;\n }\n }\n\n return `${dQty}`;\n}\n\nexport default formatQuantity;\n"],"names":["closeEnough","a","b","Math","abs","qty","useVulgarFractions","dQty","parseFloat","isNaN","dQtyAbs","iFloor","floor","sFloor","dDecimal","sFloorFinal","trim"],"mappings":"qMAIA,IAAMA,EAAc,SAACC,EAAWC,UAAcC,KAAKC,IAAIH,EAAIC,GAAK,aAQhE,SAAwBG,EAAsBC,OACtCC,EAAsB,iBAARF,EAAmBG,WAAWH,GAAOA,KAGrDI,MAAMF,IAAkB,OAATA,SACV,QAII,IAATA,QACK,OAGHG,EAAUP,KAAKC,IAAIG,GACnBI,EAASR,KAAKS,MAAMF,GACpBG,EAAoB,IAAXF,EAAiB,IAAQJ,EAAO,EAAI,IAAM,IAAKI,MACxDG,EAAWJ,EAAUC,KAGV,IAAbG,WACQP,MAGNQ,EAAcT,EAAqBO,EAAOG,OAASH,KAIrDb,EAAYc,EAAU,YACdC,GAAcT,EAAqB,IAAM,OAC9C,GAAIN,EAAYc,EAAU,YACrBC,GAAcT,EAAqB,IAAM,OAC9C,GAAIN,EAAYc,EAAU,WACrBC,GAAcT,EAAqB,IAAM,OAC9C,GAAIN,EAAYc,EAAU,WACrBC,GAAcT,EAAqB,IAAM,OAC9C,GAAIN,EAAYc,EAAU,WACrBC,GAAcT,EAAqB,IAAM,OAC9C,GAAIN,EAAYc,EAAU,WACrBC,GAAcT,EAAqB,IAAM,cAE3CQ,OACD,YACOC,GAAcT,EAAqB,IAAM,WAChD,WACOS,GAAcT,EAAqB,IAAM,WAChD,YACOS,GAAcT,EAAqB,IAAM,WAChD,UACOS,GAAcT,EAAqB,IAAM,WAChD,YACOS,GAAcT,EAAqB,IAAM,WAChD,WACOS,GAAcT,EAAqB,IAAM,WAChD,YACOS,GAAcT,EAAqB,IAAM,gBAI/CC"}
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('./format-quantity.cjs.production.min.js')
6
- } else {
7
- module.exports = require('./format-quantity.cjs.development.js')
8
- }