@megha-ui/react 1.2.76 → 1.2.77

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.
@@ -11,6 +11,11 @@ const formatDate = (date, locale = "sv-SE", options = {}) => {
11
11
  const formatter = new Intl.DateTimeFormat(locale, options);
12
12
  return formatter.format(date);
13
13
  };
14
+ // Function to format currency
15
+ const formatCurrency = (value, locale = "sv-SE", currency = "SEK", options = {}) => {
16
+ const formatter = new Intl.NumberFormat(locale, Object.assign({ style: "currency", currency: currency }, options));
17
+ return formatter.format(value);
18
+ };
14
19
  // Dynamic formatter function
15
20
  const formatValue = (value, type = "number", locale = "sv-SE", options = {
16
21
  currency: "SEK",
@@ -23,6 +28,10 @@ const formatValue = (value, type = "number", locale = "sv-SE", options = {
23
28
  const date = new Date(value);
24
29
  return formatDate(date, locale, options);
25
30
  }
31
+ else if (type === "currency") {
32
+ const num = parseFloat(value.toString());
33
+ return formatCurrency(num, locale, options.currency, options);
34
+ }
26
35
  else {
27
36
  return value;
28
37
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@megha-ui/react",
3
- "version": "1.2.76",
3
+ "version": "1.2.77",
4
4
  "description": "A collection of reusable UI components for React applications, built with TypeScript.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",