axios 0.27.2 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of axios might be problematic. Click here for more details.

Files changed (75) hide show
  1. package/CHANGELOG.md +232 -920
  2. package/LICENSE +4 -16
  3. package/README.md +386 -103
  4. package/SECURITY.md +4 -3
  5. package/UPGRADE_GUIDE.md +1 -166
  6. package/bin/ssl_hotfix.js +22 -0
  7. package/dist/axios.js +2430 -2367
  8. package/dist/axios.js.map +1 -0
  9. package/dist/axios.min.js +2 -3
  10. package/dist/axios.min.js.map +1 -0
  11. package/dist/esm/axios.js +2950 -0
  12. package/dist/esm/axios.js.map +1 -0
  13. package/dist/esm/axios.min.js +2 -0
  14. package/dist/esm/axios.min.js.map +1 -0
  15. package/dist/node/axios.cjs +3764 -0
  16. package/dist/node/axios.cjs.map +1 -0
  17. package/gulpfile.js +88 -0
  18. package/index.d.ts +299 -70
  19. package/index.js +32 -1
  20. package/karma.conf.cjs +250 -0
  21. package/lib/adapters/http.js +378 -211
  22. package/lib/adapters/index.js +33 -0
  23. package/lib/adapters/xhr.js +81 -57
  24. package/lib/axios.js +34 -22
  25. package/lib/cancel/CancelToken.js +91 -89
  26. package/lib/cancel/CanceledError.js +9 -6
  27. package/lib/cancel/isCancel.js +2 -2
  28. package/lib/core/Axios.js +133 -98
  29. package/lib/core/AxiosError.js +22 -8
  30. package/lib/core/AxiosHeaders.js +268 -0
  31. package/lib/core/InterceptorManager.js +62 -45
  32. package/lib/core/buildFullPath.js +5 -4
  33. package/lib/core/dispatchRequest.js +21 -32
  34. package/lib/core/mergeConfig.js +8 -7
  35. package/lib/core/settle.js +6 -4
  36. package/lib/core/transformData.js +15 -9
  37. package/lib/defaults/index.js +77 -38
  38. package/lib/defaults/transitional.js +1 -1
  39. package/lib/env/classes/FormData.js +2 -0
  40. package/lib/env/data.js +1 -3
  41. package/lib/helpers/AxiosTransformStream.js +191 -0
  42. package/lib/helpers/AxiosURLSearchParams.js +58 -0
  43. package/lib/helpers/bind.js +3 -7
  44. package/lib/helpers/buildURL.js +26 -33
  45. package/lib/helpers/combineURLs.js +3 -2
  46. package/lib/helpers/cookies.js +43 -44
  47. package/lib/helpers/deprecatedMethod.js +4 -2
  48. package/lib/helpers/formDataToJSON.js +92 -0
  49. package/lib/helpers/fromDataURI.js +53 -0
  50. package/lib/helpers/isAbsoluteURL.js +3 -2
  51. package/lib/helpers/isAxiosError.js +4 -3
  52. package/lib/helpers/isURLSameOrigin.js +44 -45
  53. package/lib/helpers/null.js +1 -1
  54. package/lib/helpers/parseHeaders.js +24 -22
  55. package/lib/helpers/parseProtocol.js +3 -3
  56. package/lib/helpers/speedometer.js +55 -0
  57. package/lib/helpers/spread.js +3 -2
  58. package/lib/helpers/throttle.js +33 -0
  59. package/lib/helpers/toFormData.js +193 -36
  60. package/lib/helpers/toURLEncodedForm.js +18 -0
  61. package/lib/helpers/validator.js +20 -15
  62. package/lib/platform/browser/classes/FormData.js +3 -0
  63. package/lib/platform/browser/classes/URLSearchParams.js +4 -0
  64. package/lib/platform/browser/index.js +43 -0
  65. package/lib/platform/index.js +3 -0
  66. package/lib/platform/node/classes/FormData.js +3 -0
  67. package/lib/platform/node/classes/URLSearchParams.js +4 -0
  68. package/lib/platform/node/index.js +12 -0
  69. package/lib/utils.js +321 -178
  70. package/package.json +70 -23
  71. package/rollup.config.js +90 -0
  72. package/dist/axios.map +0 -1
  73. package/dist/axios.min.map +0 -1
  74. package/lib/defaults/env/FormData.js +0 -2
  75. package/lib/helpers/normalizeHeaderName.js +0 -12
