summaryrefslogtreecommitdiff
path: root/fetcher/node_modules/axios/lib/helpers/toFormData.js
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2022-05-08 13:18:04 +0200
committerMinteck <contact@minteck.org>2022-05-08 13:18:04 +0200
commit16da8f48c7328c334a5c0d863078fd00257ae6b4 (patch)
tree4ab80e4106c4c7a61e5a7caf6102d612b8dd985d /fetcher/node_modules/axios/lib/helpers/toFormData.js
downloaddownloadcenter-16da8f48c7328c334a5c0d863078fd00257ae6b4.tar.gz
downloadcenter-16da8f48c7328c334a5c0d863078fd00257ae6b4.tar.bz2
downloadcenter-16da8f48c7328c334a5c0d863078fd00257ae6b4.zip
Initial commit
Diffstat (limited to 'fetcher/node_modules/axios/lib/helpers/toFormData.js')
-rw-r--r--fetcher/node_modules/axios/lib/helpers/toFormData.js72
1 files changed, 72 insertions, 0 deletions
diff --git a/fetcher/node_modules/axios/lib/helpers/toFormData.js b/fetcher/node_modules/axios/lib/helpers/toFormData.js
new file mode 100644
index 0000000..5e3cc0f
--- /dev/null
+++ b/fetcher/node_modules/axios/lib/helpers/toFormData.js
@@ -0,0 +1,72 @@
+'use strict';
+
+var utils = require('../utils');
+
+/**
+ * Convert a data object to FormData
+ * @param {Object} obj
+ * @param {?Object} [formData]
+ * @returns {Object}
+ **/
+
+function toFormData(obj, formData) {
+ // eslint-disable-next-line no-param-reassign
+ formData = formData || new FormData();
+
+ var stack = [];
+
+ function convertValue(value) {
+ if (value === null) return '';
+
+ if (utils.isDate(value)) {
+ return value.toISOString();
+ }
+
+ if (utils.isArrayBuffer(value) || utils.isTypedArray(value)) {
+ return typeof Blob === 'function' ? new Blob([value]) : Buffer.from(value);
+ }
+
+ return value;
+ }
+
+ function build(data, parentKey) {
+ if (utils.isPlainObject(data) || utils.isArray(data)) {
+ if (stack.indexOf(data) !== -1) {
+ throw Error('Circular reference detected in ' + parentKey);
+ }
+
+ stack.push(data);
+
+ utils.forEach(data, function each(value, key) {
+ if (utils.isUndefined(value)) return;
+ var fullKey = parentKey ? parentKey + '.' + key : key;
+ var arr;
+
+ if (value && !parentKey && typeof value === 'object') {
+ if (utils.endsWith(key, '{}')) {
+ // eslint-disable-next-line no-param-reassign
+ value = JSON.stringify(value);
+ } else if (utils.endsWith(key, '[]') && (arr = utils.toArray(value))) {
+ // eslint-disable-next-line func-names
+ arr.forEach(function(el) {
+ !utils.isUndefined(el) && formData.append(fullKey, convertValue(el));
+ });
+ return;
+ }
+ }
+
+ build(value, fullKey);
+ });
+
+ stack.pop();
+ } else {
+ formData.append(parentKey, convertValue(data));
+ }
+ }
+
+ build(obj);
+
+ return formData;
+}
+
+module.exports = toFormData;