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
@@ -0,0 +1,191 @@
1
+ 'use strict';
2
+
3
+ import stream from 'stream';
4
+ import utils from '../utils.js';
5
+ import throttle from './throttle.js';
6
+ import speedometer from './speedometer.js';
7
+
8
+ const kInternals = Symbol('internals');
9
+
10
+ class AxiosTransformStream extends stream.Transform{
11
+ constructor(options) {
12
+ options = utils.toFlatObject(options, {
13
+ maxRate: 0,
14
+ chunkSize: 64 * 1024,
15
+ minChunkSize: 100,
16
+ timeWindow: 500,
17
+ ticksRate: 2,
18
+ samplesCount: 15
19
+ }, null, (prop, source) => {
20
+ return !utils.isUndefined(source[prop]);
21
+ });
22
+
23
+ super({
24
+ readableHighWaterMark: options.chunkSize
25
+ });
26
+
27
+ const self = this;
28
+
29
+ const internals = this[kInternals] = {
30
+ length: options.length,
31
+ timeWindow: options.timeWindow,
32
+ ticksRate: options.ticksRate,
33
+ chunkSize: options.chunkSize,
34
+ maxRate: options.maxRate,
35
+ minChunkSize: options.minChunkSize,
36
+ bytesSeen: 0,
37
+ isCaptured: false,
38
+ notifiedBytesLoaded: 0,
39
+ ts: Date.now(),
40
+ bytes: 0,
41
+ onReadCallback: null
42
+ };
43
+
44
+ const _speedometer = speedometer(internals.ticksRate * options.samplesCount, internals.timeWindow);
45
+
46
+ this.on('newListener', event => {
47
+ if (event === 'progress') {
48
+ if (!internals.isCaptured) {
49
+ internals.isCaptured = true;
50
+ }
51
+ }
52
+ });
53
+
54
+ let bytesNotified = 0;
55
+
56
+ internals.updateProgress = throttle(function throttledHandler() {
57
+ const totalBytes = internals.length;
58
+ const bytesTransferred = internals.bytesSeen;
59
+ const progressBytes = bytesTransferred - bytesNotified;
60
+ if (!progressBytes || self.destroyed) return;
61
+
62
+ const rate = _speedometer(progressBytes);
63
+
64
+ bytesNotified = bytesTransferred;
65
+
66
+ process.nextTick(() => {
67
+ self.emit('progress', {
68
+ 'loaded': bytesTransferred,
69
+ 'total': totalBytes,
70
+ 'progress': totalBytes ? (bytesTransferred / totalBytes) : undefined,
71
+ 'bytes': progressBytes,
72
+ 'rate': rate ? rate : undefined,
73
+ 'estimated': rate && totalBytes && bytesTransferred <= totalBytes ?
74
+ (totalBytes - bytesTransferred) / rate : undefined
75
+ });
76
+ });
77
+ }, internals.ticksRate);
78
+
79
+ const onFinish = () => {
80
+ internals.updateProgress(true);
81
+ };
82
+
83
+ this.once('end', onFinish);
84
+ this.once('error', onFinish);
85
+ }
86
+
87
+ _read(size) {
88
+ const internals = this[kInternals];
89
+
90
+ if (internals.onReadCallback) {
91
+ internals.onReadCallback();
92
+ }
93
+
94
+ return super._read(size);
95
+ }
96
+
97
+ _transform(chunk, encoding, callback) {
98
+ const self = this;
99
+ const internals = this[kInternals];
100
+ const maxRate = internals.maxRate;
101
+
102
+ const readableHighWaterMark = this.readableHighWaterMark;
103
+
104
+ const timeWindow = internals.timeWindow;
105
+
106
+ const divider = 1000 / timeWindow;
107
+ const bytesThreshold = (maxRate / divider);
108
+ const minChunkSize = internals.minChunkSize !== false ? Math.max(internals.minChunkSize, bytesThreshold * 0.01) : 0;
109
+
110
+ function pushChunk(_chunk, _callback) {
111
+ const bytes = Buffer.byteLength(_chunk);
112
+ internals.bytesSeen += bytes;
113
+ internals.bytes += bytes;
114
+
115
+ if (internals.isCaptured) {
116
+ internals.updateProgress();
117
+ }
118
+
119
+ if (self.push(_chunk)) {
120
+ process.nextTick(_callback);
121
+ } else {
122
+ internals.onReadCallback = () => {
123
+ internals.onReadCallback = null;
124
+ process.nextTick(_callback);
125
+ };
126
+ }
127
+ }
128
+
129
+ const transformChunk = (_chunk, _callback) => {
130
+ const chunkSize = Buffer.byteLength(_chunk);
131
+ let chunkRemainder = null;
132
+ let maxChunkSize = readableHighWaterMark;
133
+ let bytesLeft;
134
+ let passed = 0;
135
+
136
+ if (maxRate) {
137
+ const now = Date.now();
138
+
139
+ if (!internals.ts || (passed = (now - internals.ts)) >= timeWindow) {
140
+ internals.ts = now;
141
+ bytesLeft = bytesThreshold - internals.bytes;
142
+ internals.bytes = bytesLeft < 0 ? -bytesLeft : 0;
143
+ passed = 0;
144
+ }
145
+
146
+ bytesLeft = bytesThreshold - internals.bytes;
147
+ }
148
+
149
+ if (maxRate) {
150
+ if (bytesLeft <= 0) {
151
+ // next time window
152
+ return setTimeout(() => {
153
+ _callback(null, _chunk);
154
+ }, timeWindow - passed);
155
+ }
156
+
157
+ if (bytesLeft < maxChunkSize) {
158
+ maxChunkSize = bytesLeft;
159
+ }
160
+ }
161
+
162
+ if (maxChunkSize && chunkSize > maxChunkSize && (chunkSize - maxChunkSize) > minChunkSize) {
163
+ chunkRemainder = _chunk.subarray(maxChunkSize);
164
+ _chunk = _chunk.subarray(0, maxChunkSize);
165
+ }
166
+
167
+ pushChunk(_chunk, chunkRemainder ? () => {
168
+ process.nextTick(_callback, null, chunkRemainder);
169
+ } : _callback);
170
+ };
171
+
172
+ transformChunk(chunk, function transformNextChunk(err, _chunk) {
173
+ if (err) {
174
+ return callback(err);
175
+ }
176
+
177
+ if (_chunk) {
178
+ transformChunk(_chunk, transformNextChunk);
179
+ } else {
180
+ callback(null);
181
+ }
182
+ });
183
+ }
184
+
185
+ setLength(length) {
186
+ this[kInternals].length = +length;
187
+ return this;
188
+ }
189
+ }
190
+
191
+ export default AxiosTransformStream;
@@ -0,0 +1,58 @@
1
+ 'use strict';
2
+
3
+ import toFormData from './toFormData.js';
4
+
5
+ /**
6
+ * It encodes a string by replacing all characters that are not in the unreserved set with
7
+ * their percent-encoded equivalents
8
+ *
9
+ * @param {string} str - The string to encode.
10
+ *
11
+ * @returns {string} The encoded string.
12
+ */
13
+ function encode(str) {
14
+ const charMap = {
15
+ '!': '%21',
16
+ "'": '%27',
17
+ '(': '%28',
18
+ ')': '%29',
19
+ '~': '%7E',
20
+ '%20': '+',
21
+ '%00': '\x00'
22
+ };
23
+ return encodeURIComponent(str).replace(/[!'()~]|%20|%00/g, function replacer(match) {
24
+ return charMap[match];
25
+ });
26
+ }
27
+
28
+ /**
29
+ * It takes a params object and converts it to a FormData object
30
+ *
31
+ * @param {Object<string, any>} params - The parameters to be converted to a FormData object.
32
+ * @param {Object<string, any>} options - The options object passed to the Axios constructor.
33
+ *
34
+ * @returns {void}
35
+ */
36
+ function AxiosURLSearchParams(params, options) {
37
+ this._pairs = [];
38
+
39
+ params && toFormData(params, this, options);
40
+ }
41
+
42
+ const prototype = AxiosURLSearchParams.prototype;
43
+
44
+ prototype.append = function append(name, value) {
45
+ this._pairs.push([name, value]);
46
+ };
47
+
48
+ prototype.toString = function toString(encoder) {
49
+ const _encode = encoder ? function(value) {
50
+ return encoder.call(this, value, encode);
51
+ } : encode;
52
+
53
+ return this._pairs.map(function each(pair) {
54
+ return _encode(pair[0]) + '=' + _encode(pair[1]);
55
+ }, '').join('&');
56
+ };
57
+
58
+ export default AxiosURLSearchParams;
@@ -1,11 +1,7 @@
1
1
  'use strict';
