axios 0.17.1 → 0.19.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 +114 -0
- package/LICENSE +1 -1
- package/README.md +102 -30
- package/dist/axios.js +615 -548
- package/dist/axios.map +1 -1
- package/dist/axios.min.js +4 -4
- package/dist/axios.min.map +1 -1
- package/index.d.ts +40 -15
- package/lib/adapters/http.js +77 -30
- package/lib/adapters/xhr.js +18 -24
- package/lib/axios.js +2 -1
- package/lib/core/Axios.js +13 -6
- package/lib/core/enhanceError.js +21 -0
- package/lib/core/mergeConfig.js +51 -0
- package/lib/core/settle.js +1 -2
- package/lib/defaults.js +10 -4
- package/lib/helpers/buildURL.js +6 -3
- package/lib/helpers/cookies.js +41 -41
- package/lib/helpers/isURLSameOrigin.js +38 -38
- package/lib/utils.js +32 -1
- package/package.json +23 -23
- package/lib/helpers/btoa.js +0 -36
package/lib/helpers/cookies.js
CHANGED
@@ -6,48 +6,48 @@ module.exports = (
|
|
6
6
|
utils.isStandardBrowserEnv() ?
|
7
7
|
|
8
8
|
// Standard browser envs support document.cookie
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
9
|
+
(function standardBrowserEnv() {
|
10
|
+
return {
|
11
|
+
write: function write(name, value, expires, path, domain, secure) {
|
12
|
+
var cookie = [];
|
13
|
+
cookie.push(name + '=' + encodeURIComponent(value));
|
14
|
+
|
15
|
+
if (utils.isNumber(expires)) {
|
16
|
+
cookie.push('expires=' + new Date(expires).toGMTString());
|
17
|
+
}
|
18
|
+
|
19
|
+
if (utils.isString(path)) {
|
20
|
+
cookie.push('path=' + path);
|
21
|
+
}
|
22
|
+
|
23
|
+
if (utils.isString(domain)) {
|
24
|
+
cookie.push('domain=' + domain);
|
25
|
+
}
|
26
|
+
|
27
|
+
if (secure === true) {
|
28
|
+
cookie.push('secure');
|
29
|
+
}
|
30
|
+
|
31
|
+
document.cookie = cookie.join('; ');
|
32
|
+
},
|
33
|
+
|
34
|
+
read: function read(name) {
|
35
|
+
var match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
|
36
|
+
return (match ? decodeURIComponent(match[3]) : null);
|
37
|
+
},
|
38
|
+
|
39
|
+
remove: function remove(name) {
|
40
|
+
this.write(name, '', Date.now() - 86400000);
|
17
41
|
}
|
18
|
-
|
19
|
-
|
20
|
-
cookie.push('path=' + path);
|
21
|
-
}
|
22
|
-
|
23
|
-
if (utils.isString(domain)) {
|
24
|
-
cookie.push('domain=' + domain);
|
25
|
-
}
|
26
|
-
|
27
|
-
if (secure === true) {
|
28
|
-
cookie.push('secure');
|
29
|
-
}
|
30
|
-
|
31
|
-
document.cookie = cookie.join('; ');
|
32
|
-
},
|
33
|
-
|
34
|
-
read: function read(name) {
|
35
|
-
var match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
|
36
|
-
return (match ? decodeURIComponent(match[3]) : null);
|
37
|
-
},
|
38
|
-
|
39
|
-
remove: function remove(name) {
|
40
|
-
this.write(name, '', Date.now() - 86400000);
|
41
|
-
}
|
42
|
-
};
|
43
|
-
})() :
|
42
|
+
};
|
43
|
+
})() :
|
44
44
|
|
45
45
|
// Non standard browser env (web workers, react-native) lack needed support.
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
46
|
+
(function nonStandardBrowserEnv() {
|
47
|
+
return {
|
48
|
+
write: function write() {},
|
49
|
+
read: function read() { return null; },
|
50
|
+
remove: function remove() {}
|
51
|
+
};
|
52
|
+
})()
|
53
53
|
);
|
@@ -7,62 +7,62 @@ module.exports = (
|
|
7
7
|
|
8
8
|
// Standard browser envs have full support of the APIs needed to test
|
9
9
|
// whether the request URL is of the same origin as current location.
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
(function standardBrowserEnv() {
|
11
|
+
var msie = /(msie|trident)/i.test(navigator.userAgent);
|
12
|
+
var urlParsingNode = document.createElement('a');
|
13
|
+
var 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
|
-
|
22
|
-
|
21
|
+
function resolveURL(url) {
|
22
|
+
var href = url;
|
23
23
|
|
24
|
-
|
24
|
+
if (msie) {
|
25
25
|
// IE needs attribute set twice to normalize properties
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
urlParsingNode.setAttribute('href', href);
|
27
|
+
href = urlParsingNode.href;
|
28
|
+
}
|
29
29
|
|
30
|
-
|
30
|
+
urlParsingNode.setAttribute('href', href);
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
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
|
+
}
|
46
46
|
|
47
|
-
|
47
|
+
originURL = resolveURL(window.location.href);
|
48
48
|
|
49
|
-
|
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
|
-
|
56
|
-
|
57
|
-
|
55
|
+
return function isURLSameOrigin(requestURL) {
|
56
|
+
var parsed = (utils.isString(requestURL)) ? resolveURL(requestURL) : requestURL;
|
57
|
+
return (parsed.protocol === originURL.protocol &&
|
58
58
|
parsed.host === originURL.host);
|
59
|
-
|
60
|
-
|
59
|
+
};
|
60
|
+
})() :
|
61
61
|
|
62
62
|
// Non standard browser envs (web workers, react-native) lack needed support.
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
63
|
+
(function nonStandardBrowserEnv() {
|
64
|
+
return function isURLSameOrigin() {
|
65
|
+
return true;
|
66
|
+
};
|
67
|
+
})()
|
68
68
|
);
|
package/lib/utils.js
CHANGED
@@ -177,9 +177,13 @@ function trim(str) {
|
|
177
177
|
*
|
178
178
|
* react-native:
|
179
179
|
* navigator.product -> 'ReactNative'
|
180
|
+
* nativescript
|
181
|
+
* navigator.product -> 'NativeScript' or 'NS'
|
180
182
|
*/
|
181
183
|
function isStandardBrowserEnv() {
|
182
|
-
if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative'
|
184
|
+
if (typeof navigator !== 'undefined' && (navigator.product === 'ReactNative' ||
|
185
|
+
navigator.product === 'NativeScript' ||
|
186
|
+
navigator.product === 'NS')) {
|
183
187
|
return false;
|
184
188
|
}
|
185
189
|
return (
|
@@ -260,6 +264,32 @@ function merge(/* obj1, obj2, obj3, ... */) {
|
|
260
264
|
return result;
|
261
265
|
}
|
262
266
|
|
267
|
+
/**
|
268
|
+
* Function equal to merge with the difference being that no reference
|
269
|
+
* to original objects is kept.
|
270
|
+
*
|
271
|
+
* @see merge
|
272
|
+
* @param {Object} obj1 Object to merge
|
273
|
+
* @returns {Object} Result of all merge properties
|
274
|
+
*/
|
275
|
+
function deepMerge(/* obj1, obj2, obj3, ... */) {
|
276
|
+
var result = {};
|
277
|
+
function assignValue(val, key) {
|
278
|
+
if (typeof result[key] === 'object' && typeof val === 'object') {
|
279
|
+
result[key] = deepMerge(result[key], val);
|
280
|
+
} else if (typeof val === 'object') {
|
281
|
+
result[key] = deepMerge({}, val);
|
282
|
+
} else {
|
283
|
+
result[key] = val;
|
284
|
+
}
|
285
|
+
}
|
286
|
+
|
287
|
+
for (var i = 0, l = arguments.length; i < l; i++) {
|
288
|
+
forEach(arguments[i], assignValue);
|
289
|
+
}
|
290
|
+
return result;
|
291
|
+
}
|
292
|
+
|
263
293
|
/**
|
264
294
|
* Extends object a by mutably adding to it the properties of object b.
|
265
295
|
*
|
@@ -298,6 +328,7 @@ module.exports = {
|
|
298
328
|
isStandardBrowserEnv: isStandardBrowserEnv,
|
299
329
|
forEach: forEach,
|
300
330
|
merge: merge,
|
331
|
+
deepMerge: deepMerge,
|
301
332
|
extend: extend,
|
302
333
|
trim: trim
|
303
334
|
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "axios",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.19.0",
|
4
4
|
"description": "Promise based HTTP client for the browser and node.js",
|
5
5
|
"main": "index.js",
|
6
6
|
"scripts": {
|
@@ -11,7 +11,8 @@
|
|
11
11
|
"version": "npm run build && grunt version && git add -A dist && git add CHANGELOG.md bower.json package.json",
|
12
12
|
"postversion": "git push && git push --tags",
|
13
13
|
"examples": "node ./examples/server.js",
|
14
|
-
"coveralls": "cat coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js"
|
14
|
+
"coveralls": "cat coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
|
15
|
+
"fix": "eslint --fix lib/**/*.js"
|
15
16
|
},
|
16
17
|
"repository": {
|
17
18
|
"type": "git",
|
@@ -31,50 +32,49 @@
|
|
31
32
|
},
|
32
33
|
"homepage": "https://github.com/axios/axios",
|
33
34
|
"devDependencies": {
|
34
|
-
"bundlesize": "^0.
|
35
|
-
"coveralls": "^
|
36
|
-
"es6-promise": "^4.
|
37
|
-
"grunt": "^1.0.
|
35
|
+
"bundlesize": "^0.17.0",
|
36
|
+
"coveralls": "^3.0.0",
|
37
|
+
"es6-promise": "^4.2.4",
|
38
|
+
"grunt": "^1.0.2",
|
38
39
|
"grunt-banner": "^0.6.0",
|
39
40
|
"grunt-cli": "^1.2.0",
|
40
|
-
"grunt-contrib-clean": "^1.
|
41
|
-
"grunt-contrib-nodeunit": "^1.0.0",
|
41
|
+
"grunt-contrib-clean": "^1.1.0",
|
42
42
|
"grunt-contrib-watch": "^1.0.0",
|
43
|
-
"grunt-eslint": "^
|
43
|
+
"grunt-eslint": "^20.1.0",
|
44
44
|
"grunt-karma": "^2.0.0",
|
45
|
-
"grunt-
|
45
|
+
"grunt-mocha-test": "^0.13.3",
|
46
|
+
"grunt-ts": "^6.0.0-beta.19",
|
46
47
|
"grunt-webpack": "^1.0.18",
|
47
48
|
"istanbul-instrumenter-loader": "^1.0.0",
|
48
49
|
"jasmine-core": "^2.4.1",
|
49
50
|
"karma": "^1.3.0",
|
50
|
-
"karma-chrome-launcher": "^2.
|
51
|
-
"karma-coverage": "^1.
|
52
|
-
"karma-firefox-launcher": "^1.
|
53
|
-
"karma-jasmine": "^1.
|
51
|
+
"karma-chrome-launcher": "^2.2.0",
|
52
|
+
"karma-coverage": "^1.1.1",
|
53
|
+
"karma-firefox-launcher": "^1.1.0",
|
54
|
+
"karma-jasmine": "^1.1.1",
|
54
55
|
"karma-jasmine-ajax": "^0.1.13",
|
55
56
|
"karma-opera-launcher": "^1.0.0",
|
56
|
-
"karma-phantomjs-launcher": "^1.0.0",
|
57
57
|
"karma-safari-launcher": "^1.0.0",
|
58
|
-
"karma-sauce-launcher": "^1.
|
58
|
+
"karma-sauce-launcher": "^1.2.0",
|
59
59
|
"karma-sinon": "^1.0.5",
|
60
60
|
"karma-sourcemap-loader": "^0.3.7",
|
61
61
|
"karma-webpack": "^1.7.0",
|
62
62
|
"load-grunt-tasks": "^3.5.2",
|
63
63
|
"minimist": "^1.2.0",
|
64
|
-
"
|
65
|
-
"sinon": "^
|
64
|
+
"mocha": "^5.2.0",
|
65
|
+
"sinon": "^4.5.0",
|
66
|
+
"typescript": "^2.8.1",
|
67
|
+
"url-search-params": "^0.10.0",
|
66
68
|
"webpack": "^1.13.1",
|
67
|
-
"webpack-dev-server": "^1.14.1"
|
68
|
-
"url-search-params": "^0.6.1",
|
69
|
-
"typescript": "^2.0.3"
|
69
|
+
"webpack-dev-server": "^1.14.1"
|
70
70
|
},
|
71
71
|
"browser": {
|
72
72
|
"./lib/adapters/http.js": "./lib/adapters/xhr.js"
|
73
73
|
},
|
74
74
|
"typings": "./index.d.ts",
|
75
75
|
"dependencies": {
|
76
|
-
"follow-redirects": "
|
77
|
-
"is-buffer": "^
|
76
|
+
"follow-redirects": "1.5.10",
|
77
|
+
"is-buffer": "^2.0.2"
|
78
78
|
},
|
79
79
|
"bundlesize": [
|
80
80
|
{
|
package/lib/helpers/btoa.js
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
'use strict';
|
2
|
-
|
3
|
-
// btoa polyfill for IE<10 courtesy https://github.com/davidchambers/Base64.js
|
4
|
-
|
5
|
-
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
6
|
-
|
7
|
-
function E() {
|
8
|
-
this.message = 'String contains an invalid character';
|
9
|
-
}
|
10
|
-
E.prototype = new Error;
|
11
|
-
E.prototype.code = 5;
|
12
|
-
E.prototype.name = 'InvalidCharacterError';
|
13
|
-
|
14
|
-
function btoa(input) {
|
15
|
-
var str = String(input);
|
16
|
-
var output = '';
|
17
|
-
for (
|
18
|
-
// initialize result and counter
|
19
|
-
var block, charCode, idx = 0, map = chars;
|
20
|
-
// if the next str index does not exist:
|
21
|
-
// change the mapping table to "="
|
22
|
-
// check if d has no fractional digits
|
23
|
-
str.charAt(idx | 0) || (map = '=', idx % 1);
|
24
|
-
// "8 - idx % 1 * 8" generates the sequence 2, 4, 6, 8
|
25
|
-
output += map.charAt(63 & block >> 8 - idx % 1 * 8)
|
26
|
-
) {
|
27
|
-
charCode = str.charCodeAt(idx += 3 / 4);
|
28
|
-
if (charCode > 0xFF) {
|
29
|
-
throw new E();
|
30
|
-
}
|
31
|
-
block = block << 8 | charCode;
|
32
|
-
}
|
33
|
-
return output;
|
34
|
-
}
|
35
|
-
|
36
|
-
module.exports = btoa;
|