@ancon/wildcat-utils 1.43.0 → 1.43.1

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.
@@ -24,6 +24,11 @@ declare type Options = {
24
24
  * @default true
25
25
  */
26
26
  onlyShowAsManyDecimalsAsNeededWhenZeroInt?: boolean;
27
+ /**
28
+ * Whether or not to show the currency postfix, formatted or not
29
+ * @default true
30
+ */
31
+ showCurrencyPostfix?: boolean;
27
32
  };
28
33
  /**
29
34
  * Formats the given monetary value
@@ -1 +1 @@
1
- "use strict";const y=require("./getFormattedCurrencyPostfix.js");function a(l=0,N="SEK",e=!0){let d=0;const c=typeof e=="object"?{formatPostfix:(e==null?void 0:e.formatPostfix)??!0,trimTrailingZeros:(e==null?void 0:e.trimTrailingZeros)??!0,showAsManyDecimalsAsNeeded:(e==null?void 0:e.showAsManyDecimalsAsNeeded)??!1,maxAsManyDecimalsAsNeeded:(e==null?void 0:e.maxAsManyDecimalsAsNeeded)??8,onlyShowAsManyDecimalsAsNeededWhenZeroInt:(e==null?void 0:e.onlyShowAsManyDecimalsAsNeededWhenZeroInt)??!0}:{formatPostfix:e,trimTrailingZeros:!0,showAsManyDecimalsAsNeeded:!1,maxAsManyDecimalsAsNeeded:8,onlyShowAsManyDecimalsAsNeededWhenZeroInt:!0};if(!l||Number.isNaN(Number(l)))d=0;else if(c.trimTrailingZeros&&Number.isInteger(Number(l)))d=l;else if(c.showAsManyDecimalsAsNeeded){d=Number(l).toFixed(c.maxAsManyDecimalsAsNeeded);const[n,s]=d.split("."),A=s!=null&&s.length>2?s.replace(/0+$/,""):s;(c.onlyShowAsManyDecimalsAsNeededWhenZeroInt?n==="0":!0)&&n!=null&&A!=null&&A.length>2?d=`${n}.${A}`:d=Number(l).toFixed(2)}else d=Number(l).toFixed(2),c.trimTrailingZeros&&d.endsWith(".00")&&(d=Number.parseInt(d,10).toString());const u=c.formatPostfix?y(N):N;return`${d} ${u}`}module.exports=a;
1
+ "use strict";const N=require("./getFormattedCurrencyPostfix.js");function h(d=0,A="SEK",e=!0){let l=0;const c=typeof e=="object"?{formatPostfix:(e==null?void 0:e.formatPostfix)??!0,trimTrailingZeros:(e==null?void 0:e.trimTrailingZeros)??!0,showAsManyDecimalsAsNeeded:(e==null?void 0:e.showAsManyDecimalsAsNeeded)??!1,maxAsManyDecimalsAsNeeded:(e==null?void 0:e.maxAsManyDecimalsAsNeeded)??8,onlyShowAsManyDecimalsAsNeededWhenZeroInt:(e==null?void 0:e.onlyShowAsManyDecimalsAsNeededWhenZeroInt)??!0,showCurrencyPostfix:(e==null?void 0:e.showCurrencyPostfix)??!0}:{formatPostfix:e,trimTrailingZeros:!0,showAsManyDecimalsAsNeeded:!1,maxAsManyDecimalsAsNeeded:8,onlyShowAsManyDecimalsAsNeededWhenZeroInt:!0,showCurrencyPostfix:!0};if(!d||Number.isNaN(Number(d)))l=0;else if(c.trimTrailingZeros&&Number.isInteger(Number(d)))l=d;else if(c.showAsManyDecimalsAsNeeded){l=Number(d).toFixed(c.maxAsManyDecimalsAsNeeded);const[u,s]=l.split("."),n=s!=null&&s.length>2?s.replace(/0+$/,""):s;(c.onlyShowAsManyDecimalsAsNeededWhenZeroInt?u==="0":!0)&&u!=null&&n!=null&&n.length>2?l=`${u}.${n}`:l=Number(d).toFixed(2)}else l=Number(d).toFixed(2),c.trimTrailingZeros&&l.endsWith(".00")&&(l=Number.parseInt(l,10).toString());if(c.showCurrencyPostfix===!1)return`${l}`;const y=c.formatPostfix?N(A):A;return`${l} ${y}`}module.exports=h;
@@ -1,32 +1,36 @@
1
- import y from "./getFormattedCurrencyPostfix.mjs";
2
- function m(l = 0, N = "SEK", e = !0) {
3
- let d = 0;
4
- const A = typeof e == "object" ? {
1
+ import N from "./getFormattedCurrencyPostfix.mjs";
2
+ function D(d = 0, s = "SEK", e = !0) {
3
+ let l = 0;
4
+ const c = typeof e == "object" ? {
5
5
  formatPostfix: (e == null ? void 0 : e.formatPostfix) ?? !0,
6
6
  trimTrailingZeros: (e == null ? void 0 : e.trimTrailingZeros) ?? !0,
7
7
  showAsManyDecimalsAsNeeded: (e == null ? void 0 : e.showAsManyDecimalsAsNeeded) ?? !1,
8
8
  maxAsManyDecimalsAsNeeded: (e == null ? void 0 : e.maxAsManyDecimalsAsNeeded) ?? 8,
9
- onlyShowAsManyDecimalsAsNeededWhenZeroInt: (e == null ? void 0 : e.onlyShowAsManyDecimalsAsNeededWhenZeroInt) ?? !0
9
+ onlyShowAsManyDecimalsAsNeededWhenZeroInt: (e == null ? void 0 : e.onlyShowAsManyDecimalsAsNeededWhenZeroInt) ?? !0,
10
+ showCurrencyPostfix: (e == null ? void 0 : e.showCurrencyPostfix) ?? !0
10
11
  } : {
11
12
  formatPostfix: e,
12
13
  trimTrailingZeros: !0,
13
14
  showAsManyDecimalsAsNeeded: !1,
14
15
  maxAsManyDecimalsAsNeeded: 8,
15
- onlyShowAsManyDecimalsAsNeededWhenZeroInt: !0
16
+ onlyShowAsManyDecimalsAsNeededWhenZeroInt: !0,
17
+ showCurrencyPostfix: !0
16
18
  };
17
- if (!l || Number.isNaN(Number(l)))
18
- d = 0;
19
- else if (A.trimTrailingZeros && Number.isInteger(Number(l)))
20
- d = l;
21
- else if (A.showAsManyDecimalsAsNeeded) {
22
- d = Number(l).toFixed(A.maxAsManyDecimalsAsNeeded);
23
- const [c, s] = d.split("."), n = s != null && s.length > 2 ? s.replace(/0+$/, "") : s;
24
- (A.onlyShowAsManyDecimalsAsNeededWhenZeroInt ? c === "0" : !0) && c != null && n != null && n.length > 2 ? d = `${c}.${n}` : d = Number(l).toFixed(2);
19
+ if (!d || Number.isNaN(Number(d)))
20
+ l = 0;
21
+ else if (c.trimTrailingZeros && Number.isInteger(Number(d)))
22
+ l = d;
23
+ else if (c.showAsManyDecimalsAsNeeded) {
24
+ l = Number(d).toFixed(c.maxAsManyDecimalsAsNeeded);
25
+ const [u, A] = l.split("."), n = A != null && A.length > 2 ? A.replace(/0+$/, "") : A;
26
+ (c.onlyShowAsManyDecimalsAsNeededWhenZeroInt ? u === "0" : !0) && u != null && n != null && n.length > 2 ? l = `${u}.${n}` : l = Number(d).toFixed(2);
25
27
  } else
26
- d = Number(l).toFixed(2), A.trimTrailingZeros && d.endsWith(".00") && (d = Number.parseInt(d, 10).toString());
27
- const a = A.formatPostfix ? y(N) : N;
28
- return `${d} ${a}`;
28
+ l = Number(d).toFixed(2), c.trimTrailingZeros && l.endsWith(".00") && (l = Number.parseInt(l, 10).toString());
29
+ if (c.showCurrencyPostfix === !1)
30
+ return `${l}`;
31
+ const y = c.formatPostfix ? N(s) : s;
32
+ return `${l} ${y}`;
29
33
  }
30
34
  export {
31
- m as default
35
+ D as default
32
36
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ancon/wildcat-utils",
3
- "version": "1.43.0",
3
+ "version": "1.43.1",
4
4
  "private": false,
5
5
  "main": "index.js",
6
6
  "module": "index.mjs",