clone.js 815 B

1234567891011121314151617181920212223242526272829
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.clone = void 0;
  4. const { isArray } = Array;
  5. const objectKeys = Object.keys;
  6. const clone = (obj) => {
  7. if (!obj)
  8. return obj;
  9. if (isArray(obj)) {
  10. const arr = [];
  11. const length = obj.length;
  12. for (let i = 0; i < length; i++)
  13. arr.push((0, exports.clone)(obj[i]));
  14. return arr;
  15. }
  16. else if (typeof obj === 'object') {
  17. const keys = objectKeys(obj);
  18. const length = keys.length;
  19. const newObject = {};
  20. for (let i = 0; i < length; i++) {
  21. const key = keys[i];
  22. newObject[key] = (0, exports.clone)(obj[key]);
  23. }
  24. return newObject;
  25. }
  26. return obj;
  27. };
  28. exports.clone = clone;
  29. //# sourceMappingURL=clone.js.map