2
2
 
3
- module.exports = function bind(fn, thisArg) {
3
+ export default function bind(fn, thisArg) {
4
4
  return function wrap() {
5
- var args = new Array(arguments.length);
6
- for (var i = 0; i < args.length; i++) {
7
- args[i] = arguments[i];
8
- }
9
- return fn.apply(thisArg, args);
5
+ return fn.apply(thisArg, arguments);
10
6
  };
11
- };
7
+ }
@@ -1,7 +1,16 @@
1
1
  'use strict';
2
2
 
3
- var utils = require('./../utils');
3
+ import utils from '../utils.js';
4
+ import AxiosURLSearchParams from '../helpers/AxiosURLSearchParams.js';
4
5
 
6
+ /**
7
+ * It replaces all instances of the characters `:`, `$`, `,`, `+`, `[`, and `]` with their
8
+ * URI encoded counterparts
9
+ *
10
+ * @param {string} val The value to be encoded.
11
+ *
12
+ * @returns {string} The encoded value.
13
+ */
5
14
  function encode(val) {
6
15
  return encodeURIComponent(val).
7
16
  replace(/%3A/gi, ':').
@@ -17,54 +26,38 @@ function encode(val) {
17
26
  *
18
27
  * @param {string} url The base of the url (e.g., http://www.google.com)
19
28
  * @param {object} [params] The params to be appended
29
+ * @param {?object} options
30
+ *
20
31
  * @returns {string} The formatted url
21
32
  */
22
- module.exports = function buildURL(url, params, paramsSerializer) {
33
+ export default function buildURL(url, params, options) {
23
34
  /*eslint no-param-reassign:0*/
24
35
  if (!params) {
25
36
  return url;
26
37
  }
38
+
39
+ const _encode = options && options.encode || encode;
27
40
 
28
- var serializedParams;
29
- if (paramsSerializer) {
30
- serializedParams = paramsSerializer(params);
31
- } else if (utils.isURLSearchParams(params)) {
32
- serializedParams = params.toString();
33
- } else {
34
- var parts = [];
35
-
36
- utils.forEach(params, function serialize(val, key) {
37
- if (val === null || typeof val === 'undefined') {
38
- return;
39
- }
40
-
41
- if (utils.isArray(val)) {
42
- key = key + '[]';
43
- } else {
44
- val = [val];
45
- }
41
+ const serializeFn = options && options.serialize;
46
42
 
47
- utils.forEach(val, function parseValue(v) {
48
- if (utils.isDate(v)) {
49
- v = v.toISOString();
50
- } else if (utils.isObject(v)) {
51
- v = JSON.stringify(v);
52
- }
53
- parts.push(encode(key) + '=' + encode(v));
54
- });
55
- });
43
+ let serializedParams;
56
44
 
57
- serializedParams = parts.join('&');
45
+ if (serializeFn) {
46
+ serializedParams = serializeFn(params, options);
47
+ } else {
48
+ serializedParams = utils.isURLSearchParams(params) ?
49
+ params.toString() :
50
+ new AxiosURLSearchParams(params, options).toString(_encode);
58
51
  }
59
52
 
60
53
  if (serializedParams) {
61
- var hashmarkIndex = url.indexOf('#');
54
+ const hashmarkIndex = url.indexOf("#");
55
+
62
56
  if (hashmarkIndex !== -1) {
63
57
  url = url.slice(0, hashmarkIndex);
64
58
  }
65
-
66
59
  url += (url.indexOf('?') === -1 ? '?' : '&') + serializedParams;
67
60
  }
68
61
 
69
62
  return url;
70
- };
63
+ }
@@ -5,10 +5,11 @@
5
5
  *
6
6
  * @param {string} baseURL The base URL
7
7
  * @param {string} relativeURL The relative URL
8
+ *
8
9
  * @returns {string} The combined URL
9
10
  */
10
- module.exports = function combineURLs(baseURL, relativeURL) {
11
+ export default function combineURLs(baseURL, relativeURL) {
11
12
  return relativeURL
12
13
  ? baseURL.replace(/\/+$/, '') + '/' + relativeURL.replace(/^\/+/, '')
13
14
  : baseURL;
14
- };
15
+ }
@@ -1,53 +1,52 @@
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 support document.cookie
9
- (function standardBrowserEnv() {
10
- return {
11
- write: function write(name, value, expires, path, domain, secure) {
12
- var cookie = [];
13
- cookie.push(name + '=' + encodeURIComponent(value));
8
+ // Standard browser envs support document.cookie
9
+ (function standardBrowserEnv() {
10
+ return {
11
+ write: function write(name, value, expires, path, domain, secure) {
12
+ const cookie = [];
13
+ cookie.push(name + '=' + encodeURIComponent(value));
14
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
- }
15
+ if (utils.isNumber(expires)) {
16
+ cookie.push('expires=' + new Date(expires).toGMTString());
17
+ }
30
18
 
31
- document.cookie = cookie.join('; ');
32
- },
19
+ if (utils.isString(path)) {
20
+ cookie.push('path=' + path);
21
+ }
33
22
 
34
- read: function read(name) {
35
- var match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
36
- return (match ? decodeURIComponent(match[3]) : null);
37
- },
23
+ if (utils.isString(domain)) {
24
+ cookie.push('domain=' + domain);
25
+ }
38
26
 
39
- remove: function remove(name) {
40
- this.write(name, '', Date.now() - 86400000);
27
+ if (secure === true) {
28
+ cookie.push('secure');
41
29
  }
42
- };
43
- })() :
44
-
45
- // Non standard browser env (web workers, react-native) lack needed support.
46
- (function nonStandardBrowserEnv() {
47
- return {
48
- write: function write() {},
49
- read: function read() { return null; },
50
- remove: function remove() {}
51
- };
52
- })()
53
- );
30
+
31
+ document.cookie = cookie.join('; ');
32
+ },
33
+
34
+ read: function read(name) {
35
+ const 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
+ })() :
44
+
45
+ // Non standard browser env (web workers, react-native) lack needed support.
46
+ (function nonStandardBrowserEnv() {
47
+ return {
48
+ write: function write() {},
49
+ read: function read() { return null; },
50
+ remove: function remove() {}
51
+ };
52
+ })();
@@ -9,8 +9,10 @@
9
9
  * @param {string} method The name of the deprecated method
10
10
  * @param {string} [instead] The alternate method to use if applicable
11
11
  * @param {string} [docs] The documentation URL to get further details
12
+ *
13
+ * @returns {void}
12
14
  */
13
- module.exports = function deprecatedMethod(method, instead, docs) {
15
+ export default function deprecatedMethod(method, instead, docs) {
14
16
  try {
15
17
  console.warn(
16
18
  'DEPRECATED method `' + method + '`.' +
@@ -21,4 +23,4 @@ module.exports = function deprecatedMethod(method, instead, docs) {
21
23
  console.warn('For more information about usage see ' + docs);
22
24
  }
23
25
  } catch (e) { /* Ignore */ }
24
- };
26
+ }
@@ -0,0 +1,92 @@
1
+ 'use strict';
2
+
3
+ import utils from '../utils.js';
4
+
5
+ /**
6
+ * It takes a string like `foo[x][y][z]` and returns an array like `['foo', 'x', 'y', 'z']
7
+ *
8
+ * @param {string} name - The name of the property to get.
9
+ *
10
+ * @returns An array of strings.
11
+ */
12
+ function parsePropPath(name) {
13
+ // foo[x][y][z]
14
+ // foo.x.y.z
15
+ // foo-x-y-z
16
+ // foo x y z
17
+ return utils.matchAll(/\w+|\[(\w*)]/g, name).map(match => {
18
+ return match[0] === '[]' ? '' : match[1] || match[0];
19
+ });
20
+ }
21
+
22
+ /**
23
+ * Convert an array to an object.
24
+ *
25
+ * @param {Array<any>} arr - The array to convert to an object.
26
+ *
27
+ * @returns An object with the same keys and values as the array.
28
+ */
29
+ function arrayToObject(arr) {
30
+ const obj = {};
31
+ const keys = Object.keys(arr);
32
+ let i;
33
+ const len = keys.length;
34
+ let key;
35
+ for (i = 0; i < len; i++) {
36
+ key = keys[i];
37
+ obj[key] = arr[key];
38
+ }
39
+ return obj;
40
+ }
41
+
42
+ /**
43
+ * It takes a FormData object and returns a JavaScript object
44
+ *
45
+ * @param {string} formData The FormData object to convert to JSON.
46
+ *
47
+ * @returns {Object<string, any> | null} The converted object.
48
+ */
49
+ function formDataToJSON(formData) {
50
+ function buildPath(path, value, target, index) {
51
+ let name = path[index++];
52
+ const isNumericKey = Number.isFinite(+name);
53
+ const isLast = index >= path.length;
54
+ name = !name && utils.isArray(target) ? target.length : name;
55
+
56
+ if (isLast) {
57
+ if (utils.hasOwnProp(target, name)) {
58
+ target[name] = [target[name], value];
59
+ } else {
60
+ target[name] = value;
61
+ }
62
+
63
+ return !isNumericKey;
64
+ }
65
+
66
+ if (!target[name] || !utils.isObject(target[name])) {
67
+ target[name] = [];
68
+ }
69
+
70
+ const result = buildPath(path, value, target[name], index);
71
+
72
+ if (result && utils.isArray(target[name])) {
73
+ target[name] = arrayToObject(target[name]);
74
+ }
75
+
76
+ return !isNumericKey;
77
+ }
78
+
79
+ if (utils.isFormData(formData) && utils.isFunction(formData.entries)) {
80
+ const obj = {};
81
+
82
+ utils.forEachEntry(formData, (name, value) => {
83
+ buildPath(parsePropPath(name), value, obj, 0);
84
+ });
85
+
86
+ return obj;
87
+ }
88
+
89
+ return null;
90
+ }
91
+
92
+ export default formDataToJSON;
@@ -0,0 +1,53 @@
1
+ 'use strict';
2
+
3
+ import AxiosError from '../core/AxiosError.js';
4
+ import parseProtocol from './parseProtocol.js';
5
+ import platform from '../platform/index.js';
6
+
7
+ const DATA_URL_PATTERN = /^(?:([^;]+);)?(?:[^;]+;)?(base64|),([\s\S]*)$/;
8
+
9
+ /**
10
+ * Parse data uri to a Buffer or Blob
11
+ *
12
+ * @param {String} uri
13
+ * @param {?Boolean} asBlob
14
+ * @param {?Object} options
15
+ * @param {?Function} options.Blob
16
+ *
17
+ * @returns {Buffer|Blob}
18
+ */
19
+ export default function fromDataURI(uri, asBlob, options) {
20
+ const _Blob = options && options.Blob || platform.classes.Blob;
21
+ const protocol = parseProtocol(uri);
22
+
23
+ if (asBlob === undefined && _Blob) {
24
+ asBlob = true;
25
+ }
26
+
27
+ if (protocol === 'data') {
28
+ uri = protocol.length ? uri.slice(protocol.length + 1) : uri;
29
+
30
+ const match = DATA_URL_PATTERN.exec(uri);
31
+
32
+ if (!match) {
33
+ throw new AxiosError('Invalid URL', AxiosError.ERR_INVALID_URL);
34
+ }
35
+
36
+ const mime = match[1];
37
+ const isBase64 = match[2];
38
+ const body = match[3];
39
+ const buffer = Buffer.from(decodeURIComponent(body), isBase64 ? 'base64' : 'utf8');
40
+
41
+ if (asBlob) {
42
+ if (!_Blob) {
43
+ throw new AxiosError('Blob is not supported', AxiosError.ERR_NOT_SUPPORT);
44
+ }
45
+
46
+ return new _Blob([buffer], {type: mime});
47
+ }
48
+
49
+ return buffer;
50
+ }
51
+
52
+ throw new AxiosError('Unsupported protocol ' + protocol, AxiosError.ERR_NOT_SUPPORT);
53
+ }
@@ -4,11 +4,12 @@
4
4
  * Determines whether the specified URL is absolute
5
5
  *
6
6
  * @param {string} url The URL to test
7
+ *
7
8
  * @returns {boolean} True if the specified URL is absolute, otherwise false
8
9
  */
9
- module.exports = function isAbsoluteURL(url) {
10
+ export default function isAbsoluteURL(url) {
10
11
  // A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
11
12
  // RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
12
13
  // by any combination of letters, digits, plus, period, or hyphen.
13
14
  return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url);
14
- };
15
+ }
@@ -1,13 +1,14 @@
1
1
  'use strict';
2
2
 
3
- var utils = require('./../utils');
3
+ import utils from './../utils.js';
4
4
 
5
5
  /**
6
6
  * Determines whether the payload is an error thrown by Axios
7
7
  *
8
8
  * @param {*} payload The value to test
9
+ *
9
10
  * @returns {boolean} True if the payload is an error thrown by Axios, otherwise false
10
11
  */
11
- module.exports = function isAxiosError(payload) {
12
+ export default function isAxiosError(payload) {
12
13
  return utils.isObject(payload) && (payload.isAxiosError === true);
13
- };
14
+ }