MCPcopy
hub / github.com/axios/axios / defaultVisitor

Function defaultVisitor

lib/helpers/toFormData.js:200–244  ·  view source on GitHub ↗

* Default visitor. * * @param {*} value * @param {String|Number} key * @param {Array<String|Number>} path * @this {FormData} * * @returns {boolean} return true to visit the each prop of the value recursively

(value, key, path)

Source from the content-addressed store, hash-verified

198 * @returns {boolean} return true to visit the each prop of the value recursively
199 */
200 function defaultVisitor(value, key, path) {
201 let arr = value;
202
203 if (utils.isReactNative(formData) && utils.isReactNativeBlob(value)) {
204 formData.append(renderKey(path, key, dots), convertValue(value));
205 return false;
206 }
207
208 if (value && !path && typeof value === 'object') {
209 if (utils.endsWith(key, '{}')) {
210 // eslint-disable-next-line no-param-reassign
211 key = metaTokens ? key : key.slice(0, -2);
212 // eslint-disable-next-line no-param-reassign
213 value = stringifyWithDepthLimit(value, 1);
214 } else if (
215 (utils.isArray(value) && isFlatArray(value)) ||
216 ((utils.isFileList(value) || utils.endsWith(key, '[]')) && (arr = utils.toArray(value)))
217 ) {
218 // eslint-disable-next-line no-param-reassign
219 key = removeBrackets(key);
220
221 arr.forEach(function each(el, index) {
222 !(utils.isUndefined(el) || el === null) &&
223 formData.append(
224 // eslint-disable-next-line no-nested-ternary
225 indexes === true
226 ? renderKey([key], index, dots)
227 : indexes === null
228 ? key
229 : key + '[]',
230 convertValue(el)
231 );
232 });
233 return false;
234 }
235 }
236
237 if (isVisitable(value)) {
238 return true;
239 }
240
241 formData.append(renderKey(path, key, dots), convertValue(value));
242
243 return false;
244 }
245
246 const exposedHelpers = Object.assign(predicates, {
247 defaultVisitor,

Callers

nothing calls this directly

Calls 8

renderKeyFunction · 0.85
convertValueFunction · 0.85
stringifyWithDepthLimitFunction · 0.85
isFlatArrayFunction · 0.85
removeBracketsFunction · 0.85
isVisitableFunction · 0.85
forEachMethod · 0.80
appendMethod · 0.65

Tested by

no test coverage detected