@molopos/shared 2.0.50 → 2.0.51
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/lib/utils/index.d.ts +2 -1
- package/lib/utils/index.js +2 -2
- package/lib/utils/index.test.js +5 -1
- package/package.json +1 -1
package/lib/utils/index.d.ts
CHANGED
|
@@ -29,12 +29,13 @@ interface Props {
|
|
|
29
29
|
isDivide?: boolean;
|
|
30
30
|
currency: string;
|
|
31
31
|
locale?: string;
|
|
32
|
+
maximumFractionDigits?: number;
|
|
32
33
|
}
|
|
33
34
|
/**
|
|
34
35
|
* @example
|
|
35
36
|
* formatePrice({ value: 2300, currency: 'EUR', locale: 'fr' }) // 23.00 €
|
|
36
37
|
*/
|
|
37
|
-
export declare const formatePrice: ({ value, currency, locale, isDivide, }: Props) => string;
|
|
38
|
+
export declare const formatePrice: ({ value, currency, locale, isDivide, maximumFractionDigits, }: Props) => string;
|
|
38
39
|
/**
|
|
39
40
|
* @example
|
|
40
41
|
* formatPercent({ value: 20, locale: 'fr' }) // 20%
|
package/lib/utils/index.js
CHANGED
|
@@ -30,7 +30,7 @@ exports.calculDiscount = calculDiscount;
|
|
|
30
30
|
* @example
|
|
31
31
|
* formatePrice({ value: 2300, currency: 'EUR', locale: 'fr' }) // 23.00 €
|
|
32
32
|
*/
|
|
33
|
-
const formatePrice = ({ value, currency, locale = "en", isDivide = false, }) => {
|
|
33
|
+
const formatePrice = ({ value, currency, locale = "en", isDivide = false, maximumFractionDigits = 3, }) => {
|
|
34
34
|
const newValue = isNaNumber(value);
|
|
35
35
|
const numberCal = isDivide ? (0, exports.fromCents)(newValue) : newValue;
|
|
36
36
|
const lang = ["fr", "it"].includes(locale.toLowerCase()) ? "de" : locale;
|
|
@@ -38,7 +38,7 @@ const formatePrice = ({ value, currency, locale = "en", isDivide = false, }) =>
|
|
|
38
38
|
currency,
|
|
39
39
|
style: "currency",
|
|
40
40
|
notation: "standard",
|
|
41
|
-
maximumFractionDigits
|
|
41
|
+
maximumFractionDigits,
|
|
42
42
|
}).format(numberCal);
|
|
43
43
|
};
|
|
44
44
|
exports.formatePrice = formatePrice;
|
package/lib/utils/index.test.js
CHANGED
|
@@ -23,7 +23,11 @@ describe("Utils", () => {
|
|
|
23
23
|
expect(result).not.toBeNull();
|
|
24
24
|
});
|
|
25
25
|
test("formatePrice", () => {
|
|
26
|
-
const result = (0, index_1.formatePrice)({
|
|
26
|
+
const result = (0, index_1.formatePrice)({
|
|
27
|
+
value: 205.35714285714286,
|
|
28
|
+
currency: "EUR",
|
|
29
|
+
locale: "fr",
|
|
30
|
+
});
|
|
27
31
|
expect(result.toString()).not.toBeNull();
|
|
28
32
|
});
|
|
29
33
|
test("formatPercent", () => {
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@molopos/shared","publishConfig":{"access":"public"},"version":"2.0.
|
|
1
|
+
{"name":"@molopos/shared","publishConfig":{"access":"public"},"version":"2.0.51","description":"Shared between backend and frontend repos","license":"ISC","repository":{"type":"git","url":"https://github.com/unicubate/molopos-shared.git"},"dependencies":{"class-transformer":"^0.5.1","date-fns":"^4.4.0","luxon":"^3.7.2"}}
|