@megha-ui/react 1.2.108 → 1.2.110

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.
@@ -50,7 +50,6 @@ const GridRow = ({ item, rowStyle, cellStyle, rowHeight, bulkSelect, selectedRow
50
50
  _dragIndex = 1;
51
51
  }
52
52
  }
53
- console.log(draggable, columns, _dragIndex);
54
53
  setDraggableIndex(_dragIndex);
55
54
  }, [columns]);
56
55
  return isExpandable &&
@@ -1,12 +1,57 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.formatValue = void 0;
4
+ const regexUtils_1 = require("../components/grid/utils/regexUtils");
4
5
  // Function to format numbers
5
6
  const formatNumber = (value, locale = "sv-SE", options = {}) => {
6
7
  const formatter = new Intl.NumberFormat(locale, options);
7
8
  return formatter.format(value);
8
9
  };
9
- // Function to format dates
10
+ const toISODate = (d) => d.toISOString().slice(0, 10);
11
+ const parseSupportedDate = (input) => {
12
+ if (input instanceof Date) {
13
+ return isNaN(input.getTime()) ? null : input;
14
+ }
15
+ if (typeof input === "number") {
16
+ const d = new Date(input);
17
+ return isNaN(d.getTime()) ? null : d;
18
+ }
19
+ if (typeof input !== "string")
20
+ return null;
21
+ const str = input.trim();
22
+ if (!str)
23
+ return null;
24
+ if (/^\d{2}[-\/]\d{2}[-\/]\d{4}$/.test(str)) {
25
+ const sep = str.includes("-") ? "-" : "/";
26
+ const [p1s, p2s, ys] = str.split(sep);
27
+ const part1 = Number(p1s);
28
+ const part2 = Number(p2s);
29
+ const year = Number(ys);
30
+ const day = part1 > 12 ? part1 : part2;
31
+ const month = part1 > 12 ? part2 : part1;
32
+ const d = new Date(year, month - 1, day);
33
+ return d.getFullYear() === year &&
34
+ d.getMonth() + 1 === month &&
35
+ d.getDate() === day
36
+ ? d
37
+ : null;
38
+ }
39
+ if (/^\d{4}[-\/.]\d{2}[-\/.]\d{2}$/.test(str)) {
40
+ const sep = str.includes("-") ? "-" : str.includes("/") ? "/" : ".";
41
+ const [ys, ms, ds] = str.split(sep);
42
+ const year = Number(ys);
43
+ const month = Number(ms);
44
+ const day = Number(ds);
45
+ const d = new Date(year, month - 1, day);
46
+ return d.getFullYear() === year &&
47
+ d.getMonth() + 1 === month &&
48
+ d.getDate() === day
49
+ ? d
50
+ : null;
51
+ }
52
+ const d = new Date(str);
53
+ return isNaN(d.getTime()) ? null : d;
54
+ };
10
55
  const formatDate = (date, locale = "sv-SE", options = {}) => {
11
56
  const formatter = new Intl.DateTimeFormat(locale, options);
12
57
  return formatter.format(date);
@@ -18,24 +63,38 @@ const formatCurrency = (value, locale = "sv-SE", currency = "SEK", options = {})
18
63
  };
19
64
  // Dynamic formatter function
20
65
  const formatValue = (value, type = "number", locale = "sv-SE", options = {
21
- currency: "SEK"
66
+ currency: "SEK",
22
67
  }) => {
23
- var _a, _b;
24
- const date = value instanceof Date ? value : new Date(value);
25
68
  if (type === "number") {
26
69
  const num = parseFloat(value.toString());
27
70
  return formatNumber(num, locale, options);
28
71
  }
29
- else if (type === "date" && !isNaN(date.getTime())) {
30
- console.log("Coming here to date format");
31
- return formatDate(date, locale, options);
72
+ else if (type === "date") {
73
+ let date = "";
74
+ if (value instanceof Date) {
75
+ date = isNaN(value.getTime()) ? "" : toISODate(value);
76
+ }
77
+ if (typeof value === "number") {
78
+ const d = parseSupportedDate(value);
79
+ date = d ? toISODate(d) : "";
80
+ }
81
+ if (typeof value === "string") {
82
+ if (!(0, regexUtils_1.isValidDateFormat)(value))
83
+ return value;
84
+ const d = parseSupportedDate(value);
85
+ date = d ? toISODate(d) : "";
86
+ }
87
+ if (date) {
88
+ return formatDate(new Date(date).getTime(), locale, options);
89
+ }
90
+ return value.toString();
32
91
  }
33
92
  else if (type === "currency") {
34
93
  const num = parseFloat(value.toString());
35
94
  return formatCurrency(num, locale, options.currency, options);
36
95
  }
37
96
  else {
38
- return typeof value === "number" ? value : (_b = (_a = value === null || value === void 0 ? void 0 : value.toString) === null || _a === void 0 ? void 0 : _a.call(value)) !== null && _b !== void 0 ? _b : "";
97
+ return value.toString();
39
98
  }
40
99
  };
41
100
  exports.formatValue = formatValue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@megha-ui/react",
3
- "version": "1.2.108",
3
+ "version": "1.2.110",
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",