HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/good-life-be/node_modules/@sendgrid/helpers/helpers/merge-data-deep.js
'use strict';

/**
 * Merge data deep helper
 */

function isObject(item) {
  return (item && typeof item === 'object' && !Array.isArray(item));
}

module.exports = function mergeDeep(base, data) {
  //Validate data
  if (typeof base !== 'object' || base === null) {
    throw new Error('Not an object provided for base');
  }
  if (typeof data !== 'object' || data === null) {
    throw new Error('Not an object provided for data');
  }
  let output = Object.assign({}, base);
  if (isObject(base) && isObject(data)) {
    Object.keys(data).forEach(key => {
      if (isObject(data[key])) {
        if (!(key in base)) {
          Object.assign(output, { [key]: data[key] });
        } else {
          output[key] = mergeDeep(base[key], data[key]);
        }
      } else {
        Object.assign(output, { [key]: data[key] });
      }
    });
  }
  return output;
};