From ff2f0b4bd75c80a03a9c295af3d1ecf99299953e Mon Sep 17 00:00:00 2001 From: Jay Date: Thu, 2 Jun 2022 20:49:51 +0200 Subject: [PATCH] docs(helpers/formDataToJSON) --- lib/helpers/formDataToJSON.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib/helpers/formDataToJSON.js b/lib/helpers/formDataToJSON.js index 45a1036..28e4730 100644 --- a/lib/helpers/formDataToJSON.js +++ b/lib/helpers/formDataToJSON.js @@ -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} 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 | null} The converted object. + */ function formDataToJSON(formData) { function buildPath(path, value, target, index) { var name = path[index++];