deep-clone.js 472 B

12345678910111213141516171819202122232425262728
  1. "use strict";
  2. exports.__esModule = true;
  3. exports.deepClone = deepClone;
  4. var _index = require("./index");
  5. function deepClone(obj) {
  6. if (!(0, _index.isDef)(obj)) {
  7. return obj;
  8. }
  9. if (Array.isArray(obj)) {
  10. return obj.map(function (item) {
  11. return deepClone(item);
  12. });
  13. }
  14. if (typeof obj === 'object') {
  15. var to = {};
  16. Object.keys(obj).forEach(function (key) {
  17. to[key] = deepClone(obj[key]);
  18. });
  19. return to;
  20. }
  21. return obj;
  22. }