@8ms/helpers 2.3.45 → 2.3.46
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/number/index.d.mts +3 -3
- package/dist/number/index.mjs +9 -15
- package/package.json +1 -1
package/dist/number/index.d.mts
CHANGED
|
@@ -2,20 +2,20 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Take a given number and format as a compact number.
|
|
4
4
|
*/
|
|
5
|
-
declare const formatCompact: (input: any,
|
|
5
|
+
declare const formatCompact: (input: any, minDp?: number, maxDp?: number) => string;
|
|
6
6
|
//#endregion
|
|
7
7
|
//#region src/number/formatCurrency.d.ts
|
|
8
8
|
/**
|
|
9
9
|
* Use the International number formatting to return the currency value.
|
|
10
10
|
* https://www.freecodecamp.org/news/how-to-format-number-as-currency-in-javascript-one-line-of-code/
|
|
11
11
|
*/
|
|
12
|
-
declare const formatCurrency: (input: any, currency?: string,
|
|
12
|
+
declare const formatCurrency: (input: any, currency?: string, minDp?: number, maxDp?: number) => string;
|
|
13
13
|
//#endregion
|
|
14
14
|
//#region src/number/formatStandard.d.ts
|
|
15
15
|
/**
|
|
16
16
|
* Take a given number and format it.
|
|
17
17
|
*/
|
|
18
|
-
declare const formatStandard: (input: any,
|
|
18
|
+
declare const formatStandard: (input: any, minDp?: number, maxDp?: number) => string;
|
|
19
19
|
//#endregion
|
|
20
20
|
//#region src/number/getDecimal.d.ts
|
|
21
21
|
/**
|
package/dist/number/index.mjs
CHANGED
|
@@ -4,13 +4,11 @@ import { n as getNumber, t as getDecimal } from "../getDecimal-CafxtLhH.mjs";
|
|
|
4
4
|
/**
|
|
5
5
|
* Take a given number and format as a compact number.
|
|
6
6
|
*/
|
|
7
|
-
const formatCompact = (input,
|
|
7
|
+
const formatCompact = (input, minDp, maxDp) => {
|
|
8
8
|
const inputValue = getNumber(input);
|
|
9
|
-
const maximumDp = maxDp ?? 2;
|
|
10
|
-
const minimumDp = minDp ?? maxDp;
|
|
11
9
|
return Intl.NumberFormat(void 0, {
|
|
12
|
-
minimumFractionDigits:
|
|
13
|
-
maximumFractionDigits:
|
|
10
|
+
minimumFractionDigits: minDp || 0,
|
|
11
|
+
maximumFractionDigits: maxDp || minDp || 0,
|
|
14
12
|
notation: "compact"
|
|
15
13
|
}).format(inputValue);
|
|
16
14
|
};
|
|
@@ -21,16 +19,14 @@ const formatCompact = (input, maxDp, minDp) => {
|
|
|
21
19
|
* Use the International number formatting to return the currency value.
|
|
22
20
|
* https://www.freecodecamp.org/news/how-to-format-number-as-currency-in-javascript-one-line-of-code/
|
|
23
21
|
*/
|
|
24
|
-
const formatCurrency = (input, currency = "GBP",
|
|
22
|
+
const formatCurrency = (input, currency = "GBP", minDp, maxDp) => {
|
|
25
23
|
const value = Number(input);
|
|
26
24
|
const currencyClean = currency.toUpperCase().trim();
|
|
27
|
-
const maximumDp = maxDp ?? 2;
|
|
28
|
-
const minimumDp = minDp ?? maxDp;
|
|
29
25
|
let formatted = new Intl.NumberFormat(void 0, {
|
|
30
26
|
style: "currency",
|
|
31
27
|
currency: currencyClean,
|
|
32
|
-
minimumFractionDigits:
|
|
33
|
-
maximumFractionDigits:
|
|
28
|
+
minimumFractionDigits: minDp || 0,
|
|
29
|
+
maximumFractionDigits: maxDp || minDp || 0
|
|
34
30
|
}).format(value);
|
|
35
31
|
if ("USD" === currencyClean) formatted = formatted.replace("US$", "$");
|
|
36
32
|
return formatted;
|
|
@@ -41,13 +37,11 @@ const formatCurrency = (input, currency = "GBP", maxDp, minDp) => {
|
|
|
41
37
|
/**
|
|
42
38
|
* Take a given number and format it.
|
|
43
39
|
*/
|
|
44
|
-
const formatStandard = (input,
|
|
40
|
+
const formatStandard = (input, minDp, maxDp) => {
|
|
45
41
|
const inputValue = getNumber(input);
|
|
46
|
-
const maximumDp = maxDp ?? 0;
|
|
47
|
-
const minimumDp = minDp ?? maxDp;
|
|
48
42
|
return Intl.NumberFormat(void 0, {
|
|
49
|
-
minimumFractionDigits:
|
|
50
|
-
maximumFractionDigits:
|
|
43
|
+
minimumFractionDigits: minDp || 0,
|
|
44
|
+
maximumFractionDigits: maxDp || minDp || 0,
|
|
51
45
|
notation: "standard"
|
|
52
46
|
}).format(inputValue);
|
|
53
47
|
};
|