@ptolemy2002/list-object-utils 2.1.0 → 2.1.1

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/README.md CHANGED
@@ -186,6 +186,7 @@ Clones an object. Uses recursion to clone nested objects and the `listClone` fun
186
186
 
187
187
  ## Peer Dependencies
188
188
  - @ptolemy2002/ts-utils^2.0.0
189
+ - is-callable^1.2.7
189
190
 
190
191
  ## Commands
191
192
  The following commands exist in the project:
package/dist/index.js CHANGED
@@ -1,4 +1,7 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.listsEqual = listsEqual;
4
7
  exports.objectsEqual = objectsEqual;
@@ -14,6 +17,7 @@ exports.sortWithIndeces = sortWithIndeces;
14
17
  exports.objectToString = objectToString;
15
18
  exports.listClone = listClone;
16
19
  exports.objectClone = objectClone;
20
+ const is_callable_1 = __importDefault(require("is-callable"));
17
21
  function listsEqual(a, b) {
18
22
  if (a === b)
19
23
  return true;
@@ -200,11 +204,16 @@ function listClone(list, maxDepth = Infinity, depth = 0) {
200
204
  function objectClone(obj, maxDepth = Infinity, depth = 0) {
201
205
  if (depth >= maxDepth)
202
206
  return obj;
207
+ if (obj instanceof Date)
208
+ return new Date(obj.getTime());
203
209
  return Object.keys(obj).reduce((acc, key) => {
204
210
  const value = obj[key];
205
211
  if (Array.isArray(value)) {
206
212
  acc[key] = listClone(value, maxDepth, depth + 1);
207
213
  }
214
+ else if ((0, is_callable_1.default)(value.clone)) {
215
+ acc[key] = value.clone();
216
+ }
208
217
  else if (typeof value === "object") {
209
218
  acc[key] = objectClone(value, maxDepth, depth + 1);
210
219
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ptolemy2002/list-object-utils",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
4
4
  "private": false,
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -27,9 +27,12 @@
27
27
  "release-major": "bash ./scripts/release.sh major"
28
28
  },
29
29
  "peerDependencies": {
30
- "@ptolemy2002/ts-utils": "^2.0.0"
30
+ "@ptolemy2002/ts-utils": "^2.0.0",
31
+ "is-callable": "^1.2.7"
31
32
  },
32
33
  "devDependencies": {
33
- "@ptolemy2002/ts-utils": "^2.0.0"
34
+ "@ptolemy2002/ts-utils": "^2.0.0",
35
+ "@types/is-callable": "^1.1.2",
36
+ "is-callable": "^1.2.7"
34
37
  }
35
38
  }