deep-assign.js 544 B

123456789101112131415161718192021222324
  1. import { isDef, isObject } from '.';
  2. var hasOwnProperty = Object.prototype.hasOwnProperty;
  3. function assignKey(to, from, key) {
  4. var val = from[key];
  5. if (!isDef(val)) {
  6. return;
  7. }
  8. if (!hasOwnProperty.call(to, key) || !isObject(val)) {
  9. to[key] = val;
  10. } else {
  11. // eslint-disable-next-line @typescript-eslint/no-use-before-define
  12. to[key] = deepAssign(Object(to[key]), from[key]);
  13. }
  14. }
  15. export function deepAssign(to, from) {
  16. Object.keys(from).forEach(function (key) {
  17. assignKey(to, from, key);
  18. });
  19. return to;
  20. }