(config1, config2)
| 15 | * @returns {Object} New object resulting from merging config2 to config1 |
| 16 | */ |
| 17 | export default function mergeConfig(config1, config2) { |
| 18 | // eslint-disable-next-line no-param-reassign |
| 19 | config1 = config1 || {}; |
| 20 | config2 = config2 || {}; |
| 21 | |
| 22 | // Use a null-prototype object so that downstream reads such as `config.auth` |
| 23 | // or `config.baseURL` cannot inherit polluted values from Object.prototype. |
| 24 | // `hasOwnProperty` is restored as a non-enumerable own slot to preserve |
| 25 | // ergonomics for user code that relies on it. |
| 26 | const config = Object.create(null); |
| 27 | Object.defineProperty(config, 'hasOwnProperty', { |
| 28 | // Null-proto descriptor so a polluted Object.prototype.get cannot turn |
| 29 | // this data descriptor into an accessor descriptor on the way in. |
| 30 | __proto__: null, |
| 31 | value: Object.prototype.hasOwnProperty, |
| 32 | enumerable: false, |
| 33 | writable: true, |
| 34 | configurable: true, |
| 35 | }); |
| 36 | |
| 37 | function getMergedValue(target, source, prop, caseless) { |
| 38 | if (utils.isPlainObject(target) && utils.isPlainObject(source)) { |
| 39 | return utils.merge.call({ caseless }, target, source); |
| 40 | } else if (utils.isPlainObject(source)) { |
| 41 | return utils.merge({}, source); |
| 42 | } else if (utils.isArray(source)) { |
| 43 | return source.slice(); |
| 44 | } |
| 45 | return source; |
| 46 | } |
| 47 | |
| 48 | function mergeDeepProperties(a, b, prop, caseless) { |
| 49 | if (!utils.isUndefined(b)) { |
| 50 | return getMergedValue(a, b, prop, caseless); |
| 51 | } else if (!utils.isUndefined(a)) { |
| 52 | return getMergedValue(undefined, a, prop, caseless); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | // eslint-disable-next-line consistent-return |
| 57 | function valueFromConfig2(a, b) { |
| 58 | if (!utils.isUndefined(b)) { |
| 59 | return getMergedValue(undefined, b); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | // eslint-disable-next-line consistent-return |
| 64 | function defaultToConfig2(a, b) { |
| 65 | if (!utils.isUndefined(b)) { |
| 66 | return getMergedValue(undefined, b); |
| 67 | } else if (!utils.isUndefined(a)) { |
| 68 | return getMergedValue(undefined, a); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | function getMergedTransitionalOption(prop) { |
| 73 | const transitional2 = utils.hasOwnProp(config2, 'transitional') ? config2.transitional : undefined; |
| 74 |
no test coverage detected