axios 0.24.0 → 0.26.1

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.
package/lib/core/Axios.js CHANGED
@@ -26,14 +26,14 @@ function Axios(instanceConfig) {
26
26
  *
27
27
  * @param {Object} config The config specific for this request (merged with this.defaults)
28
28
  */
29
- Axios.prototype.request = function request(config) {
29
+ Axios.prototype.request = function request(configOrUrl, config) {
30
30
  /*eslint no-param-reassign:0*/
31
31
  // Allow for axios('example/url'[, config]) a la fetch API
32
- if (typeof config === 'string') {
33
- config = arguments[1] || {};
34
- config.url = arguments[0];
35
- } else {
32
+ if (typeof configOrUrl === 'string') {
36
33
  config = config || {};
34
+ config.url = configOrUrl;
35
+ } else {
36
+ config = configOrUrl || {};
37
37
  }
38
38
 
39
39
  config = mergeConfig(this.defaults, config);
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var utils = require('./../utils');
4
- var defaults = require('./../defaults');
4
+ var defaults = require('../defaults');
5
5
 
6
6
  /**
7
7
  * Transform the data for a request or a response
@@ -1,8 +1,9 @@
1
1
  'use strict';
2
2
 
3
- var utils = require('./utils');
4
- var normalizeHeaderName = require('./helpers/normalizeHeaderName');
5
- var enhanceError = require('./core/enhanceError');
3
+ var utils = require('../utils');
4
+ var normalizeHeaderName = require('../helpers/normalizeHeaderName');
5
+ var enhanceError = require('../core/enhanceError');
6
+ var transitionalDefaults = require('./transitional');
6
7
 
7
8
  var DEFAULT_CONTENT_TYPE = {
8
9
  'Content-Type': 'application/x-www-form-urlencoded'
@@ -18,10 +19,10 @@ function getDefaultAdapter() {
18
19
  var adapter;
19
20
  if (typeof XMLHttpRequest !== 'undefined') {
20
21
  // For browsers use XHR adapter
21
- adapter = require('./adapters/xhr');
22
+ adapter = require('../adapters/xhr');
22
23
  } else if (typeof process !== 'undefined' && Object.prototype.toString.call(process) === '[object process]') {
23
24
  // For node use HTTP adapter
24
- adapter = require('./adapters/http');
25
+ adapter = require('../adapters/http');
25
26
  }
26
27
  return adapter;
27
28
  }
@@ -43,11 +44,7 @@ function stringifySafely(rawValue, parser, encoder) {
43
44
 
44
45
  var defaults = {
45
46
 
46
- transitional: {
47
- silentJSONParsing: true,
48
- forcedJSONParsing: true,
49
- clarifyTimeoutError: false
50
- },
47
+ transitional: transitionalDefaults,
51
48
 
52
49
  adapter: getDefaultAdapter(),
53
50
 
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ module.exports = {
4
+ silentJSONParsing: true,
5
+ forcedJSONParsing: true,
6
+ clarifyTimeoutError: false
7
+ };
package/lib/env/data.js CHANGED
@@ -1,3 +1,3 @@
1
1
  module.exports = {
2
- "version": "0.24.0"
2
+ "version": "0.26.1"
3
3
  };
@@ -10,5 +10,5 @@ module.exports = function isAbsoluteURL(url) {
10
10
  // A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
11
11
  // RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
12
12
  // by any combination of letters, digits, plus, period, or hyphen.
13
- return /^([a-z][a-z\d\+\-\.]*:)?\/\//i.test(url);
13
+ return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url);
14
14
  };
@@ -1,5 +1,7 @@
1
1
  'use strict';
2
2
 
3
+ var utils = require('./../utils');
4
+
3
5
  /**
4
6
  * Determines whether the payload is an error thrown by Axios
5
7
  *
@@ -7,5 +9,5 @@
7
9
  * @returns {boolean} True if the payload is an error thrown by Axios, otherwise false
8
10
  */
9
11
  module.exports = function isAxiosError(payload) {
10
- return (typeof payload === 'object') && (payload.isAxiosError === true);
12
+ return utils.isObject(payload) && (payload.isAxiosError === true);
11
13
  };
@@ -0,0 +1,55 @@
1
+ 'use strict';
2
+
3
+ function combinedKey(parentKey, elKey) {
4
+ return parentKey + '.' + elKey;
5
+ }
6
+
7
+ function buildFormData(formData, data, parentKey) {
8
+ if (Array.isArray(data)) {
9
+ data.forEach(function buildArray(el, i) {
10
+ buildFormData(formData, el, combinedKey(parentKey, i));
11
+ });
12
+ } else if (
13
+ typeof data === 'object' &&
14
+ !(data instanceof File || data === null)
15
+ ) {
16
+ Object.keys(data).forEach(function buildObject(key) {
17
+ buildFormData(
18
+ formData,
19
+ data[key],
20
+ parentKey ? combinedKey(parentKey, key) : key
21
+ );
22
+ });
23
+ } else {
24
+ if (data === undefined) {
25
+ return;
26
+ }
27
+
28
+ var value =
29
+ typeof data === 'boolean' || typeof data === 'number'
30
+ ? data.toString()
31
+ : data;
32
+ formData.append(parentKey, value);
33
+ }
34
+ }
35
+
36
+ /**
37
+ * convert a data object to FormData
38
+ *
39
+ * type FormDataPrimitive = string | Blob | number | boolean
40
+ * interface FormDataNest {
41
+ * [x: string]: FormVal
42
+ * }
43
+ *
44
+ * type FormVal = FormDataNest | FormDataPrimitive
45
+ *
46
+ * @param {FormVal} data
47
+ */
48
+
49
+ module.exports = function getFormData(data) {
50
+ var formData = new FormData();
51
+
52
+ buildFormData(formData, data);
53
+
54
+ return formData;
55
+ };
package/lib/utils.js CHANGED
@@ -13,7 +13,7 @@ var toString = Object.prototype.toString;
13
13
  * @returns {boolean} True if value is an Array, otherwise false
14
14
  */
15
15
  function isArray(val) {
16
- return toString.call(val) === '[object Array]';
16
+ return Array.isArray(val);
17
17
  }
18
18
 
19
19
  /**
@@ -54,7 +54,7 @@ function isArrayBuffer(val) {
54
54
  * @returns {boolean} True if value is an FormData, otherwise false
55
55
  */
56
56
  function isFormData(val) {
57
- return (typeof FormData !== 'undefined') && (val instanceof FormData);
57
+ return toString.call(val) === '[object FormData]';
58
58
  }
59
59
 
60
60
  /**
@@ -68,7 +68,7 @@ function isArrayBufferView(val) {
68
68
  if ((typeof ArrayBuffer !== 'undefined') && (ArrayBuffer.isView)) {
69
69
  result = ArrayBuffer.isView(val);
70
70
  } else {
71
- result = (val) && (val.buffer) && (val.buffer instanceof ArrayBuffer);
71
+ result = (val) && (val.buffer) && (isArrayBuffer(val.buffer));
72
72
  }
73
73
  return result;
74
74
  }
@@ -175,7 +175,7 @@ function isStream(val) {
175
175
  * @returns {boolean} True if value is a URLSearchParams object, otherwise false
176
176
  */
177
177
  function isURLSearchParams(val) {
178
- return typeof URLSearchParams !== 'undefined' && val instanceof URLSearchParams;
178
+ return toString.call(val) === '[object URLSearchParams]';
179
179
  }
180
180
 
181
181
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "axios",
3
- "version": "0.24.0",
3
+ "version": "0.26.1",
4
4
  "description": "Promise based HTTP client for the browser and node.js",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -75,7 +75,7 @@
75
75
  "unpkg": "dist/axios.min.js",
76
76
  "typings": "./index.d.ts",
77
77
  "dependencies": {
78
- "follow-redirects": "^1.14.4"
78
+ "follow-redirects": "^1.14.8"
79
79
  },
80
80
  "bundlesize": [
81
81
  {