MCPcopy
hub / github.com/axios/axios / mergeConfig

Function mergeConfig

lib/core/mergeConfig.js:17–159  ·  view source on GitHub ↗
(config1, config2)

Source from the content-addressed store, hash-verified

15 * @returns {Object} New object resulting from merging config2 to config1
16 */
17export 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

Callers 8

createInstanceFunction · 0.85
_requestMethod · 0.85
getUriMethod · 0.85
Axios.jsFile · 0.85
generateHTTPMethodFunction · 0.85
resolveConfigFunction · 0.85

Calls 7

mergeDeepPropertiesFunction · 0.85
headersToObjectFunction · 0.85
mergeFunction · 0.85
getMergedValueFunction · 0.85
createMethod · 0.80
forEachMethod · 0.80

Tested by

no test coverage detected