From 767b975545d2d83627799f35e5cafbbe0bc1099a Mon Sep 17 00:00:00 2001 From: Ankit Singh <155445436+singhankit001@users.noreply.github.com> Date: Fri, 24 Apr 2026 23:06:50 +0530 Subject: [PATCH] refactor: modernize utils and xhr adapter using ES6 features (#10588) Co-authored-by: Jay --- lib/adapters/xhr.js | 4 ++-- lib/utils.js | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/adapters/xhr.js b/lib/adapters/xhr.js index 1d2c8375..1d795505 100644 --- a/lib/adapters/xhr.js +++ b/lib/adapters/xhr.js @@ -91,7 +91,7 @@ export default isXHRAdapterSupported && // will return status as 0 even though it's a successful request if ( request.status === 0 && - !(request.responseURL && request.responseURL.indexOf('file:') === 0) + !(request.responseURL && request.responseURL.startsWith('file:')) ) { return; } @@ -205,7 +205,7 @@ export default isXHRAdapterSupported && const protocol = parseProtocol(_config.url); - if (protocol && platform.protocols.indexOf(protocol) === -1) { + if (protocol && !platform.protocols.includes(protocol)) { reject( new AxiosError( 'Unsupported protocol ' + protocol + ':', diff --git a/lib/utils.js b/lib/utils.js index 6bcd6726..77f395e9 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -401,7 +401,7 @@ const isContextDefined = (context) => !isUndefined(context) && context !== _glob * * @returns {Object} Result of all merge properties */ -function merge(/* obj1, obj2, obj3, ... */) { +function merge(...objs) { const { caseless, skipUndefined } = (isContextDefined(this) && this) || {}; const result = {}; const assignValue = (val, key) => { @@ -422,8 +422,8 @@ function merge(/* obj1, obj2, obj3, ... */) { } }; - for (let i = 0, l = arguments.length; i < l; i++) { - arguments[i] && forEach(arguments[i], assignValue); + for (let i = 0, l = objs.length; i < l; i++) { + objs[i] && forEach(objs[i], assignValue); } return result; } @@ -677,7 +677,7 @@ const reduceDescriptors = (obj, reducer) => { const freezeMethods = (obj) => { reduceDescriptors(obj, (descriptor, name) => { // skip restricted props in strict mode - if (isFunction(obj) && ['arguments', 'caller', 'callee'].indexOf(name) !== -1) { + if (isFunction(obj) && ['arguments', 'caller', 'callee'].includes(name)) { return false; }