cloneDeep.js 544 B

12345678910111213141516171819202122
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. Object.defineProperty(exports, "cloneDeep", {
  6. enumerable: true,
  7. get: function() {
  8. return cloneDeep;
  9. }
  10. });
  11. function cloneDeep(value) {
  12. if (Array.isArray(value)) {
  13. return value.map((child)=>cloneDeep(child));
  14. }
  15. if (typeof value === "object" && value !== null) {
  16. return Object.fromEntries(Object.entries(value).map(([k, v])=>[
  17. k,
  18. cloneDeep(v)
  19. ]));
  20. }
  21. return value;
  22. }