@cloudstrytech/validations 1.2.0 → 1.2.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudstrytech/validations",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "description": "JavaScript utility functions for validation",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -1,10 +1,11 @@
1
1
  // csvValidator.js file
2
2
 
3
- import { parseCSV } from "./parseCSV.js";
3
+ import { parseCSV } from "./parseCsv.js";
4
4
  import { isValidEmail } from "../validators/emailValidator.js";
5
5
  import { isValidIndianMobile } from "../validators/mobileValidator.js";
6
6
  import { isValidDate } from "../validators/dateValidator.js";
7
7
  import { normalizeDate } from "../validators/normalizeDate.js";
8
+ import { normalizeExcelDate } from "../validators/normalizeExcelDate.js";
8
9
 
9
10
  /* Normalize CSV headers */
10
11
  function normalizeKey(key = "") {
@@ -80,7 +81,7 @@ export async function validateCSV(csvInput) {
80
81
  ...row,
81
82
  "issuedate-b1":
82
83
  messages.length === 0
83
- ? normalizeDate(normalizedRow["issuedate-b1"])
84
+ ? normalizeDate(normalizeExcelDate(normalizedRow["issuedate-b1"]))
84
85
  : row["issuedate-b1"],
85
86
 
86
87
  __status: messages.length > 0 ? "ERROR" : "SUCCESS",
@@ -56,7 +56,7 @@ export function parseCSV(input) {
56
56
  /* 🔒 3️⃣ SAFE sheet_to_json (ADD HERE) */
57
57
  const json = XLSX.utils.sheet_to_json(worksheet, {
58
58
  defval: "",
59
- raw: false,
59
+ raw: true,
60
60
  });
61
61
 
62
62
  /* (Optional but recommended) Row limit */
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Convert Excel date OR string → DD/MM/YYYY
3
+ */
4
+ export function normalizeExcelDate(value) {
5
+ // Excel serial date (number)
6
+ if (typeof value === "number") {
7
+ const excelEpoch = new Date(Date.UTC(1899, 11, 30));
8
+ const date = new Date(excelEpoch.getTime() + value * 86400000);
9
+
10
+ const dd = String(date.getUTCDate()).padStart(2, "0");
11
+ const mm = String(date.getUTCMonth() + 1).padStart(2, "0");
12
+ const yyyy = date.getUTCFullYear();
13
+
14
+ return `${dd}/${mm}/${yyyy}`;
15
+ }
16
+
17
+ // Already string → trust validator
18
+ return value;
19
+ }