MCPcopy
hub / github.com/axios/axios / buildPath

Function buildPath

lib/helpers/formDataToJSON.js:70–104  ·  view source on GitHub ↗
(path, value, target, index)

Source from the content-addressed store, hash-verified

68 */
69function formDataToJSON(formData) {
70 function buildPath(path, value, target, index) {
71 throwIfDepthExceeded(index);
72
73 let name = path[index++];
74
75 if (name === '__proto__') return true;
76
77 const isNumericKey = Number.isFinite(+name);
78 const isLast = index >= path.length;
79 name = !name && utils.isArray(target) ? target.length : name;
80
81 if (isLast) {
82 if (utils.hasOwnProp(target, name)) {
83 target[name] = utils.isArray(target[name])
84 ? target[name].concat(value)
85 : [target[name], value];
86 } else {
87 target[name] = value;
88 }
89
90 return !isNumericKey;
91 }
92
93 if (!utils.hasOwnProp(target, name) || !utils.isObject(target[name])) {
94 target[name] = [];
95 }
96
97 const result = buildPath(path, value, target[name], index);
98
99 if (result && utils.isArray(target[name])) {
100 target[name] = arrayToObject(target[name]);
101 }
102
103 return !isNumericKey;
104 }
105
106 if (utils.isFormData(formData) && utils.isFunction(formData.entries)) {
107 const obj = {};

Callers 1

formDataToJSONFunction · 0.85

Calls 3

throwIfDepthExceededFunction · 0.85
arrayToObjectFunction · 0.85
concatMethod · 0.80

Tested by

no test coverage detected