mirror of
https://github.com/tenrok/axios.git
synced 2026-05-15 11:59:42 +03:00
docs(helpers/formDataToJSON)
This commit is contained in:
@@ -2,6 +2,13 @@
|
||||
|
||||
var utils = require('../utils');
|
||||
|
||||
/**
|
||||
* It takes a string like `foo[x][y][z]` and returns an array like `['foo', 'x', 'y', 'z']
|
||||
*
|
||||
* @param {string} name - The name of the property to get.
|
||||
*
|
||||
* @returns An array of strings.
|
||||
*/
|
||||
function parsePropPath(name) {
|
||||
// foo[x][y][z]
|
||||
// foo.x.y.z
|
||||
@@ -12,6 +19,13 @@ function parsePropPath(name) {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert an array to an object.
|
||||
*
|
||||
* @param {Array<any>} arr - The array to convert to an object.
|
||||
*
|
||||
* @returns An object with the same keys and values as the array.
|
||||
*/
|
||||
function arrayToObject(arr) {
|
||||
var obj = {};
|
||||
var keys = Object.keys(arr);
|
||||
@@ -25,6 +39,13 @@ function arrayToObject(arr) {
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* It takes a FormData object and returns a JavaScript object
|
||||
*
|
||||
* @param {string} formData The FormData object to convert to JSON.
|
||||
*
|
||||
* @returns {Object<string, any> | null} The converted object.
|
||||
*/
|
||||
function formDataToJSON(formData) {
|
||||
function buildPath(path, value, target, index) {
|
||||
var name = path[index++];
|
||||
|
||||
Reference in New Issue
Block a user