@molopos/shared 2.0.28 → 2.0.29

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.
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.formatPercent = exports.formatePrice = exports.calculDiscount = exports.calculVat = exports.toCents = exports.fromCents = void 0;
4
+ const isNaNumber = (value) => (!isNaN(Number(value)) ? value : 0);
4
5
  /**
5
6
  * @example
6
7
  * fromCents(2300) // 23
@@ -30,9 +31,8 @@ exports.calculDiscount = calculDiscount;
30
31
  * formatePrice({ value: 2300, currency: 'EUR', locale: 'fr' }) // 23.00 €
31
32
  */
32
33
  const formatePrice = ({ value, currency, locale = "en", isDivide = false, }) => {
33
- if (isNaN(value))
34
- return "—";
35
- const numberCal = isDivide ? (0, exports.fromCents)(value) : value;
34
+ const newValue = isNaNumber(value);
35
+ const numberCal = isDivide ? (0, exports.fromCents)(newValue) : newValue;
36
36
  const lang = ["fr", "it"].includes(locale.toLowerCase()) ? "de" : locale;
37
37
  return new Intl.NumberFormat(lang, {
38
38
  currency,
@@ -47,10 +47,12 @@ exports.formatePrice = formatePrice;
47
47
  * formatPercent({ value: 20, locale: 'fr' }) // 20%
48
48
  */
49
49
  const formatPercent = ({ value, locale, }) => {
50
- return new Intl.NumberFormat(locale, {
50
+ const newValue = isNaNumber(value);
51
+ const result = new Intl.NumberFormat(locale, {
51
52
  style: "percent",
52
53
  notation: "standard",
53
54
  maximumFractionDigits: 1,
54
- }).format(value / 100);
55
+ }).format(newValue / 100);
56
+ return result;
55
57
  };
56
58
  exports.formatPercent = formatPercent;
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@molopos/shared","publishConfig":{"access":"public"},"version":"2.0.28","description":"Shared between backend and frontend repos","license":"ISC","repository":{"type":"git","url":"https://github.com/unicubate/molopos-shared.git"},"dependencies":{"date-fns":"^4.3.0","luxon":"^3.7.2"}}
1
+ {"name":"@molopos/shared","publishConfig":{"access":"public"},"version":"2.0.29","description":"Shared between backend and frontend repos","license":"ISC","repository":{"type":"git","url":"https://github.com/unicubate/molopos-shared.git"},"dependencies":{"date-fns":"^4.3.0","luxon":"^3.7.2"}}