@@ -1,68 +1,67 @@
1
1
  'use strict';
2
2
 
3
- var utils = require('./../utils');
3
+ import utils from './../utils.js';
4
+ import platform from '../platform/index.js';
4
5
 
5
- module.exports = (
6
- utils.isStandardBrowserEnv() ?
6
+ export default platform.isStandardBrowserEnv ?
7
7
 
8
- // Standard browser envs have full support of the APIs needed to test
9
- // whether the request URL is of the same origin as current location.
10
- (function standardBrowserEnv() {
11
- var msie = /(msie|trident)/i.test(navigator.userAgent);
12
- var urlParsingNode = document.createElement('a');
13
- var originURL;
8
+ // Standard browser envs have full support of the APIs needed to test
9
+ // whether the request URL is of the same origin as current location.
10
+ (function standardBrowserEnv() {
11
+ const msie = /(msie|trident)/i.test(navigator.userAgent);
12
+ const urlParsingNode = document.createElement('a');
13
+ let originURL;
14
14
 
15
- /**
15
+ /**
16
16
  * Parse a URL to discover it's components
17
17
  *
18
18
  * @param {String} url The URL to be parsed
19
19
  * @returns {Object}
20
20
  */
21
- function resolveURL(url) {
22
- var href = url;
21
+ function resolveURL(url) {
22
+ let href = url;
23
23
 
24
- if (msie) {
24
+ if (msie) {
25
25
  // IE needs attribute set twice to normalize properties
26
- urlParsingNode.setAttribute('href', href);
27
- href = urlParsingNode.href;
28
- }
29
-
30
26
  urlParsingNode.setAttribute('href', href);
31
-
32
- // urlParsingNode provides the UrlUtils interface - http://url.spec.whatwg.org/#urlutils
33
- return {
34
- href: urlParsingNode.href,
35
- protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, '') : '',
36
- host: urlParsingNode.host,
37
- search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, '') : '',
38
- hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, '') : '',
39
- hostname: urlParsingNode.hostname,
40
- port: urlParsingNode.port,
41
- pathname: (urlParsingNode.pathname.charAt(0) === '/') ?
42
- urlParsingNode.pathname :
43
- '/' + urlParsingNode.pathname
44
- };
27
+ href = urlParsingNode.href;
45
28
  }
46
29
 
47
- originURL = resolveURL(window.location.href);
30
+ urlParsingNode.setAttribute('href', href);
31
+
32
+ // urlParsingNode provides the UrlUtils interface - http://url.spec.whatwg.org/#urlutils
33
+ return {
34
+ href: urlParsingNode.href,
35
+ protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, '') : '',
36
+ host: urlParsingNode.host,
37
+ search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, '') : '',
38
+ hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, '') : '',
39
+ hostname: urlParsingNode.hostname,
40
+ port: urlParsingNode.port,
41
+ pathname: (urlParsingNode.pathname.charAt(0) === '/') ?
42
+ urlParsingNode.pathname :
43
+ '/' + urlParsingNode.pathname
44
+ };
45
+ }
48
46
 
49
- /**
47
+ originURL = resolveURL(window.location.href);
48
+
49
+ /**
50
50
  * Determine if a URL shares the same origin as the current location
51
51
  *
52
52
  * @param {String} requestURL The URL to test
53
53
  * @returns {boolean} True if URL shares the same origin, otherwise false
54
54
  */
55
- return function isURLSameOrigin(requestURL) {
56
- var parsed = (utils.isString(requestURL)) ? resolveURL(requestURL) : requestURL;
57
- return (parsed.protocol === originURL.protocol &&
58
- parsed.host === originURL.host);
59
- };
60
- })() :
55
+ return function isURLSameOrigin(requestURL) {
56
+ const parsed = (utils.isString(requestURL)) ? resolveURL(requestURL) : requestURL;
57
+ return (parsed.protocol === originURL.protocol &&
58
+ parsed.host === originURL.host);
59
+ };
60
+ })() :
61
61
 
