@molopos/shared 2.0.26 → 2.0.28

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/enum/index.d.ts CHANGED
@@ -36,12 +36,14 @@ export declare enum ProductTypeEnum {
36
36
  * Query type enum
37
37
  */
38
38
  export declare enum QueryTypeEnum {
39
+ Task = "TASK",
39
40
  Unit = "UNIT",
40
41
  Post = "POST",
41
42
  Shop = "SHOP",
42
43
  Brand = "BRAND",
43
44
  Order = "ORDER",
44
45
  Quote = "QUOTE",
46
+ Section = "SECTION",
45
47
  Message = "MESSAGE",
46
48
  Catalog = "CATALOG",
47
49
  Product = "PRODUCT",
@@ -50,22 +52,21 @@ export declare enum QueryTypeEnum {
50
52
  Expense = "EXPENSE",
51
53
  Profile = "PROFILE",
52
54
  Variant = "VARIANT",
55
+ Project = "PROJECT",
56
+ Pipeline = "PIPELINE",
57
+ Customer = "CUSTOMER",
53
58
  Checkout = "CHECKOUT",
54
59
  Category = "CATEGORY",
60
+ Discount = "DISCOUNT",
55
61
  Warehouse = "WAREHOUSE",
56
62
  OrderItem = "ORDERITEM",
57
63
  QuoteItem = "QUOTEITEM",
58
64
  QuoteOption = "QUOTEOPTION",
59
- Section = "SECTION",
60
- Discount = "DISCOUNT",
61
- Project = "PROJECT",
62
65
  UserAddress = "USERADDRESS",
63
66
  Subcategory = "SUBCATEGORY",
64
67
  ExpenseItem = "EXPENSEITEM",
65
68
  Organization = "ORGANIZATION",
66
- ApplicationSection = "APPLICATIONSECTION",
67
- Task = "TASK",
68
- Pipeline = "PIPELINE"
69
+ ApplicationSection = "APPLICATIONSECTION"
69
70
  }
70
71
  /**
71
72
  * Activity model enum
package/enum/index.js CHANGED
@@ -44,12 +44,14 @@ var ProductTypeEnum;
44
44
  */
45
45
  var QueryTypeEnum;
46
46
  (function (QueryTypeEnum) {
47
+ QueryTypeEnum["Task"] = "TASK";
47
48
  QueryTypeEnum["Unit"] = "UNIT";
48
49
  QueryTypeEnum["Post"] = "POST";
49
50
  QueryTypeEnum["Shop"] = "SHOP";
50
51
  QueryTypeEnum["Brand"] = "BRAND";
51
52
  QueryTypeEnum["Order"] = "ORDER";
52
53
  QueryTypeEnum["Quote"] = "QUOTE";
54
+ QueryTypeEnum["Section"] = "SECTION";
53
55
  QueryTypeEnum["Message"] = "MESSAGE";
54
56
  QueryTypeEnum["Catalog"] = "CATALOG";
55
57
  QueryTypeEnum["Product"] = "PRODUCT";
@@ -58,22 +60,21 @@ var QueryTypeEnum;
58
60
  QueryTypeEnum["Expense"] = "EXPENSE";
59
61
  QueryTypeEnum["Profile"] = "PROFILE";
60
62
  QueryTypeEnum["Variant"] = "VARIANT";
63
+ QueryTypeEnum["Project"] = "PROJECT";
64
+ QueryTypeEnum["Pipeline"] = "PIPELINE";
65
+ QueryTypeEnum["Customer"] = "CUSTOMER";
61
66
  QueryTypeEnum["Checkout"] = "CHECKOUT";
62
67
  QueryTypeEnum["Category"] = "CATEGORY";
68
+ QueryTypeEnum["Discount"] = "DISCOUNT";
63
69
  QueryTypeEnum["Warehouse"] = "WAREHOUSE";
64
70
  QueryTypeEnum["OrderItem"] = "ORDERITEM";
65
71
  QueryTypeEnum["QuoteItem"] = "QUOTEITEM";
66
72
  QueryTypeEnum["QuoteOption"] = "QUOTEOPTION";
67
- QueryTypeEnum["Section"] = "SECTION";
68
- QueryTypeEnum["Discount"] = "DISCOUNT";
69
- QueryTypeEnum["Project"] = "PROJECT";
70
73
  QueryTypeEnum["UserAddress"] = "USERADDRESS";
71
74
  QueryTypeEnum["Subcategory"] = "SUBCATEGORY";
72
75
  QueryTypeEnum["ExpenseItem"] = "EXPENSEITEM";
73
76
  QueryTypeEnum["Organization"] = "ORGANIZATION";
74
77
  QueryTypeEnum["ApplicationSection"] = "APPLICATIONSECTION";
75
- QueryTypeEnum["Task"] = "TASK";
76
- QueryTypeEnum["Pipeline"] = "PIPELINE";
77
78
  })(QueryTypeEnum || (exports.QueryTypeEnum = QueryTypeEnum = {}));
78
79
  /**
79
80
  * Activity model enum
@@ -1,10 +1,46 @@
1
+ /**
2
+ * @example
3
+ * fromCents(2300) // 23
4
+ */
1
5
  export declare const fromCents: (value: number | string) => number;
6
+ /**
7
+ * @example
8
+ * toCents(23) // 2300
9
+ */
2
10
  export declare const toCents: (value: number | string) => number;
11
+ /**
12
+ * @example
13
+ * calculVat({ value: 2300, percentage: 20 }) // 460
14
+ */
3
15
  export declare const calculVat: ({ value, percentage, }: {
4
16
  value: number;
5
17
  percentage: number;
6
18
  }) => number;
19
+ /**
20
+ * @example
21
+ * calculDiscount({ value: 2300, percentage: 20 }) // 460
22
+ */
7
23
  export declare const calculDiscount: ({ value, percentage, }: {
8
24
  value: number;
9
25
  percentage: number;
10
26
  }) => number;
27
+ interface Props {
28
+ value: number;
29
+ isDivide?: boolean;
30
+ currency: string;
31
+ locale?: string;
32
+ }
33
+ /**
34
+ * @example
35
+ * formatePrice({ value: 2300, currency: 'EUR', locale: 'fr' }) // 23.00 €
36
+ */
37
+ export declare const formatePrice: ({ value, currency, locale, isDivide, }: Props) => string;
38
+ /**
39
+ * @example
40
+ * formatPercent({ value: 20, locale: 'fr' }) // 20%
41
+ */
42
+ export declare const formatPercent: ({ value, locale, }: {
43
+ value: number;
44
+ locale: string;
45
+ }) => string;
46
+ export {};
@@ -1,11 +1,56 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.calculDiscount = exports.calculVat = exports.toCents = exports.fromCents = void 0;
3
+ exports.formatPercent = exports.formatePrice = exports.calculDiscount = exports.calculVat = exports.toCents = exports.fromCents = void 0;
4
+ /**
5
+ * @example
6
+ * fromCents(2300) // 23
7
+ */
4
8
  const fromCents = (value) => Number(value) / 100;
5
9
  exports.fromCents = fromCents;
10
+ /**
11
+ * @example
12
+ * toCents(23) // 2300
13
+ */
6
14
  const toCents = (value) => Number(value) * 100;
7
15
  exports.toCents = toCents;
16
+ /**
17
+ * @example
18
+ * calculVat({ value: 2300, percentage: 20 }) // 460
19
+ */
8
20
  const calculVat = ({ value, percentage, }) => (percentage > 0 ? value * (0, exports.fromCents)(percentage) : 0);
9
21
  exports.calculVat = calculVat;
22
+ /**
23
+ * @example
24
+ * calculDiscount({ value: 2300, percentage: 20 }) // 460
25
+ */
10
26
  const calculDiscount = ({ value, percentage, }) => (percentage > 0 ? (0, exports.fromCents)(value * percentage) : 0);
11
27
  exports.calculDiscount = calculDiscount;
28
+ /**
29
+ * @example
30
+ * formatePrice({ value: 2300, currency: 'EUR', locale: 'fr' }) // 23.00 €
31
+ */
32
+ const formatePrice = ({ value, currency, locale = "en", isDivide = false, }) => {
33
+ if (isNaN(value))
34
+ return "—";
35
+ const numberCal = isDivide ? (0, exports.fromCents)(value) : value;
36
+ const lang = ["fr", "it"].includes(locale.toLowerCase()) ? "de" : locale;
37
+ return new Intl.NumberFormat(lang, {
38
+ currency,
39
+ style: "currency",
40
+ notation: "standard",
41
+ maximumFractionDigits: 1,
42
+ }).format(numberCal);
43
+ };
44
+ exports.formatePrice = formatePrice;
45
+ /**
46
+ * @example
47
+ * formatPercent({ value: 20, locale: 'fr' }) // 20%
48
+ */
49
+ const formatPercent = ({ value, locale, }) => {
50
+ return new Intl.NumberFormat(locale, {
51
+ style: "percent",
52
+ notation: "standard",
53
+ maximumFractionDigits: 1,
54
+ }).format(value / 100);
55
+ };
56
+ exports.formatPercent = formatPercent;
@@ -22,4 +22,12 @@ describe("Utils", () => {
22
22
  expect(result).toEqual(20);
23
23
  expect(result).not.toBeNull();
24
24
  });
25
+ test("formatePrice", () => {
26
+ const result = (0, index_1.formatePrice)({ value: 2, currency: "EUR", locale: "fr" });
27
+ expect(result.toString()).not.toBeNull();
28
+ });
29
+ test("formatPercent", () => {
30
+ const result = (0, index_1.formatPercent)({ value: 20, locale: "fr" });
31
+ expect(result).not.toBeNull();
32
+ });
25
33
  });
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@molopos/shared","publishConfig":{"access":"public"},"version":"2.0.26","description":"Shared between backend and frontend repos","license":"ISC","repository":{"type":"git","url":"https://github.com/unicubate/molopos-shared.git"},"dependencies":{"date-fns":"^4.1.0","luxon":"^3.7.2"}}
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"}}