@8ms/helpers 1.3.33 → 1.4.0
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/environment/isLocalhost.js +4 -1
- package/number/getCurrency.d.ts +10 -0
- package/number/getCurrency.js +20 -0
- package/package.json +1 -1
|
@@ -10,7 +10,10 @@ const isVercel_1 = __importDefault(require("./isVercel"));
|
|
|
10
10
|
*/
|
|
11
11
|
const isLocalhost = () => {
|
|
12
12
|
let response = false;
|
|
13
|
-
if (
|
|
13
|
+
if ('true' === process.env['IS_LOCAL']) {
|
|
14
|
+
response = true;
|
|
15
|
+
}
|
|
16
|
+
else if ((0, isAws_1.default)()) {
|
|
14
17
|
response = 'true' === process.env['AWS_SAM_LOCAL'];
|
|
15
18
|
}
|
|
16
19
|
else if ((0, isVercel_1.default)()) {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type GetCurrency = {
|
|
2
|
+
currency: string;
|
|
3
|
+
input: any;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Use the International number formatting to return the currency value.
|
|
7
|
+
* https://www.freecodecamp.org/news/how-to-format-number-as-currency-in-javascript-one-line-of-code/
|
|
8
|
+
*/
|
|
9
|
+
declare const getCurrency: ({ currency, input }: GetCurrency) => string;
|
|
10
|
+
export default getCurrency;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* Use the International number formatting to return the currency value.
|
|
5
|
+
* https://www.freecodecamp.org/news/how-to-format-number-as-currency-in-javascript-one-line-of-code/
|
|
6
|
+
*/
|
|
7
|
+
const getCurrency = ({ currency, input }) => {
|
|
8
|
+
const value = Number(input);
|
|
9
|
+
const currencyClean = currency.toUpperCase()
|
|
10
|
+
.trim();
|
|
11
|
+
let formatted = new Intl.NumberFormat('en-GB', {
|
|
12
|
+
style: 'currency',
|
|
13
|
+
currency: currencyClean,
|
|
14
|
+
}).format(value);
|
|
15
|
+
if ('USD' === currencyClean) {
|
|
16
|
+
formatted = formatted.replace('US$', '$');
|
|
17
|
+
}
|
|
18
|
+
return formatted;
|
|
19
|
+
};
|
|
20
|
+
exports.default = getCurrency;
|