62
62
  // Non standard browser envs (web workers, react-native) lack needed support.
63
- (function nonStandardBrowserEnv() {
64
- return function isURLSameOrigin() {
65
- return true;
66
- };
67
- })()
68
- );
63
+ (function nonStandardBrowserEnv() {
64
+ return function isURLSameOrigin() {
65
+ return true;
66
+ };
67
+ })();
@@ -1,2 +1,2 @@
1
1
  // eslint-disable-next-line strict
2
- module.exports = null;
2
+ export default null;
@@ -1,15 +1,15 @@
1
1
  'use strict';
2
2
 
3
- var utils = require('./../utils');
3
+ import utils from './../utils.js';
4
4
 
5
- // Headers whose duplicates are ignored by node
5
+ // RawAxiosHeaders whose duplicates are ignored by node
6
6
  // c.f. https://nodejs.org/api/http.html#http_message_headers
7
- var ignoreDuplicateOf = [
7
+ const ignoreDuplicateOf = utils.toObjectSet([
8
8
  'age', 'authorization', 'content-length', 'content-type', 'etag',
9
9
  'expires', 'from', 'host', 'if-modified-since', 'if-unmodified-since',
10
10
  'last-modified', 'location', 'max-forwards', 'proxy-authorization',
11
11
  'referer', 'retry-after', 'user-agent'
12
- ];
12
+ ]);
13
13
 
14
14
  /**
15
15
  * Parse headers into an object
@@ -21,31 +21,33 @@ var ignoreDuplicateOf = [
21
21
  * Transfer-Encoding: chunked
22
22
  * ```
23
23
  *
24
- * @param {String} headers Headers needing to be parsed
24
+ * @param {String} rawHeaders Headers needing to be parsed
25
+ *
25
26
  * @returns {Object} Headers parsed into an object
26
27
  */
