@adaskothebeast/hierarchical-convert-to-date 1.2.0 → 2.0.0
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
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/hierarchical-convert-to-date/src/index.ts"],"names":[],"mappings":";;;AAAA,6EAAmD"}
|
|
@@ -1,41 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.hierarchicalConvertToDate = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
};
|
|
4
|
+
// Regular expression that matches ISO 8601 date strings
|
|
5
|
+
const dateRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{3})?Z$/;
|
|
7
6
|
/**
|
|
8
7
|
* Function to recursively traverse the object and convert date strings to Date objects in place.
|
|
9
8
|
* @param obj Object to traverse
|
|
10
9
|
* @returns Void.
|
|
11
10
|
*/
|
|
12
11
|
function hierarchicalConvertToDate(obj) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if (typeof obj === 'object') {
|
|
16
|
-
const o = obj;
|
|
17
|
-
for (const key in o) {
|
|
18
|
-
if (!Object.prototype.hasOwnProperty.call(o, key)) {
|
|
19
|
-
continue;
|
|
20
|
-
}
|
|
21
|
-
const k = key;
|
|
22
|
-
const v = o[k];
|
|
23
|
-
if (typeof v === 'string' && dateRegex.test(v)) {
|
|
24
|
-
// Convert string to Date object if it matches the date regex
|
|
25
|
-
setter(o, k, new Date(v));
|
|
26
|
-
}
|
|
27
|
-
else if (typeof v === 'object') {
|
|
28
|
-
// Recurse into the object if it's not a string (could be an array or object)
|
|
29
|
-
hierarchicalConvertToDate(v);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
else if (Array.isArray(obj)) {
|
|
34
|
-
// Recurse into the array if it's an array
|
|
35
|
-
obj.forEach(hierarchicalConvertToDate);
|
|
12
|
+
if (typeof obj !== 'object') {
|
|
13
|
+
return;
|
|
36
14
|
}
|
|
37
|
-
|
|
38
|
-
|
|
15
|
+
const o = obj;
|
|
16
|
+
for (const key in o) {
|
|
17
|
+
if (!Object.prototype.hasOwnProperty.call(o, key)) {
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
const v = o[key];
|
|
21
|
+
if (typeof v === 'string' && dateRegex.test(v)) {
|
|
22
|
+
// Convert string to Date object if it matches the date regex
|
|
23
|
+
o[key] = new Date(v);
|
|
24
|
+
}
|
|
25
|
+
else if (typeof v === 'object') {
|
|
26
|
+
// Recurse into the object if it's not a string (could be an array or object)
|
|
27
|
+
hierarchicalConvertToDate(v);
|
|
28
|
+
}
|
|
39
29
|
}
|
|
40
30
|
}
|
|
41
31
|
exports.hierarchicalConvertToDate = hierarchicalConvertToDate;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hierarchical-convert-to-date.js","sourceRoot":"","sources":["../../../../../
|
|
1
|
+
{"version":3,"file":"hierarchical-convert-to-date.js","sourceRoot":"","sources":["../../../../../libs/hierarchical-convert-to-date/src/lib/hierarchical-convert-to-date.ts"],"names":[],"mappings":";;;AAEA,wDAAwD;AACxD,MAAM,SAAS,GAAW,kDAAkD,CAAC;AAE7E;;;;GAIG;AACH,SAAgB,yBAAyB,CAAC,GAAY;IACpD,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;QAC3B,OAAO;KACR;IACD,MAAM,CAAC,GAAG,GAAqB,CAAC;IAEhC,KAAK,MAAM,GAAG,IAAI,CAAC,EAAE;QACnB,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE;YACjD,SAAS;SACV;QAED,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;QACjB,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE;YAC9C,6DAA6D;YAC7D,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC;SACtB;aAAM,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE;YAChC,6EAA6E;YAC7E,yBAAyB,CAAC,CAAC,CAAC,CAAC;SAC9B;KACF;AACH,CAAC;AApBD,8DAoBC"}
|