topkat-utils 1.0.46 → 1.0.47

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/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ### v1.0.47
2
+ * deep clone type improvement
3
+
1
4
  ### v1.0.46
2
5
  * FIX templater undefined no error anymore
3
6
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "topkat-utils",
3
- "version": "1.0.46",
3
+ "version": "1.0.47",
4
4
  "type": "commonjs",
5
5
  "private": false,
6
6
  "description": "UTILS BIG TIME",
package/utils.ts CHANGED
@@ -492,17 +492,17 @@ function cloneObject(o) {
492
492
  }
493
493
 
494
494
  /** Deep clone. WILL REMOVE circular references */
495
- function deepClone(obj, cache = []) {
495
+ function deepClone<T>(obj: T, cache = []): T {
496
496
 
497
497
  let copy;
498
498
  // usefull to not modify 1st level objet by lower levels
499
499
  // this is required for the same object to be referenced not in a redundant way
500
500
  const newCache = [...cache];
501
- if (obj instanceof Date) return new Date(obj)
501
+ if (obj instanceof Date) return new Date(obj) as any
502
502
 
503
503
  // Handle Array
504
504
  if (Array.isArray(obj)) {
505
- if (newCache.includes(obj)) return [];
505
+ if (newCache.includes(obj)) return [] as any
506
506
  newCache.push(obj);
507
507
  copy = [];
508
508
  for (var i = 0, len = obj.length; i < len; i++) {
@@ -512,7 +512,7 @@ function deepClone(obj, cache = []) {
512
512
  }
513
513
 
514
514
  if (typeof obj === 'object' && obj !== null && Object.getPrototypeOf(obj) === Object.prototype) {
515
- if (newCache.includes(obj)) return {};
515
+ if (newCache.includes(obj)) return {} as any
516
516
  newCache.push(obj);
517
517
  copy = {};
518
518
  for (var key in obj) {