27
- module.exports = function parseHeaders(headers) {
28
- var parsed = {};
29
- var key;
30
- var val;
31
- var i;
32
-
33
- if (!headers) { return parsed; }
28
+ export default rawHeaders => {
29
+ const parsed = {};
30
+ let key;
31
+ let val;
32
+ let i;
34
33
 
35
- utils.forEach(headers.split('\n'), function parser(line) {
34
+ rawHeaders && rawHeaders.split('\n').forEach(function parser(line) {
36
35
  i = line.indexOf(':');
37
- key = utils.trim(line.substr(0, i)).toLowerCase();
38
- val = utils.trim(line.substr(i + 1));
36
+ key = line.substring(0, i).trim().toLowerCase();
37
+ val = line.substring(i + 1).trim();
39
38
 
40
- if (key) {
41
- if (parsed[key] && ignoreDuplicateOf.indexOf(key) >= 0) {
42
- return;
43
- }
44
- if (key === 'set-cookie') {
45
- parsed[key] = (parsed[key] ? parsed[key] : []).concat([val]);
39
+ if (!key || (parsed[key] && ignoreDuplicateOf[key])) {
40
+ return;
41
+ }
42
+
43
+ if (key === 'set-cookie') {
44
+ if (parsed[key]) {
45
+ parsed[key].push(val);
46
46
  } else {
47
- parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val;
47
+ parsed[key] = [val];
48
48
  }
49
+ } else {
50
+ parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val;
49
51
  }
50
52
  });
51
53
 
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- module.exports = function parseProtocol(url) {
4
- var match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
3
+ export default function parseProtocol(url) {
4
+ const match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
5
5
  return match && match[1] || '';
6
- };
6
+ }
@@ -0,0 +1,55 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Calculate data maxRate
5
+ * @param {Number} [samplesCount= 10]
6
+ * @param {Number} [min= 1000]
7
+ * @returns {Function}
8
+ */
9
+ function speedometer(samplesCount, min) {
10
+ samplesCount = samplesCount || 10;
11
+ const bytes = new Array(samplesCount);
12
+ const timestamps = new Array(samplesCount);
13
+ let head = 0;
14
+ let tail = 0;
15
+ let firstSampleTS;
16
+
17
+ min = min !== undefined ? min : 1000;
18
+
19
+ return function push(chunkLength) {
20
+ const now = Date.now();
21
+
22
+ const startedAt = timestamps[tail];
23
+
24
+ if (!firstSampleTS) {
25
+ firstSampleTS = now;
26
+ }
27
+
28
+ bytes[head] = chunkLength;
29
+ timestamps[head] = now;
30
+
31
+ let i = tail;
32
+ let bytesCount = 0;
33
+
34
+ while (i !== head) {
35
+ bytesCount += bytes[i++];
36
+ i = i % samplesCount;
37
+ }
38
+
39
+ head = (head + 1) % samplesCount;
40
+
41
+ if (head === tail) {
42
+ tail = (tail + 1) % samplesCount;
43
+ }
44
+
45
+ if (now - firstSampleTS < min) {
46
+ return;
47
+ }
48
+
49
+ const passed = startedAt && now - startedAt;
50
+
51
+ return passed ? Math.round(bytesCount * 1000 / passed) : undefined;
52
+ };
53
+ }
54
+
55
+ export default speedometer;
@@ -18,10 +18,11 @@
18
18
  * ```
19
19
  *
20
20
  * @param {Function} callback
21
+ *
21
22
  * @returns {Function}
22
23
  */
23
- module.exports = function spread(callback) {
24
+ export default function spread(callback) {
24
25
  return function wrap(arr) {
25
26
  return callback.apply(null, arr);
26
27
  };
27
- };
28
+ }
@@ -0,0 +1,33 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Throttle decorator
5
+ * @param {Function} fn
6
+ * @param {Number} freq
7
+ * @return {Function}
8
+ */
9
+ function throttle(fn, freq) {
10
+ let timestamp = 0;
11
+ const threshold = 1000 / freq;
12
+ let timer = null;
13
+ return function throttled(force, args) {
14
+ const now = Date.now();
15
+ if (force || now - timestamp > threshold) {
16
+ if (timer) {
17
+ clearTimeout(timer);
18
+ timer = null;
19
+ }
20
+ timestamp = now;
21
+ return fn.apply(null, args);
22
+ }
23
+ if (!timer) {
24
+ timer = setTimeout(() => {
25
+ timer = null;
26
+ timestamp = Date.now();
27
+ return fn.apply(null, args);
28
+ }, threshold - (now - timestamp));
29
+ }
30
+ };
31
+ }
32
+
33
+ export default throttle;
@@ -1,19 +1,127 @@
1
1
  'use strict';
2
2
 
3
- var utils = require('../utils');
3
+ import utils from '../utils.js';
4
+ import AxiosError from '../core/AxiosError.js';
5
+ import envFormData from '../env/classes/FormData.js';
6
+
7
+ /**
8
+ * Determines if the given thing is a array or js object.
9
+ *
10
+ * @param {string} thing - The object or array to be visited.
11
+ *
12
+ * @returns {boolean}
13
+ */
14
+ function isVisitable(thing) {
15
+ return utils.isPlainObject(thing) || utils.isArray(thing);
16
+ }
17
+
18
+ /**
19
+ * It removes the brackets from the end of a string
20
+ *
21
+ * @param {string} key - The key of the parameter.
22
+ *
23
+ * @returns {string} the key without the brackets.
24
+ */
25
+ function removeBrackets(key) {
26
+ return utils.endsWith(key, '[]') ? key.slice(0, -2) : key;
27
+ }
28
+
29
+ /**
30
+ * It takes a path, a key, and a boolean, and returns a string
31
+ *
32
+ * @param {string} path - The path to the current key.
33
+ * @param {string} key - The key of the current object being iterated over.
34
+ * @param {string} dots - If true, the key will be rendered with dots instead of brackets.
35
+ *
36
+ * @returns {string} The path to the current key.
37
+ */
38
+ function renderKey(path, key, dots) {
39
+ if (!path) return key;
40
+ return path.concat(key).map(function each(token, i) {
41
+ // eslint-disable-next-line no-param-reassign
42
+ token = removeBrackets(token);
43
+ return !dots && i ? '[' + token + ']' : token;
44
+ }).join(dots ? '.' : '');
45
+ }
46
+
47
+ /**
48
+ * If the array is an array and none of its elements are visitable, then it's a flat array.
49
+ *
50
+ * @param {Array<any>} arr - The array to check
51
+ *
52
+ * @returns {boolean}
53
+ */
54
+ function isFlatArray(arr) {
55
+ return utils.isArray(arr) && !arr.some(isVisitable);
56
+ }
57
+
58
+ const predicates = utils.toFlatObject(utils, {}, null, function filter(prop) {
59
+ return /^is[A-Z]/.test(prop);
60
+ });
61
+
62
+ /**
63
+ * If the thing is a FormData object, return true, otherwise return false.
64
+ *
65
+ * @param {unknown} thing - The thing to check.
66
+ *
67
+ * @returns {boolean}
68
+ */
69
+ function isSpecCompliant(thing) {
70
+ return thing && utils.isFunction(thing.append) && thing[Symbol.toStringTag] === 'FormData' && thing[Symbol.iterator];
71
+ }
4
72
 
5
73
  /**
6
74
  * Convert a data object to FormData
75
+ *
7
76
  * @param {Object} obj
8
77
  * @param {?Object} [formData]
78
+ * @param {?Object} [options]
79
+ * @param {Function} [options.visitor]
80
+ * @param {Boolean} [options.metaTokens = true]
81
+ * @param {Boolean} [options.dots = false]
82
+ * @param {?Boolean} [options.indexes = false]
83
+ *
9
84
  * @returns {Object}
10
85
  **/
11
86
 
12
- function toFormData(obj, formData) {
87
+ /**
88
+ * It converts an object into a FormData object
89
+ *
90
+ * @param {Object<any, any>} obj - The object to convert to form data.
91
+ * @param {string} formData - The FormData object to append to.
92
+ * @param {Object<string, any>} options
93
+ *
94
+ * @returns
95
+ */
96
+ function toFormData(obj, formData, options) {
97
+ if (!utils.isObject(obj)) {
98
+ throw new TypeError('target must be an object');
99
+ }
100
+
13
101
  // eslint-disable-next-line no-param-reassign
14
- formData = formData || new FormData();
102
+ formData = formData || new (envFormData || FormData)();
15
103
 
16
- var stack = [];
104
+ // eslint-disable-next-line no-param-reassign
105
+ options = utils.toFlatObject(options, {
106
+ metaTokens: true,
107
+ dots: false,
108
+ indexes: false
109
+ }, false, function defined(option, source) {
110
+ // eslint-disable-next-line no-eq-null,eqeqeq
111
+ return !utils.isUndefined(source[option]);
112
+ });
113
+
114
+ const metaTokens = options.metaTokens;
115
+ // eslint-disable-next-line no-use-before-define
116
+ const visitor = options.visitor || defaultVisitor;
117
+ const dots = options.dots;
118
+ const indexes = options.indexes;
119
+ const _Blob = options.Blob || typeof Blob !== 'undefined' && Blob;
120
+ const useBlob = _Blob && isSpecCompliant(formData);
121
+
122
+ if (!utils.isFunction(visitor)) {
123
+ throw new TypeError('visitor must be a function');
124
+ }
17
125
 
18
126
  function convertValue(value) {
19
127
  if (value === null) return '';
@@ -22,46 +130,95 @@ function toFormData(obj, formData) {
22
130
  return value.toISOString();
23
131
  }
24
132
 
133
+ if (!useBlob && utils.isBlob(value)) {
134
+ throw new AxiosError('Blob is not supported. Use a Buffer instead.');
135
+ }
136
+
25
137
  if (utils.isArrayBuffer(value) || utils.isTypedArray(value)) {
26
- return typeof Blob === 'function' ? new Blob([value]) : Buffer.from(value);
138
+ return useBlob && typeof Blob === 'function' ? new Blob([value]) : Buffer.from(value);
27
139
  }
28
140
 
29
141
  return value;
30
142
  }
31
143
 
32
- function build(data, parentKey) {
33
- if (utils.isPlainObject(data) || utils.isArray(data)) {
34
- if (stack.indexOf(data) !== -1) {
35
- throw Error('Circular reference detected in ' + parentKey);
144
+ /**
145
+ * Default visitor.
146
+ *
147
+ * @param {*} value
148
+ * @param {String|Number} key
149
+ * @param {Array<String|Number>} path
150
+ * @this {FormData}
151
+ *
152
+ * @returns {boolean} return true to visit the each prop of the value recursively
153
+ */
154
+ function defaultVisitor(value, key, path) {
155
+ let arr = value;
156
+
157
+ if (value && !path && typeof value === 'object') {
158
+ if (utils.endsWith(key, '{}')) {
159
+ // eslint-disable-next-line no-param-reassign
160
+ key = metaTokens ? key : key.slice(0, -2);
161
+ // eslint-disable-next-line no-param-reassign
162
+ value = JSON.stringify(value);
163
+ } else if (
164
+ (utils.isArray(value) && isFlatArray(value)) ||
165
+ (utils.isFileList(value) || utils.endsWith(key, '[]') && (arr = utils.toArray(value))
166
+ )) {
167
+ // eslint-disable-next-line no-param-reassign
168
+ key = removeBrackets(key);
169
+
170
+ arr.forEach(function each(el, index) {
171
+ !(utils.isUndefined(el) || el === null) && formData.append(
172
+ // eslint-disable-next-line no-nested-ternary
173
+ indexes === true ? renderKey([key], index, dots) : (indexes === null ? key : key + '[]'),
174
+ convertValue(el)
175
+ );
176
+ });
177
+ return false;
36
178
  }
179
+ }
37
180
 
38
- stack.push(data);
39
-
40
- utils.forEach(data, function each(value, key) {
41
- if (utils.isUndefined(value)) return;
42
- var fullKey = parentKey ? parentKey + '.' + key : key;
43
- var arr;
44
-
45
- if (value && !parentKey && typeof value === 'object') {
46
- if (utils.endsWith(key, '{}')) {
47
- // eslint-disable-next-line no-param-reassign
48
- value = JSON.stringify(value);
49
- } else if (utils.endsWith(key, '[]') && (arr = utils.toArray(value))) {
50
- // eslint-disable-next-line func-names
51
- arr.forEach(function(el) {
52
- !utils.isUndefined(el) && formData.append(fullKey, convertValue(el));
53
- });
54
- return;
55
- }
56
- }
57
-
58
- build(value, fullKey);
59
- });
60
-
61
- stack.pop();
62
- } else {
63
- formData.append(parentKey, convertValue(data));
181
+ if (isVisitable(value)) {
182
+ return true;
64
183
  }
184
+
185
+ formData.append(renderKey(path, key, dots), convertValue(value));
186
+
187
+ return false;
188
+ }
189
+
190
+ const stack = [];
191
+
192
+ const exposedHelpers = Object.assign(predicates, {
193
+ defaultVisitor,
194
+ convertValue,
195
+ isVisitable
196
+ });
197
+
198
+ function build(value, path) {
199
+ if (utils.isUndefined(value)) return;
200
+
201
+ if (stack.indexOf(value) !== -1) {
202
+ throw Error('Circular reference detected in ' + path.join('.'));
203
+ }
204
+
205
+ stack.push(value);
206
+
207
+ utils.forEach(value, function each(el, key) {
208
+ const result = !(utils.isUndefined(el) || el === null) && visitor.call(
209
+ formData, el, utils.isString(key) ? key.trim() : key, path, exposedHelpers
210
+ );
211
+
212
+ if (result === true) {
213
+ build(el, path ? path.concat(key) : [key]);
214
+ }
215
+ });
216
+
217
+ stack.pop();
218
+ }
219
+
220
+ if (!utils.isObject(obj)) {
221
+ throw new TypeError('data must be an object');
65
222
  }
66
223
 
67
224
  build(obj);
@@ -69,4 +226,4 @@ function toFormData(obj, formData) {
69
226
  return formData;
70
227
  }
71
228
 
72
- module.exports = toFormData;
229
+ export default toFormData;
@@ -0,0 +1,18 @@
1
+ 'use strict';
2
+
3
+ import utils from '../utils.js';
4
+ import toFormData from './toFormData.js';
5
+ import platform from '../platform/index.js';
6
+
7
+ export default function toURLEncodedForm(data, options) {
8
+ return toFormData(data, new platform.classes.URLSearchParams(), Object.assign({
9
+ visitor: function(value, key, path, helpers) {
10
+ if (platform.isNode && utils.isBuffer(value)) {
11
+ this.append(key, value.toString('base64'));
12
+ return false;
13
+ }
14
+
15
+ return helpers.defaultVisitor.apply(this, arguments);
16
+ }
17
+ }, options));
18
+ }
@@ -1,24 +1,26 @@
1
1
  'use strict';
2
2
 
3
- var VERSION = require('../env/data').version;
4
- var AxiosError = require('../core/AxiosError');
3
+ import {VERSION} from '../env/data.js';
4
+ import AxiosError from '../core/AxiosError.js';
5
5
 
6
- var validators = {};
6
+ const validators = {};
7
7
 
8
8
  // eslint-disable-next-line func-names
9
- ['object', 'boolean', 'number', 'function', 'string', 'symbol'].forEach(function(type, i) {
9
+ ['object', 'boolean', 'number', 'function', 'string', 'symbol'].forEach((type, i) => {
10
10
  validators[type] = function validator(thing) {
11
11
  return typeof thing === type || 'a' + (i < 1 ? 'n ' : ' ') + type;
12
12
  };
13
13
  });
14
14
 
15
- var deprecatedWarnings = {};
15
+ const deprecatedWarnings = {};
16
16
 
17
17
  /**
18
18
  * Transitional option validator
19
+ *
19
20
  * @param {function|boolean?} validator - set to false if the transitional option has been removed
20
21
  * @param {string?} version - deprecated version / removed since version
21
22
  * @param {string?} message - some message with additional info
23
+ *
22
24
  * @returns {function}
23
25
  */
24
26
  validators.transitional = function transitional(validator, version, message) {
@@ -27,7 +29,7 @@ validators.transitional = function transitional(validator, version, message) {
27
29
  }
28
30
 
29
31
  // eslint-disable-next-line func-names
30
- return function(value, opt, opts) {
32
+ return (value, opt, opts) => {
31
33
  if (validator === false) {
32
34
  throw new AxiosError(
33
35
  formatMessage(opt, ' has been removed' + (version ? ' in ' + version : '')),
@@ -52,23 +54,26 @@ validators.transitional = function transitional(validator, version, message) {
52
54
 
53
55
  /**
54
56
  * Assert object's properties type
57
+ *
55
58
  * @param {object} options
56
59
  * @param {object} schema
57
60
  * @param {boolean?} allowUnknown
61
+ *
62
+ * @returns {object}
58
63
  */
59
64
 
60
65
  function assertOptions(options, schema, allowUnknown) {
61
66
  if (typeof options !== 'object') {
62
67
  throw new AxiosError('options must be an object', AxiosError.ERR_BAD_OPTION_VALUE);
63
68
  }
64
- var keys = Object.keys(options);
65
- var i = keys.length;
69
+ const keys = Object.keys(options);
70
+ let i = keys.length;
66
71
  while (i-- > 0) {
67
- var opt = keys[i];
68
- var validator = schema[opt];
72
+ const opt = keys[i];
73
+ const validator = schema[opt];
69
74
  if (validator) {
70
- var value = options[opt];
71
- var result = value === undefined || validator(value, opt, options);
75
+ const value = options[opt];
76
+ const result = value === undefined || validator(value, opt, options);
72
77
  if (result !== true) {
73
78
  throw new AxiosError('option ' + opt + ' must be ' + result, AxiosError.ERR_BAD_OPTION_VALUE);
74
79
  }
@@ -80,7 +85,7 @@ function assertOptions(options, schema, allowUnknown) {
80
85
  }
81
86
  }
82
87
 
83
- module.exports = {
84
- assertOptions: assertOptions,
85
- validators: validators
88
+ export default {
89
+ assertOptions,
90
+ validators
86
91
  };
@@ -0,0 +1,3 @@
1
+ 'use strict';
2
+
3
+ export default FormData;
@@ -0,0 +1,4 @@
1
+ 'use strict';
2
+
3
+ import AxiosURLSearchParams from '../../../helpers/AxiosURLSearchParams.js';
4
+ export default typeof URLSearchParams !== 'undefined' ? URLSearchParams : AxiosURLSearchParams;