@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
@@ -1,6 +1,9 @@
1
1
  {
2
2
  "name": "@adaskothebeast/hierarchical-convert-to-date",
3
- "version": "1.2.0",
3
+ "version": "2.0.0",
4
+ "peerDependencies": {
5
+ "tslib": "^2.6.2"
6
+ },
4
7
  "main": "./src/index.js",
5
- "types": "./src/index.d.ts"
8
+ "type": "commonjs"
6
9
  }
package/src/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/hierarchical-convert-to-date/src/index.ts"],"names":[],"mappings":";;;AAAA,6EAAmD"}
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
- const setter = (obj, prop, val) => {
5
- obj[prop] = val;
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
- // Regular expression that matches ISO 8601 date strings
14
- const dateRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{3})?Z$/;
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
- else if (typeof obj === 'string' && dateRegex.test(obj)) {
38
- obj = new Date(obj);
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":["../../../../../packages/hierarchical-convert-to-date/src/lib/hierarchical-convert-to-date.ts"],"names":[],"mappings":";;;AAEA,MAAM,MAAM,GAAG,CACb,GAAM,EACN,IAAO,EACP,GAAS,EACH,EAAE;IACR,GAAG,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC;AAClB,CAAC,CAAC;AAEF;;;;GAIG;AACH,SAAgB,yBAAyB,CAAC,GAAY;IACpD,wDAAwD;IACxD,MAAM,SAAS,GAAW,kDAAkD,CAAC;IAE7E,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;QAC3B,MAAM,CAAC,GAAG,GAAqB,CAAC;QAEhC,KAAK,MAAM,GAAG,IAAI,CAAC,EAAE;YACnB,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE;gBACjD,SAAS;aACV;YAED,MAAM,CAAC,GAAG,GAAqB,CAAC;YAChC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;YACf,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE;gBAC9C,6DAA6D;gBAC7D,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;aAC3B;iBAAM,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE;gBAChC,6EAA6E;gBAC7E,yBAAyB,CAAC,CAAC,CAAC,CAAC;aAC9B;SACF;KACF;SAAM,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;QAC7B,0CAA0C;QAC1C,GAAG,CAAC,OAAO,CAAC,yBAAyB,CAAC,CAAC;KACxC;SAAM,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;QACzD,GAAG,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC;KACrB;AACH,CAAC;AA5BD,8DA4BC"}
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"}