axios 1.0.0-alpha.1 → 1.0.0
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.
- package/CHANGELOG.md +55 -1
- package/README.md +59 -48
- package/SECURITY.md +3 -2
- package/bin/ssl_hotfix.js +1 -1
- package/dist/axios.js +1552 -975
- package/dist/axios.js.map +1 -1
- package/dist/axios.min.js +1 -1
- package/dist/axios.min.js.map +1 -1
- package/dist/esm/axios.js +1471 -865
- package/dist/esm/axios.js.map +1 -1
- package/dist/esm/axios.min.js +1 -1
- package/dist/esm/axios.min.js.map +1 -1
- package/dist/node/axios.cjs +3750 -0
- package/dist/node/axios.cjs.map +1 -0
- package/gulpfile.js +88 -0
- package/index.d.ts +208 -63
- package/index.js +2 -1
- package/karma.conf.cjs +250 -0
- package/lib/adapters/http.js +251 -131
- package/lib/adapters/index.js +33 -0
- package/lib/adapters/xhr.js +79 -56
- package/lib/axios.js +33 -25
- package/lib/cancel/CancelToken.js +91 -88
- package/lib/cancel/CanceledError.js +5 -4
- package/lib/cancel/isCancel.js +2 -2
- package/lib/core/Axios.js +127 -100
- package/lib/core/AxiosError.js +10 -7
- package/lib/core/AxiosHeaders.js +274 -0
- package/lib/core/InterceptorManager.js +61 -53
- package/lib/core/buildFullPath.js +5 -4
- package/lib/core/dispatchRequest.js +21 -39
- package/lib/core/mergeConfig.js +8 -7
- package/lib/core/settle.js +6 -4
- package/lib/core/transformData.js +15 -10
- package/lib/defaults/index.js +46 -39
- package/lib/defaults/transitional.js +1 -1
- package/lib/env/classes/FormData.js +2 -2
- package/lib/env/data.js +1 -3
- package/lib/helpers/AxiosTransformStream.js +191 -0
- package/lib/helpers/AxiosURLSearchParams.js +23 -7
- package/lib/helpers/bind.js +2 -2
- package/lib/helpers/buildURL.js +16 -7
- package/lib/helpers/combineURLs.js +3 -2
- package/lib/helpers/cookies.js +43 -44
- package/lib/helpers/deprecatedMethod.js +4 -2
- package/lib/helpers/formDataToJSON.js +36 -15
- package/lib/helpers/fromDataURI.js +15 -13
- package/lib/helpers/isAbsoluteURL.js +3 -2
- package/lib/helpers/isAxiosError.js +4 -3
- package/lib/helpers/isURLSameOrigin.js +55 -56
- package/lib/helpers/null.js +1 -1
- package/lib/helpers/parseHeaders.js +24 -22
- package/lib/helpers/parseProtocol.js +3 -3
- package/lib/helpers/speedometer.js +55 -0
- package/lib/helpers/spread.js +3 -2
- package/lib/helpers/throttle.js +33 -0
- package/lib/helpers/toFormData.js +68 -18
- package/lib/helpers/toURLEncodedForm.js +5 -5
- package/lib/helpers/validator.js +20 -15
- package/lib/platform/browser/classes/FormData.js +1 -1
- package/lib/platform/browser/classes/URLSearchParams.js +2 -3
- package/lib/platform/browser/index.js +38 -6
- package/lib/platform/index.js +2 -2
- package/lib/platform/node/classes/FormData.js +2 -2
- package/lib/platform/node/classes/URLSearchParams.js +2 -3
- package/lib/platform/node/index.js +5 -4
- package/lib/utils.js +293 -191
- package/package.json +55 -22
- package/rollup.config.js +36 -6
- package/lib/helpers/normalizeHeaderName.js +0 -12
@@ -1,68 +1,67 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
-
|
3
|
+
import utils from './../utils.js';
|
4
|
+
import platform from '../platform/index.js';
|
4
5
|
|
5
|
-
|
6
|
-
utils.isStandardBrowserEnv() ?
|
6
|
+
export default platform.isStandardBrowserEnv ?
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
if (msie) {
|
25
|
-
// IE needs attribute set twice to normalize properties
|
26
|
-
urlParsingNode.setAttribute('href', href);
|
27
|
-
href = urlParsingNode.href;
|
28
|
-
}
|
15
|
+
/**
|
16
|
+
* Parse a URL to discover it's components
|
17
|
+
*
|
18
|
+
* @param {String} url The URL to be parsed
|
19
|
+
* @returns {Object}
|
20
|
+
*/
|
21
|
+
function resolveURL(url) {
|
22
|
+
let href = url;
|
29
23
|
|
24
|
+
if (msie) {
|
25
|
+
// IE needs attribute set twice to normalize properties
|
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
|
-
|
30
|
+
urlParsingNode.setAttribute('href', href);
|
48
31
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
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
|
59
44
|
};
|
60
|
-
}
|
45
|
+
}
|
61
46
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
}
|
68
|
-
|
47
|
+
originURL = resolveURL(window.location.href);
|
48
|
+
|
49
|
+
/**
|
50
|
+
* Determine if a URL shares the same origin as the current location
|
51
|
+
*
|
52
|
+
* @param {String} requestURL The URL to test
|
53
|
+
* @returns {boolean} True if URL shares the same origin, otherwise false
|
54
|
+
*/
|
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
|
+
|
62
|
+
// Non standard browser envs (web workers, react-native) lack needed support.
|
63
|
+
(function nonStandardBrowserEnv() {
|
64
|
+
return function isURLSameOrigin() {
|
65
|
+
return true;
|
66
|
+
};
|
67
|
+
})();
|
package/lib/helpers/null.js
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
// eslint-disable-next-line strict
|
2
|
-
|
2
|
+
export default null;
|
@@ -1,15 +1,15 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
-
|
3
|
+
import utils from './../utils.js';
|
4
4
|
|
5
|
-
//
|
5
|
+
// RawAxiosHeaders whose duplicates are ignored by node
|
6
6
|
// c.f. https://nodejs.org/api/http.html#http_message_headers
|
7
|
-
|
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}
|
24
|
+
* @param {String} rawHeaders Headers needing to be parsed
|
25
|
+
*
|
25
26
|
* @returns {Object} Headers parsed into an object
|
26
27
|
*/
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
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
|
-
|
34
|
+
rawHeaders && rawHeaders.split('\n').forEach(function parser(line) {
|
36
35
|
i = line.indexOf(':');
|
37
|
-
key =
|
38
|
-
val =
|
36
|
+
key = line.substring(0, i).trim().toLowerCase();
|
37
|
+
val = line.substring(i + 1).trim();
|
39
38
|
|
40
|
-
if (key) {
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
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] =
|
47
|
+
parsed[key] = [val];
|
48
48
|
}
|
49
|
+
} else {
|
50
|
+
parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val;
|
49
51
|
}
|
50
52
|
});
|
51
53
|
|
@@ -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;
|
package/lib/helpers/spread.js
CHANGED
@@ -18,10 +18,11 @@
|
|
18
18
|
* ```
|
19
19
|
*
|
20
20
|
* @param {Function} callback
|
21
|
+
*
|
21
22
|
* @returns {Function}
|
22
23
|
*/
|
23
|
-
|
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,17 +1,40 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
import utils from '../utils.js';
|
4
|
+
import AxiosError from '../core/AxiosError.js';
|
5
|
+
import envFormData from '../env/classes/FormData.js';
|
6
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
|
+
*/
|
7
14
|
function isVisitable(thing) {
|
8
15
|
return utils.isPlainObject(thing) || utils.isArray(thing);
|
9
16
|
}
|
10
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
|
+
*/
|
11
25
|
function removeBrackets(key) {
|
12
26
|
return utils.endsWith(key, '[]') ? key.slice(0, -2) : key;
|
13
27
|
}
|
14
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
|
+
*/
|
15
38
|
function renderKey(path, key, dots) {
|
16
39
|
if (!path) return key;
|
17
40
|
return path.concat(key).map(function each(token, i) {
|
@@ -21,20 +44,35 @@ function renderKey(path, key, dots) {
|
|
21
44
|
}).join(dots ? '.' : '');
|
22
45
|
}
|
23
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
|
+
*/
|
24
54
|
function isFlatArray(arr) {
|
25
55
|
return utils.isArray(arr) && !arr.some(isVisitable);
|
26
56
|
}
|
27
57
|
|
28
|
-
|
58
|
+
const predicates = utils.toFlatObject(utils, {}, null, function filter(prop) {
|
29
59
|
return /^is[A-Z]/.test(prop);
|
30
60
|
});
|
31
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
|
+
*/
|
32
69
|
function isSpecCompliant(thing) {
|
33
70
|
return thing && utils.isFunction(thing.append) && thing[Symbol.toStringTag] === 'FormData' && thing[Symbol.iterator];
|
34
71
|
}
|
35
72
|
|
36
73
|
/**
|
37
74
|
* Convert a data object to FormData
|
75
|
+
*
|
38
76
|
* @param {Object} obj
|
39
77
|
* @param {?Object} [formData]
|
40
78
|
* @param {?Object} [options]
|
@@ -42,9 +80,19 @@ function isSpecCompliant(thing) {
|
|
42
80
|
* @param {Boolean} [options.metaTokens = true]
|
43
81
|
* @param {Boolean} [options.dots = false]
|
44
82
|
* @param {?Boolean} [options.indexes = false]
|
83
|
+
*
|
45
84
|
* @returns {Object}
|
46
85
|
**/
|
47
86
|
|
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
|
+
*/
|
48
96
|
function toFormData(obj, formData, options) {
|
49
97
|
if (!utils.isObject(obj)) {
|
50
98
|
throw new TypeError('target must be an object');
|
@@ -63,13 +111,13 @@ function toFormData(obj, formData, options) {
|
|
63
111
|
return !utils.isUndefined(source[option]);
|
64
112
|
});
|
65
113
|
|
66
|
-
|
114
|
+
const metaTokens = options.metaTokens;
|
67
115
|
// eslint-disable-next-line no-use-before-define
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
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);
|
73
121
|
|
74
122
|
if (!utils.isFunction(visitor)) {
|
75
123
|
throw new TypeError('visitor must be a function');
|
@@ -94,15 +142,17 @@ function toFormData(obj, formData, options) {
|
|
94
142
|
}
|
95
143
|
|
96
144
|
/**
|
145
|
+
* Default visitor.
|
97
146
|
*
|
98
147
|
* @param {*} value
|
99
148
|
* @param {String|Number} key
|
100
149
|
* @param {Array<String|Number>} path
|
101
150
|
* @this {FormData}
|
151
|
+
*
|
102
152
|
* @returns {boolean} return true to visit the each prop of the value recursively
|
103
153
|
*/
|
104
154
|
function defaultVisitor(value, key, path) {
|
105
|
-
|
155
|
+
let arr = value;
|
106
156
|
|
107
157
|
if (value && !path && typeof value === 'object') {
|
108
158
|
if (utils.endsWith(key, '{}')) {
|
@@ -137,12 +187,12 @@ function toFormData(obj, formData, options) {
|
|
137
187
|
return false;
|
138
188
|
}
|
139
189
|
|
140
|
-
|
190
|
+
const stack = [];
|
141
191
|
|
142
|
-
|
143
|
-
defaultVisitor
|
144
|
-
convertValue
|
145
|
-
isVisitable
|
192
|
+
const exposedHelpers = Object.assign(predicates, {
|
193
|
+
defaultVisitor,
|
194
|
+
convertValue,
|
195
|
+
isVisitable
|
146
196
|
});
|
147
197
|
|
148
198
|
function build(value, path) {
|
@@ -155,7 +205,7 @@ function toFormData(obj, formData, options) {
|
|
155
205
|
stack.push(value);
|
156
206
|
|
157
207
|
utils.forEach(value, function each(el, key) {
|
158
|
-
|
208
|
+
const result = !utils.isUndefined(el) && visitor.call(
|
159
209
|
formData, el, utils.isString(key) ? key.trim() : key, path, exposedHelpers
|
160
210
|
);
|
161
211
|
|
@@ -176,4 +226,4 @@ function toFormData(obj, formData, options) {
|
|
176
226
|
return formData;
|
177
227
|
}
|
178
228
|
|
179
|
-
|
229
|
+
export default toFormData;
|
@@ -1,10 +1,10 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
import utils from '../utils.js';
|
4
|
+
import toFormData from './toFormData.js';
|
5
|
+
import platform from '../platform/index.js';
|
6
6
|
|
7
|
-
|
7
|
+
export default function toURLEncodedForm(data, options) {
|
8
8
|
return toFormData(data, new platform.classes.URLSearchParams(), Object.assign({
|
9
9
|
visitor: function(value, key, path, helpers) {
|
10
10
|
if (platform.isNode && utils.isBuffer(value)) {
|
@@ -15,4 +15,4 @@ module.exports = function toURLEncodedForm(data, options) {
|
|
15
15
|
return helpers.defaultVisitor.apply(this, arguments);
|
16
16
|
}
|
17
17
|
}, options));
|
18
|
-
}
|
18
|
+
}
|
package/lib/helpers/validator.js
CHANGED
@@ -1,24 +1,26 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
import {VERSION} from '../env/data.js';
|
4
|
+
import AxiosError from '../core/AxiosError.js';
|
5
5
|
|
6
|
-
|
6
|
+
const validators = {};
|
7
7
|
|
8
8
|
// eslint-disable-next-line func-names
|
9
|
-
['object', 'boolean', 'number', 'function', 'string', 'symbol'].forEach(
|
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
|
-
|
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
|
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
|
-
|
65
|
-
|
69
|
+
const keys = Object.keys(options);
|
70
|
+
let i = keys.length;
|
66
71
|
while (i-- > 0) {
|
67
|
-
|
68
|
-
|
72
|
+
const opt = keys[i];
|
73
|
+
const validator = schema[opt];
|
69
74
|
if (validator) {
|
70
|
-
|
71
|
-
|
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
|
-
|
84
|
-
assertOptions
|
85
|
-
validators
|
88
|
+
export default {
|
89
|
+
assertOptions,
|
90
|
+
validators
|
86
91
|
};
|
@@ -1,5 +1,4 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
module.exports = typeof URLSearchParams !== 'undefined' ? URLSearchParams : AxiosURLSearchParams;
|
3
|
+
import AxiosURLSearchParams from '../../../helpers/AxiosURLSearchParams.js';
|
4
|
+
export default typeof URLSearchParams !== 'undefined' ? URLSearchParams : AxiosURLSearchParams;
|
@@ -1,11 +1,43 @@
|
|
1
|
-
|
1
|
+
import URLSearchParams from './classes/URLSearchParams.js'
|
2
|
+
import FormData from './classes/FormData.js'
|
2
3
|
|
3
|
-
|
4
|
+
/**
|
5
|
+
* Determine if we're running in a standard browser environment
|
6
|
+
*
|
7
|
+
* This allows axios to run in a web worker, and react-native.
|
8
|
+
* Both environments support XMLHttpRequest, but not fully standard globals.
|
9
|
+
*
|
10
|
+
* web workers:
|
11
|
+
* typeof window -> undefined
|
12
|
+
* typeof document -> undefined
|
13
|
+
*
|
14
|
+
* react-native:
|
15
|
+
* navigator.product -> 'ReactNative'
|
16
|
+
* nativescript
|
17
|
+
* navigator.product -> 'NativeScript' or 'NS'
|
18
|
+
*
|
19
|
+
* @returns {boolean}
|
20
|
+
*/
|
21
|
+
const isStandardBrowserEnv = (() => {
|
22
|
+
let product;
|
23
|
+
if (typeof navigator !== 'undefined' && (
|
24
|
+
(product = navigator.product) === 'ReactNative' ||
|
25
|
+
product === 'NativeScript' ||
|
26
|
+
product === 'NS')
|
27
|
+
) {
|
28
|
+
return false;
|
29
|
+
}
|
30
|
+
|
31
|
+
return typeof window !== 'undefined' && typeof document !== 'undefined';
|
32
|
+
})();
|
33
|
+
|
34
|
+
export default {
|
4
35
|
isBrowser: true,
|
5
36
|
classes: {
|
6
|
-
URLSearchParams
|
7
|
-
FormData
|
8
|
-
Blob
|
37
|
+
URLSearchParams,
|
38
|
+
FormData,
|
39
|
+
Blob
|
9
40
|
},
|
10
|
-
|
41
|
+
isStandardBrowserEnv,
|
42
|
+
protocols: ['http', 'https', 'file', 'blob', 'url', 'data']
|
11
43
|
};
|
package/lib/platform/index.js
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
|
1
|
+
import platform from './node/index.js';
|
2
2
|
|
3
|
-
|
3
|
+
export {platform as default}
|
@@ -1,3 +1,3 @@
|
|
1
|
-
|
1
|
+
import FormData from 'form-data';
|
2
2
|
|
3
|
-
|
3
|
+
export default FormData;
|