utils.js 657 B

123456789101112131415161718192021222324252627
  1. "use strict";
  2. function isArray(value) {
  3. if (typeof Array.isArray === "function") {
  4. return Array.isArray(value);
  5. } else {
  6. return Object.prototype.toString.call(value) === "[object Array]";
  7. }
  8. }
  9. function isObject(value) {
  10. return Object.prototype.toString.call(value) === "[object Object]";
  11. }
  12. function cloneDeep(obj) {
  13. const d = isArray(obj) ? obj : {};
  14. if (isObject(obj)) {
  15. for (const key in obj) {
  16. if (obj[key]) {
  17. if (obj[key] && typeof obj[key] === "object") {
  18. d[key] = cloneDeep(obj[key]);
  19. } else {
  20. d[key] = obj[key];
  21. }
  22. }
  23. }
  24. }
  25. return d;
  26. }
  27. exports.cloneDeep = cloneDeep;