summaryrefslogtreecommitdiff
path: root/alarm/node_modules/axios/lib/helpers/formDataToJSON.js
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2023-01-10 14:54:04 +0100
committerMinteck <contact@minteck.org>2023-01-10 14:54:04 +0100
commit99c1d9af689e5325f3cf535c4007b3aeb8325229 (patch)
treee663b3c2ebdbd67c818ac0c5147f0ce1d2463cda /alarm/node_modules/axios/lib/helpers/formDataToJSON.js
parent9871b03912fc28ad38b4037ebf26a78aa937baba (diff)
downloadpluralconnect-99c1d9af689e5325f3cf535c4007b3aeb8325229.tar.gz
pluralconnect-99c1d9af689e5325f3cf535c4007b3aeb8325229.tar.bz2
pluralconnect-99c1d9af689e5325f3cf535c4007b3aeb8325229.zip
Update - This is an automated commit
Diffstat (limited to 'alarm/node_modules/axios/lib/helpers/formDataToJSON.js')
-rw-r--r--alarm/node_modules/axios/lib/helpers/formDataToJSON.js92
1 files changed, 0 insertions, 92 deletions
diff --git a/alarm/node_modules/axios/lib/helpers/formDataToJSON.js b/alarm/node_modules/axios/lib/helpers/formDataToJSON.js
deleted file mode 100644
index f4581df..0000000
--- a/alarm/node_modules/axios/lib/helpers/formDataToJSON.js
+++ /dev/null
@@ -1,92 +0,0 @@
-'use strict';
-
-import utils from '../utils.js';
-
-/**
- * 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
- // foo-x-y-z
- // foo x y z
- return utils.matchAll(/\w+|\[(\w*)]/g, name).map(match => {
- return match[0] === '[]' ? '' : match[1] || match[0];
- });
-}
-
-/**
- * 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) {
- const obj = {};
- const keys = Object.keys(arr);
- let i;
- const len = keys.length;
- let key;
- for (i = 0; i < len; i++) {
- key = keys[i];
- obj[key] = arr[key];
- }
- 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) {
- let name = path[index++];
- const isNumericKey = Number.isFinite(+name);
- const isLast = index >= path.length;
- name = !name && utils.isArray(target) ? target.length : name;
-
- if (isLast) {
- if (utils.hasOwnProp(target, name)) {
- target[name] = [target[name], value];
- } else {
- target[name] = value;
- }
-
- return !isNumericKey;
- }
-
- if (!target[name] || !utils.isObject(target[name])) {
- target[name] = [];
- }
-
- const result = buildPath(path, value, target[name], index);
-
- if (result && utils.isArray(target[name])) {
- target[name] = arrayToObject(target[name]);
- }
-
- return !isNumericKey;
- }
-
- if (utils.isFormData(formData) && utils.isFunction(formData.entries)) {
- const obj = {};
-
- utils.forEachEntry(formData, (name, value) => {
- buildPath(parsePropPath(name), value, obj, 0);
- });
-
- return obj;
- }
-
- return null;
-}
-
-export default formDataToJSON;