(path, value, target, index)
| 68 | */ |
| 69 | function 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 = {}; |
no test coverage detected