@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
|
|
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
|
|
2
|
-
function
|
|
3
|
-
let
|
|
4
|
-
const
|
|
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 (!
|
|
18
|
-
|
|
19
|
-
else if (
|
|
20
|
-
|
|
21
|
-
else if (
|
|
22
|
-
|
|
23
|
-
const [
|
|
24
|
-
(
|
|
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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
35
|
+
D as default
|
|
32
36
|
};
|