axios 1.13.2 → 1.13.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.
package/index.d.cts CHANGED
@@ -100,7 +100,7 @@ declare class AxiosError<T = unknown, D = any> extends Error {
100
100
  isAxiosError: boolean;
101
101
  status?: number;
102
102
  toJSON: () => object;
103
- cause?: unknown;
103
+ cause?: Error;
104
104
  event?: BrowserProgressEvent;
105
105
  static from<T = unknown, D = any>(
106
106
  error: Error | unknown,
@@ -515,14 +515,32 @@ declare namespace axios {
515
515
  runWhen?: (config: InternalAxiosRequestConfig) => boolean;
516
516
  }
517
517
 
518
- type AxiosRequestInterceptorUse<T> = (onFulfilled?: ((value: T) => T | Promise<T>) | null, onRejected?: ((error: any) => any) | null, options?: AxiosInterceptorOptions) => number;
518
+ type AxiosInterceptorFulfilled<T> = (value: T) => T | Promise<T>;
519
+ type AxiosInterceptorRejected = (error: any) => any;
519
520
 
520
- type AxiosResponseInterceptorUse<T> = (onFulfilled?: ((value: T) => T | Promise<T>) | null, onRejected?: ((error: any) => any) | null) => number;
521
+ type AxiosRequestInterceptorUse<T> = (
522
+ onFulfilled?: AxiosInterceptorFulfilled<T> | null,
523
+ onRejected?: AxiosInterceptorRejected | null,
524
+ options?: AxiosInterceptorOptions
525
+ ) => number;
526
+
527
+ type AxiosResponseInterceptorUse<T> = (
528
+ onFulfilled?: AxiosInterceptorFulfilled<T> | null,
529
+ onRejected?: AxiosInterceptorRejected | null
530
+ ) => number;
531
+
532
+ interface AxiosInterceptorHandler<T> {
533
+ fulfilled: AxiosInterceptorFulfilled<T>;
534
+ rejected?: AxiosInterceptorRejected;
535
+ synchronous: boolean;
536
+ runWhen?: (config: AxiosRequestConfig) => boolean;
537
+ }
521
538
 
522
539
  interface AxiosInterceptorManager<V> {
523
540
  use: V extends AxiosResponse ? AxiosResponseInterceptorUse<V> : AxiosRequestInterceptorUse<V>;
524
541
  eject(id: number): void;
525
542
  clear(): void;
543
+ handlers?: Array<AxiosInterceptorHandler<V>>;
526
544
  }
527
545
 
528
546
  interface AxiosInstance extends Axios {
package/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  // TypeScript Version: 4.7
2
+ type StringLiteralsOrString<Literals extends string> = Literals | (string & {});
3
+
2
4
  export type AxiosHeaderValue = AxiosHeaders | string | string[] | number | boolean | null;
3
5
 
4
6
  interface RawAxiosHeaders {
@@ -302,7 +304,7 @@ export interface AxiosProgressEvent {
302
304
 
303
305
  type Milliseconds = number;
304
306
 
305
- type AxiosAdapterName = 'fetch' | 'xhr' | 'http' | (string & {});
307
+ type AxiosAdapterName = StringLiteralsOrString<'xhr' | 'http' | 'fetch'>;
306
308
 
307
309
  type AxiosAdapterConfig = AxiosAdapter | AxiosAdapterName;
308
310
 
@@ -317,7 +319,7 @@ export type LookupAddress = string | LookupAddressEntry;
317
319
 
318
320
  export interface AxiosRequestConfig<D = any> {
319
321
  url?: string;
320
- method?: Method | string;
322
+ method?: StringLiteralsOrString<Method>;
321
323
  baseURL?: string;
322
324
  allowAbsoluteUrls?: boolean;
323
325
  transformRequest?: AxiosRequestTransformer | AxiosRequestTransformer[];
@@ -332,7 +334,7 @@ export interface AxiosRequestConfig<D = any> {
332
334
  adapter?: AxiosAdapterConfig | AxiosAdapterConfig[];
333
335
  auth?: AxiosBasicCredentials;
334
336
  responseType?: ResponseType;
335
- responseEncoding?: responseEncoding | string;
337
+ responseEncoding?: StringLiteralsOrString<responseEncoding>;
336
338
  xsrfCookieName?: string;
337
339
  xsrfHeaderName?: string;
338
340
  onUploadProgress?: (progressEvent: AxiosProgressEvent) => void;
@@ -348,7 +350,7 @@ export interface AxiosRequestConfig<D = any> {
348
350
  httpAgent?: any;
349
351
  httpsAgent?: any;
350
352
  proxy?: AxiosProxyConfig | false;
351
- cancelToken?: CancelToken;
353
+ cancelToken?: CancelToken | undefined;
352
354
  decompress?: boolean;
353
355
  transitional?: TransitionalOptions;
354
356
  signal?: GenericAbortSignal;
@@ -429,7 +431,7 @@ export class AxiosError<T = unknown, D = any> extends Error {
429
431
  isAxiosError: boolean;
430
432
  status?: number;
431
433
  toJSON: () => object;
432
- cause?: unknown;
434
+ cause?: Error;
433
435
  event?: BrowserProgressEvent;
434
436
  static from<T = unknown, D = any>(
435
437
  error: Error | unknown,
@@ -492,14 +494,32 @@ export interface AxiosInterceptorOptions {
492
494
  runWhen?: (config: InternalAxiosRequestConfig) => boolean;
493
495
  }
494
496
 
495
- type AxiosRequestInterceptorUse<T> = (onFulfilled?: ((value: T) => T | Promise<T>) | null, onRejected?: ((error: any) => any) | null, options?: AxiosInterceptorOptions) => number;
497
+ type AxiosInterceptorFulfilled<T> = (value: T) => T | Promise<T>;
498
+ type AxiosInterceptorRejected = (error: any) => any;
499
+
500
+ type AxiosRequestInterceptorUse<T> = (
501
+ onFulfilled?: AxiosInterceptorFulfilled<T> | null,
502
+ onRejected?: AxiosInterceptorRejected | null,
503
+ options?: AxiosInterceptorOptions
504
+ ) => number;
496
505
 
497
- type AxiosResponseInterceptorUse<T> = (onFulfilled?: ((value: T) => T | Promise<T>) | null, onRejected?: ((error: any) => any) | null) => number;
506
+ type AxiosResponseInterceptorUse<T> = (
507
+ onFulfilled?: AxiosInterceptorFulfilled<T> | null,
508
+ onRejected?: AxiosInterceptorRejected | null
509
+ ) => number;
510
+
511
+ interface AxiosInterceptorHandler<T> {
512
+ fulfilled: AxiosInterceptorFulfilled<T>;
513
+ rejected?: AxiosInterceptorRejected;
514
+ synchronous: boolean;
515
+ runWhen: (config: AxiosRequestConfig) => boolean | null;
516
+ }
498
517
 
499
518
  export interface AxiosInterceptorManager<V> {
500
519
  use: V extends AxiosResponse ? AxiosResponseInterceptorUse<V> : AxiosRequestInterceptorUse<V>;
501
520
  eject(id: number): void;
502
521
  clear(): void;
522
+ handlers?: Array<AxiosInterceptorHandler<V>>;
503
523
  }
504
524
 
505
525
  export class Axios {
@@ -5,7 +5,7 @@ The modules under `adapters/` are modules that handle dispatching a request and
5
5
  ## Example
6
6
 
7
7
  ```js
8
- var settle = require('./../core/settle');
8
+ var settle = require('../core/settle');
9
9
 
10
10
  module.exports = function myAdapter(config) {
11
11
  // At this point:
@@ -1,7 +1,7 @@
1
- import utils from './../utils.js';
2
- import settle from './../core/settle.js';
1
+ import utils from '../utils.js';
2
+ import settle from '../core/settle.js';
3
3
  import buildFullPath from '../core/buildFullPath.js';
4
- import buildURL from './../helpers/buildURL.js';
4
+ import buildURL from '../helpers/buildURL.js';
5
5
  import proxyFromEnv from 'proxy-from-env';
6
6
  import http from 'http';
7
7
  import https from 'https';
@@ -193,12 +193,16 @@ function setProxy(options, configProxy, location) {
193
193
 
194
194
  if (proxy.auth) {
195
195
  // Support proxy auth object form
196
- if (proxy.auth.username || proxy.auth.password) {
196
+ const validProxyAuth = Boolean(proxy.auth.username || proxy.auth.password);
197
+
198
+ if (validProxyAuth) {
197
199
  proxy.auth = (proxy.auth.username || '') + ':' + (proxy.auth.password || '');
200
+ } else if (typeof proxy.auth === 'object') {
201
+ throw new AxiosError('Invalid proxy authorization', AxiosError.ERR_BAD_OPTION, { proxy });
198
202
  }
199
- const base64 = Buffer
200
- .from(proxy.auth, 'utf8')
201
- .toString('base64');
203
+
204
+ const base64 = Buffer.from(proxy.auth, 'utf8').toString('base64');
205
+
202
206
  options.headers['Proxy-Authorization'] = 'Basic ' + base64;
203
207
  }
204
208
 
@@ -264,7 +268,8 @@ const buildAddressEntry = (address, family) => resolveFamily(utils.isObject(addr
264
268
 
265
269
  const http2Transport = {
266
270
  request(options, cb) {
267
- const authority = options.protocol + '//' + options.hostname + ':' + (options.port || 80);
271
+ const authority = options.protocol + '//' + options.hostname + ':' + (options.port ||(options.protocol === 'https:' ? 443 : 80));
272
+
268
273
 
269
274
  const {http2Options, headers} = options;
270
275
 
@@ -812,8 +817,6 @@ export default isHttpAdapterSupported && function httpAdapter(config) {
812
817
 
813
818
  // Handle errors
814
819
  req.on('error', function handleRequestError(err) {
815
- // @todo remove
816
- // if (req.aborted && err.code !== AxiosError.ERR_FR_TOO_MANY_REDIRECTS) return;
817
820
  reject(AxiosError.from(err, null, config, req));
818
821
  });
819
822
 
@@ -1,5 +1,5 @@
1
- import utils from './../utils.js';
2
- import settle from './../core/settle.js';
1
+ import utils from '../utils.js';
2
+ import settle from '../core/settle.js';
3
3
  import transitionalDefaults from '../defaults/transitional.js';
4
4
  import AxiosError from '../core/AxiosError.js';
5
5
  import CanceledError from '../cancel/CanceledError.js';
@@ -1,25 +1,22 @@
1
1
  'use strict';
2
2
 
3
3
  import AxiosError from '../core/AxiosError.js';
4
- import utils from '../utils.js';
5
4
 
6
- /**
7
- * A `CanceledError` is an object that is thrown when an operation is canceled.
8
- *
9
- * @param {string=} message The message.
10
- * @param {Object=} config The config.
11
- * @param {Object=} request The request.
12
- *
13
- * @returns {CanceledError} The created error.
14
- */
15
- function CanceledError(message, config, request) {
16
- // eslint-disable-next-line no-eq-null,eqeqeq
17
- AxiosError.call(this, message == null ? 'canceled' : message, AxiosError.ERR_CANCELED, config, request);
18
- this.name = 'CanceledError';
5
+ class CanceledError extends AxiosError {
6
+ /**
7
+ * A `CanceledError` is an object that is thrown when an operation is canceled.
8
+ *
9
+ * @param {string=} message The message.
10
+ * @param {Object=} config The config.
11
+ * @param {Object=} request The request.
12
+ *
13
+ * @returns {CanceledError} The created error.
14
+ */
15
+ constructor(message, config, request) {
16
+ super(message == null ? 'canceled' : message, AxiosError.ERR_CANCELED, config, request);
17
+ this.name = 'CanceledError';
18
+ this.__CANCEL__ = true;
19
+ }
19
20
  }
20
21
 
21
- utils.inherits(CanceledError, AxiosError, {
22
- __CANCEL__: true
23
- });
24
-
25
22
  export default CanceledError;
package/lib/core/Axios.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- import utils from './../utils.js';
3
+ import utils from '../utils.js';
4
4
  import buildURL from '../helpers/buildURL.js';
5
5
  import InterceptorManager from './InterceptorManager.js';
6
6
  import dispatchRequest from './dispatchRequest.js';
@@ -159,8 +159,13 @@ class Axios {
159
159
 
160
160
  promise = Promise.resolve(config);
161
161
 
162
+ let prevResult = config;
162
163
  while (i < len) {
163
- promise = promise.then(chain[i++], chain[i++]);
164
+ promise = promise
165
+ .then(chain[i++])
166
+ .then(result => { prevResult = result !== undefined ? result : prevResult })
167
+ .catch(chain[i++])
168
+ .then(() => prevResult);
164
169
  }
165
170
 
166
171
  return promise;
@@ -191,7 +196,7 @@ class Axios {
191
196
  len = responseInterceptorChain.length;
192
197
 
193
198
  while (i < len) {
194
- promise = promise.then(responseInterceptorChain[i++], responseInterceptorChain[i++]);
199
+ promise = promise.then(responseInterceptorChain[i++]).catch(responseInterceptorChain[i++]);
195
200
  }
196
201
 
197
202
  return promise;
@@ -2,109 +2,72 @@
2
2
 
3
3
  import utils from '../utils.js';
4
4
 
5
- /**
6
- * Create an Error with the specified message, config, error code, request and response.
7
- *
8
- * @param {string} message The error message.
9
- * @param {string} [code] The error code (for example, 'ECONNABORTED').
10
- * @param {Object} [config] The config.
11
- * @param {Object} [request] The request.
12
- * @param {Object} [response] The response.
13
- *
14
- * @returns {Error} The created error.
15
- */
16
- function AxiosError(message, code, config, request, response) {
17
- Error.call(this);
18
-
19
- if (Error.captureStackTrace) {
20
- Error.captureStackTrace(this, this.constructor);
21
- } else {
22
- this.stack = (new Error()).stack;
23
- }
24
-
25
- this.message = message;
26
- this.name = 'AxiosError';
27
- code && (this.code = code);
28
- config && (this.config = config);
29
- request && (this.request = request);
30
- if (response) {
31
- this.response = response;
32
- this.status = response.status ? response.status : null;
33
- }
5
+ class AxiosError extends Error {
6
+ static from(error, code, config, request, response, customProps) {
7
+ const axiosError = new AxiosError(error.message, code || error.code, config, request, response);
8
+ axiosError.cause = error;
9
+ axiosError.name = error.name;
10
+ customProps && Object.assign(axiosError, customProps);
11
+ return axiosError;
12
+ }
13
+
14
+ /**
15
+ * Create an Error with the specified message, config, error code, request and response.
16
+ *
17
+ * @param {string} message The error message.
18
+ * @param {string} [code] The error code (for example, 'ECONNABORTED').
19
+ * @param {Object} [config] The config.
20
+ * @param {Object} [request] The request.
21
+ * @param {Object} [response] The response.
22
+ *
23
+ * @returns {Error} The created error.
24
+ */
25
+ constructor(message, code, config, request, response) {
26
+ super(message);
27
+ this.name = 'AxiosError';
28
+ this.isAxiosError = true;
29
+ code && (this.code = code);
30
+ config && (this.config = config);
31
+ request && (this.request = request);
32
+ if (response) {
33
+ this.response = response;
34
+ this.status = response.status;
35
+ }
36
+ }
37
+
38
+ toJSON() {
39
+ return {
40
+ // Standard
41
+ message: this.message,
42
+ name: this.name,
43
+ // Microsoft
44
+ description: this.description,
45
+ number: this.number,
46
+ // Mozilla
47
+ fileName: this.fileName,
48
+ lineNumber: this.lineNumber,
49
+ columnNumber: this.columnNumber,
50
+ stack: this.stack,
51
+ // Axios
52
+ config: utils.toJSONObject(this.config),
53
+ code: this.code,
54
+ status: this.status,
55
+ };
56
+ }
34
57
  }
35
58
 
36
- utils.inherits(AxiosError, Error, {
37
- toJSON: function toJSON() {
38
- return {
39
- // Standard
40
- message: this.message,
41
- name: this.name,
42
- // Microsoft
43
- description: this.description,
44
- number: this.number,
45
- // Mozilla
46
- fileName: this.fileName,
47
- lineNumber: this.lineNumber,
48
- columnNumber: this.columnNumber,
49
- stack: this.stack,
50
- // Axios
51
- config: utils.toJSONObject(this.config),
52
- code: this.code,
53
- status: this.status
54
- };
55
- }
56
- });
57
-
58
- const prototype = AxiosError.prototype;
59
- const descriptors = {};
60
-
61
- [
62
- 'ERR_BAD_OPTION_VALUE',
63
- 'ERR_BAD_OPTION',
64
- 'ECONNABORTED',
65
- 'ETIMEDOUT',
66
- 'ERR_NETWORK',
67
- 'ERR_FR_TOO_MANY_REDIRECTS',
68
- 'ERR_DEPRECATED',
69
- 'ERR_BAD_RESPONSE',
70
- 'ERR_BAD_REQUEST',
71
- 'ERR_CANCELED',
72
- 'ERR_NOT_SUPPORT',
73
- 'ERR_INVALID_URL'
74
- // eslint-disable-next-line func-names
75
- ].forEach(code => {
76
- descriptors[code] = {value: code};
77
- });
78
-
79
- Object.defineProperties(AxiosError, descriptors);
80
- Object.defineProperty(prototype, 'isAxiosError', {value: true});
81
-
82
- // eslint-disable-next-line func-names
83
- AxiosError.from = (error, code, config, request, response, customProps) => {
84
- const axiosError = Object.create(prototype);
85
-
86
- utils.toFlatObject(error, axiosError, function filter(obj) {
87
- return obj !== Error.prototype;
88
- }, prop => {
89
- return prop !== 'isAxiosError';
90
- });
91
-
92
- const msg = error && error.message ? error.message : 'Error';
93
-
94
- // Prefer explicit code; otherwise copy the low-level error's code (e.g. ECONNREFUSED)
95
- const errCode = code == null && error ? error.code : code;
96
- AxiosError.call(axiosError, msg, errCode, config, request, response);
97
-
98
- // Chain the original error on the standard field; non-enumerable to avoid JSON noise
99
- if (error && axiosError.cause == null) {
100
- Object.defineProperty(axiosError, 'cause', { value: error, configurable: true });
101
- }
102
-
103
- axiosError.name = (error && error.name) || 'Error';
104
-
105
- customProps && Object.assign(axiosError, customProps);
106
-
107
- return axiosError;
108
- };
59
+ // This can be changed to static properties as soon as the parser options in .eslint.cjs are updated.
60
+ AxiosError.ERR_BAD_OPTION_VALUE = 'ERR_BAD_OPTION_VALUE';
61
+ AxiosError.ERR_BAD_OPTION = 'ERR_BAD_OPTION';
62
+ AxiosError.ECONNABORTED = 'ECONNABORTED';
63
+ AxiosError.ETIMEDOUT = 'ETIMEDOUT';
64
+ AxiosError.ERR_NETWORK = 'ERR_NETWORK';
65
+ AxiosError.ERR_FR_TOO_MANY_REDIRECTS = 'ERR_FR_TOO_MANY_REDIRECTS';
66
+ AxiosError.ERR_DEPRECATED = 'ERR_DEPRECATED';
67
+ AxiosError.ERR_BAD_RESPONSE = 'ERR_BAD_RESPONSE';
68
+ AxiosError.ERR_BAD_REQUEST = 'ERR_BAD_REQUEST';
69
+ AxiosError.ERR_CANCELED = 'ERR_CANCELED';
70
+ AxiosError.ERR_NOT_SUPPORT = 'ERR_NOT_SUPPORT';
71
+ AxiosError.ERR_INVALID_URL = 'ERR_INVALID_URL';
109
72
 
110
73
  export default AxiosError;
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- import utils from './../utils.js';
3
+ import utils from '../utils.js';
4
4
 
5
5
  class InterceptorManager {
6
6
  constructor() {
@@ -12,6 +12,7 @@ class InterceptorManager {
12
12
  *
13
13
  * @param {Function} fulfilled The function to handle `then` for a `Promise`
14
14
  * @param {Function} rejected The function to handle `reject` for a `Promise`
15
+ * @param {Object} options The options for the interceptor, synchronous and runWhen
15
16
  *
16
17
  * @return {Number} An ID used to remove interceptor later
17
18
  */
@@ -21,7 +21,7 @@ export default function mergeConfig(config1, config2) {
21
21
 
22
22
  function getMergedValue(target, source, prop, caseless) {
23
23
  if (utils.isPlainObject(target) && utils.isPlainObject(source)) {
24
- return utils.merge.call({caseless}, target, source);
24
+ return utils.merge.call({ caseless }, target, source);
25
25
  } else if (utils.isPlainObject(source)) {
26
26
  return utils.merge({}, source);
27
27
  } else if (utils.isArray(source)) {
@@ -30,7 +30,6 @@ export default function mergeConfig(config1, config2) {
30
30
  return source;
31
31
  }
32
32
 
33
- // eslint-disable-next-line consistent-return
34
33
  function mergeDeepProperties(a, b, prop, caseless) {
35
34
  if (!utils.isUndefined(b)) {
36
35
  return getMergedValue(a, b, prop, caseless);
@@ -96,7 +95,7 @@ export default function mergeConfig(config1, config2) {
96
95
  headers: (a, b, prop) => mergeDeepProperties(headersToObject(a), headersToObject(b), prop, true)
97
96
  };
98
97
 
99
- utils.forEach(Object.keys({...config1, ...config2}), function computeConfigValue(prop) {
98
+ utils.forEach(Object.keys({ ...config1, ...config2 }), function computeConfigValue(prop) {
100
99
  const merge = mergeMap[prop] || mergeDeepProperties;
101
100
  const configValue = merge(config1[prop], config2[prop], prop);
102
101
  (utils.isUndefined(configValue) && merge !== mergeDirectKeys) || (config[prop] = configValue);
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- import utils from './../utils.js';
3
+ import utils from '../utils.js';
4
4
  import defaults from '../defaults/index.js';
5
5
  import AxiosHeaders from '../core/AxiosHeaders.js';
6
6
 
package/lib/env/data.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = "1.13.2";
1
+ export const VERSION = "1.13.3";
@@ -29,29 +29,26 @@ function encode(val) {
29
29
  * @returns {string} The formatted url
30
30
  */
31
31
  export default function buildURL(url, params, options) {
32
- /*eslint no-param-reassign:0*/
33
32
  if (!params) {
34
33
  return url;
35
34
  }
36
-
35
+
37
36
  const _encode = options && options.encode || encode;
38
37
 
39
- if (utils.isFunction(options)) {
40
- options = {
41
- serialize: options
42
- };
43
- }
38
+ const _options = utils.isFunction(options) ? {
39
+ serialize: options
40
+ } : options;
44
41
 
45
- const serializeFn = options && options.serialize;
42
+ const serializeFn = _options && _options.serialize;
46
43
 
47
44
  let serializedParams;
48
45
 
49
46
  if (serializeFn) {
50
- serializedParams = serializeFn(params, options);
47
+ serializedParams = serializeFn(params, _options);
51
48
  } else {
52
49
  serializedParams = utils.isURLSearchParams(params) ?
53
50
  params.toString() :
54
- new AxiosURLSearchParams(params, options).toString(_encode);
51
+ new AxiosURLSearchParams(params, _options).toString(_encode);
55
52
  }
56
53
 
57
54
  if (serializedParams) {
@@ -21,7 +21,7 @@ const composeSignals = (signals, timeout) => {
21
21
 
22
22
  let timer = timeout && setTimeout(() => {
23
23
  timer = null;
24
- onabort(new AxiosError(`timeout ${timeout} of ms exceeded`, AxiosError.ETIMEDOUT))
24
+ onabort(new AxiosError(`timeout of ${timeout}ms exceeded`, AxiosError.ETIMEDOUT))
25
25
  }, timeout)
26
26
 
27
27
  const unsubscribe = () => {
@@ -1,4 +1,4 @@
1
- import utils from './../utils.js';
1
+ import utils from '../utils.js';
2
2
  import platform from '../platform/index.js';
3
3
 
4
4
  export default platform.hasStandardBrowserEnv ?
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- import utils from './../utils.js';
3
+ import utils from '../utils.js';
4
4
 
5
5
  /**
6
6
  * Determines whether the payload is an error thrown by Axios
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- import utils from './../utils.js';
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 +7,7 @@
7
7
  *
8
8
  * ```js
9
9
  * function f(x, y, z) {}
10
- * var args = [1, 2, 3];
10
+ * const args = [1, 2, 3];
11
11
  * f.apply(null, args);
12
12
  * ```
13
13
  *
package/lib/utils.js CHANGED
@@ -252,10 +252,11 @@ const trim = (str) => str.trim ?
252
252
  * If 'obj' is an Object callback will be called passing
253
253
  * the value, key, and complete object for each property.
254
254
  *
255
- * @param {Object|Array} obj The object to iterate
255
+ * @param {Object|Array<unknown>} obj The object to iterate
256
256
  * @param {Function} fn The callback to invoke for each item
257
257
  *
258
- * @param {Boolean} [allOwnKeys = false]
258
+ * @param {Object} [options]
259
+ * @param {Boolean} [options.allOwnKeys = false]
259
260
  * @returns {any}
260
261
  */
261
262
  function forEach(obj, fn, {allOwnKeys = false} = {}) {
@@ -332,7 +333,7 @@ const isContextDefined = (context) => !isUndefined(context) && context !== _glob
332
333
  * Example:
333
334
  *
334
335
  * ```js
335
- * var result = merge({foo: 123}, {foo: 456});
336
+ * const result = merge({foo: 123}, {foo: 456});
336
337
  * console.log(result.foo); // outputs 456
337
338
  * ```
338
339
  *
@@ -369,15 +370,26 @@ function merge(/* obj1, obj2, obj3, ... */) {
369
370
  * @param {Object} b The object to copy properties from
370
371
  * @param {Object} thisArg The object to bind function to
371
372
  *
372
- * @param {Boolean} [allOwnKeys]
373
+ * @param {Object} [options]
374
+ * @param {Boolean} [options.allOwnKeys]
373
375
  * @returns {Object} The resulting value of object a
374
376
  */
375
377
  const extend = (a, b, thisArg, {allOwnKeys}= {}) => {
376
378
  forEach(b, (val, key) => {
377
379
  if (thisArg && isFunction(val)) {
378
- a[key] = bind(val, thisArg);
380
+ Object.defineProperty(a, key, {
381
+ value: bind(val, thisArg),
382
+ writable: true,
383
+ enumerable: true,
384
+ configurable: true
385
+ });
379
386
  } else {
380
- a[key] = val;
387
+ Object.defineProperty(a, key, {
388
+ value: val,
389
+ writable: true,
390
+ enumerable: true,
391
+ configurable: true
392
+ });
381
393
  }
382
394
  }, {allOwnKeys});
383
395
  return a;
@@ -408,7 +420,12 @@ const stripBOM = (content) => {
408
420
  */
409
421
  const inherits = (constructor, superConstructor, props, descriptors) => {
410
422
  constructor.prototype = Object.create(superConstructor.prototype, descriptors);
411
- constructor.prototype.constructor = constructor;
423
+ Object.defineProperty(constructor.prototype, 'constructor', {
424
+ value: constructor,
425
+ writable: true,
426
+ enumerable: false,
427
+ configurable: true
428
+ });
412
429
  Object.defineProperty(constructor, 'super', {
413
430
  value: superConstructor.prototype
414
431
  });