Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. /**
  2. * Simple is object check.
  3. * @param item
  4. * @returns {boolean}
  5. */
  6. function isObject(item) {
  7. return (item && typeof item === 'object' && !Array.isArray(item));
  8. }
  9.  
  10. /**
  11. * Deep merge two objects.
  12. * @param target
  13. * @param source
  14. */
  15. function mergeDeep(target, source) {
  16. if (isObject(target) && isObject(source)) {
  17. for (const key in source) {
  18. if (isObject(source[key])) {
  19. if (!target[key]) Object.assign(target, { [key]: {} });
  20. mergeDeep(target[key], source[key]);
  21. } else {
  22. Object.assign(target, { [key]: source[key] });
  23. }
  24. }
  25. }
  26. return target;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement