deep-assign.js 613 B

123456789101112131415161718192021222324252627282930
  1. "use strict";
  2. exports.__esModule = true;
  3. exports.deepAssign = deepAssign;
  4. var _ = require(".");
  5. var hasOwnProperty = Object.prototype.hasOwnProperty;
  6. function assignKey(to, from, key) {
  7. var val = from[key];
  8. if (!(0, _.isDef)(val)) {
  9. return;
  10. }
  11. if (!hasOwnProperty.call(to, key) || !(0, _.isObject)(val)) {
  12. to[key] = val;
  13. } else {
  14. // eslint-disable-next-line @typescript-eslint/no-use-before-define
  15. to[key] = deepAssign(Object(to[key]), from[key]);
  16. }
  17. }
  18. function deepAssign(to, from) {
  19. Object.keys(from).forEach(function (key) {
  20. assignKey(to, from, key);
  21. });
  22. return to;
  23. }