...**/!(*.map|*.min.js)Size
Gzip
Dependencies
Publish
Install
Publish
Install
Size
Gzip
Dependencies
@@ -2,7 +2,7 @@ | |||
| 2 | import httpAdapter from './http.js'; | 2 | import httpAdapter from './http.js'; |
| 3 | import xhrAdapter from './xhr.js'; | 3 | import xhrAdapter from './xhr.js'; |
| 4 | import * as fetchAdapter from './fetch.js'; | 4 | import * as fetchAdapter from './fetch.js'; |
| 5 | import AxiosError from "../core/AxiosError.js"; | 5 | import AxiosError from '../core/AxiosError.js'; |
| 6 | 6 | ||
| 7 | /** | 7 | /** |
| 8 | * Known adapters mapping. | 8 | * Known adapters mapping. |
@@ -10,7 +10,7 @@ | |||
| 10 | * - `http` for Node.js | 10 | * - `http` for Node.js |
| 11 | * - `xhr` for browsers | 11 | * - `xhr` for browsers |
| 12 | * - `fetch` for fetch API-based requests | 12 | * - `fetch` for fetch API-based requests |
| 13 | * | 13 | * |
| 14 | * @type {Object<string, Function|Object>} | 14 | * @type {Object<string, Function|Object>} |
| 15 | */ | 15 | */ |
| 16 | const knownAdapters = { | 16 | const knownAdapters = { |
@@ -18,7 +18,7 @@ | |||
| 18 | xhr: xhrAdapter, | 18 | xhr: xhrAdapter, |
| 19 | fetch: { | 19 | fetch: { |
| 20 | get: fetchAdapter.getFetch, | 20 | get: fetchAdapter.getFetch, |
| 21 | } | 21 | }, |
| 22 | }; | 22 | }; |
| 23 | 23 | ||
| 24 | // Assign adapter names for easier debugging and identification | 24 | // Assign adapter names for easier debugging and identification |
@@ -35,7 +35,7 @@ | |||
| 35 | 35 | ||
| 36 | /** | 36 | /** |
| 37 | * Render a rejection reason string for unknown or unsupported adapters | 37 | * Render a rejection reason string for unknown or unsupported adapters |
| 38 | * | 38 | * |
| 39 | * @param {string} reason | 39 | * @param {string} reason |
| 40 | * @returns {string} | 40 | * @returns {string} |
| 41 | */ | 41 | */ |
@@ -43,17 +43,18 @@ | |||
| 43 | 43 | ||
| 44 | /** | 44 | /** |
| 45 | * Check if the adapter is resolved (function, null, or false) | 45 | * Check if the adapter is resolved (function, null, or false) |
| 46 | * | 46 | * |
| 47 | * @param {Function|null|false} adapter | 47 | * @param {Function|null|false} adapter |
| 48 | * @returns {boolean} | 48 | * @returns {boolean} |
| 49 | */ | 49 | */ |
| 50 | const isResolvedHandle = (adapter) => utils.isFunction(adapter) || adapter === null || adapter === false; | 50 | const isResolvedHandle = (adapter) => |
| 51 | utils.isFunction(adapter) || adapter === null || adapter === false; | ||
| 51 | 52 | ||
| 52 | /** | 53 | /** |
| 53 | * Get the first suitable adapter from the provided list. | 54 | * Get the first suitable adapter from the provided list. |
| 54 | * Tries each adapter in order until a supported one is found. | 55 | * Tries each adapter in order until a supported one is found. |
| 55 | * Throws an AxiosError if no adapter is suitable. | 56 | * Throws an AxiosError if no adapter is suitable. |
| 56 | * | 57 | * |
| 57 | * @param {Array<string|Function>|string|Function} adapters - Adapter(s) by name or function. | 58 | * @param {Array<string|Function>|string|Function} adapters - Adapter(s) by name or function. |
| 58 | * @param {Object} config - Axios request configuration | 59 | * @param {Object} config - Axios request configuration |
| 59 | * @throws {AxiosError} If no suitable adapter is available | 60 | * @throws {AxiosError} If no suitable adapter is available |
@@ -90,14 +91,17 @@ | |||
| 90 | } | 91 | } |
| 91 | 92 | ||
| 92 | if (!adapter) { | 93 | if (!adapter) { |
| 93 | const reasons = Object.entries(rejectedReasons) | ||
| 94 | .map(([id, state]) => `adapter ${id} ` + | 94 | const reasons = Object.entries(rejectedReasons).map( |
| 95 | ([id, state]) => | ||
| 96 | `adapter ${id} ` + | ||
| 95 | (state === false ? 'is not supported by the environment' : 'is not available in the build') | 97 | (state === false ? 'is not supported by the environment' : 'is not available in the build') |
| 96 | ); | 98 | ); |
| 97 | 99 | ||
| 98 | let s = length ? | ||
| 99 | (reasons.length > 1 ? 'since :\n' + reasons.map(renderReason).join('\n') : ' ' + renderReason(reasons[0])) : | ||
| 100 | 'as no adapter specified'; | 100 | let s = length |
| 101 | ? reasons.length > 1 | ||
| 102 | ? 'since :\n' + reasons.map(renderReason).join('\n') | ||
| 103 | : ' ' + renderReason(reasons[0]) | ||
| 104 | : 'as no adapter specified'; | ||
| 101 | 105 | ||
| 102 | throw new AxiosError( | 106 | throw new AxiosError( |
| 103 | `There is no suitable adapter to dispatch the request ` + s, | 107 | `There is no suitable adapter to dispatch the request ` + s, |
@@ -122,5 +126,5 @@ | |||
| 122 | * Exposes all known adapters | 126 | * Exposes all known adapters |
| 123 | * @type {Object<string, Function|Object>} | 127 | * @type {Object<string, Function|Object>} |
| 124 | */ | 128 | */ |
| 125 | adapters: knownAdapters | 129 | adapters: knownAdapters, |
| 126 | }; | 130 | }; |
@@ -9,12 +9,12 @@ | |||
| 9 | import CanceledError from './cancel/CanceledError.js'; | 9 | import CanceledError from './cancel/CanceledError.js'; |
| 10 | import CancelToken from './cancel/CancelToken.js'; | 10 | import CancelToken from './cancel/CancelToken.js'; |
| 11 | import isCancel from './cancel/isCancel.js'; | 11 | import isCancel from './cancel/isCancel.js'; |
| 12 | import {VERSION} from './env/data.js'; | 12 | import { VERSION } from './env/data.js'; |
| 13 | import toFormData from './helpers/toFormData.js'; | 13 | import toFormData from './helpers/toFormData.js'; |
| 14 | import AxiosError from './core/AxiosError.js'; | 14 | import AxiosError from './core/AxiosError.js'; |
| 15 | import spread from './helpers/spread.js'; | 15 | import spread from './helpers/spread.js'; |
| 16 | import isAxiosError from './helpers/isAxiosError.js'; | 16 | import isAxiosError from './helpers/isAxiosError.js'; |
| 17 | import AxiosHeaders from "./core/AxiosHeaders.js"; | 17 | import AxiosHeaders from './core/AxiosHeaders.js'; |
| 18 | import adapters from './adapters/adapters.js'; | 18 | import adapters from './adapters/adapters.js'; |
| 19 | import HttpStatusCode from './helpers/HttpStatusCode.js'; | 19 | import HttpStatusCode from './helpers/HttpStatusCode.js'; |
| 20 | 20 | ||
@@ -30,10 +30,10 @@ | |||
| 30 | const instance = bind(Axios.prototype.request, context); | 30 | const instance = bind(Axios.prototype.request, context); |
| 31 | 31 | ||
| 32 | // Copy axios.prototype to instance | 32 | // Copy axios.prototype to instance |
| 33 | utils.extend(instance, Axios.prototype, context, {allOwnKeys: true}); | 33 | utils.extend(instance, Axios.prototype, context, { allOwnKeys: true }); |
| 34 | 34 | ||
| 35 | // Copy context to instance | 35 | // Copy context to instance |
| 36 | utils.extend(instance, context, null, {allOwnKeys: true}); | 36 | utils.extend(instance, context, null, { allOwnKeys: true }); |
| 37 | 37 | ||
| 38 | // Factory for creating new instances | 38 | // Factory for creating new instances |
| 39 | instance.create = function create(instanceConfig) { | 39 | instance.create = function create(instanceConfig) { |
@@ -77,7 +77,7 @@ | |||
| 77 | 77 | ||
| 78 | axios.AxiosHeaders = AxiosHeaders; | 78 | axios.AxiosHeaders = AxiosHeaders; |
| 79 | 79 | ||
| 80 | axios.formToJSON = thing => formDataToJSON(utils.isHTMLForm(thing) ? new FormData(thing) : thing); | 80 | axios.formToJSON = (thing) => formDataToJSON(utils.isHTMLForm(thing) ? new FormData(thing) : thing); |
| 81 | 81 | ||
| 82 | axios.getAdapter = adapters.getAdapter; | 82 | axios.getAdapter = adapters.getAdapter; |
| 83 | 83 | ||
@@ -86,4 +86,4 @@ | |||
| 86 | axios.default = axios; | 86 | axios.default = axios; |
| 87 | 87 | ||
| 88 | // this module should only have a default export | 88 | // this module should only have a default export |
| 89 | export default axios | 89 | export default axios; |
@@ -3,14 +3,20 @@ | |||
| 3 | import utils from '../utils.js'; | 3 | import utils from '../utils.js'; |
| 4 | 4 | ||
| 5 | class AxiosError extends Error { | 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; | 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 | |||
| 11 | // Preserve status from the original error if not already set from response | ||
| 12 | if (error.status != null && axiosError.status == null) { | ||
| 13 | axiosError.status = error.status; | ||
| 12 | } | 14 | } |
| 13 | 15 | ||
| 16 | customProps && Object.assign(axiosError, customProps); | ||
| 17 | return axiosError; | ||
| 18 | } | ||
| 19 | |||
| 14 | /** | 20 | /** |
| 15 | * Create an Error with the specified message, config, error code, request and response. | 21 | * Create an Error with the specified message, config, error code, request and response. |
| 16 | * | 22 | * |
@@ -23,37 +29,48 @@ | |||
| 23 | * @returns {Error} The created error. | 29 | * @returns {Error} The created error. |
| 24 | */ | 30 | */ |
| 25 | constructor(message, code, config, request, response) { | 31 | 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 | } | 32 | super(message); |
| 33 | |||
| 34 | // Make message enumerable to maintain backward compatibility | ||
| 35 | // The native Error constructor sets message as non-enumerable, | ||
| 36 | // but axios < v1.13.3 had it as enumerable | ||
| 37 | Object.defineProperty(this, 'message', { | ||
| 38 | value: message, | ||
| 39 | enumerable: true, | ||
| 40 | writable: true, | ||
| 41 | configurable: true | ||
| 42 | }); | ||
| 43 | |||
| 44 | this.name = 'AxiosError'; | ||
| 45 | this.isAxiosError = true; | ||
| 46 | code && (this.code = code); | ||
| 47 | config && (this.config = config); | ||
| 48 | request && (this.request = request); | ||
| 49 | if (response) { | ||
| 50 | this.response = response; | ||
| 51 | this.status = response.status; | ||
| 52 | } | ||
| 36 | } | 53 | } |
| 37 | 54 | ||
| 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 | } | 55 | toJSON() { |
| 56 | return { | ||
| 57 | // Standard | ||
| 58 | message: this.message, | ||
| 59 | name: this.name, | ||
| 60 | // Microsoft | ||
| 61 | description: this.description, | ||
| 62 | number: this.number, | ||
| 63 | // Mozilla | ||
| 64 | fileName: this.fileName, | ||
| 65 | lineNumber: this.lineNumber, | ||
| 66 | columnNumber: this.columnNumber, | ||
| 67 | stack: this.stack, | ||
| 68 | // Axios | ||
| 69 | config: utils.toJSONObject(this.config), | ||
| 70 | code: this.code, | ||
| 71 | status: this.status, | ||
| 72 | }; | ||
| 73 | } | ||
| 57 | } | 74 | } |
| 58 | 75 | ||
| 59 | // This can be changed to static properties as soon as the parser options in .eslint.cjs are updated. | 76 | // This can be changed to static properties as soon as the parser options in .eslint.cjs are updated. |
@@ -5,24 +5,29 @@ | |||
| 5 | 5 | ||
| 6 | const kInternals = Symbol('internals'); | 6 | const kInternals = Symbol('internals'); |
| 7 | 7 | ||
| 8 | class AxiosTransformStream extends stream.Transform{ | 8 | class AxiosTransformStream extends stream.Transform { |
| 9 | constructor(options) { | 9 | constructor(options) { |
| 10 | options = utils.toFlatObject(options, { | ||
| 11 | maxRate: 0, | ||
| 12 | chunkSize: 64 * 1024, | ||
| 13 | minChunkSize: 100, | ||
| 14 | timeWindow: 500, | ||
| 15 | ticksRate: 2, | ||
| 16 | samplesCount: 15 | ||
| 17 | }, null, (prop, source) => { | ||
| 18 | return !utils.isUndefined(source[prop]); | ||
| 19 | }); | 10 | options = utils.toFlatObject( |
| 11 | options, | ||
| 12 | { | ||
| 13 | maxRate: 0, | ||
| 14 | chunkSize: 64 * 1024, | ||
| 15 | minChunkSize: 100, | ||
| 16 | timeWindow: 500, | ||
| 17 | ticksRate: 2, | ||
| 18 | samplesCount: 15, | ||
| 19 | }, | ||
| 20 | null, | ||
| 21 | (prop, source) => { | ||
| 22 | return !utils.isUndefined(source[prop]); | ||
| 23 | } | ||
| 24 | ); | ||
| 20 | 25 | ||
| 21 | super({ | 26 | super({ |
| 22 | readableHighWaterMark: options.chunkSize | 27 | readableHighWaterMark: options.chunkSize, |
| 23 | }); | 28 | }); |
| 24 | 29 | ||
| 25 | const internals = this[kInternals] = { | 30 | const internals = (this[kInternals] = { |
| 26 | timeWindow: options.timeWindow, | 31 | timeWindow: options.timeWindow, |
| 27 | chunkSize: options.chunkSize, | 32 | chunkSize: options.chunkSize, |
| 28 | maxRate: options.maxRate, | 33 | maxRate: options.maxRate, |
@@ -32,10 +37,10 @@ | |||
| 32 | notifiedBytesLoaded: 0, | 37 | notifiedBytesLoaded: 0, |
| 33 | ts: Date.now(), | 38 | ts: Date.now(), |
| 34 | bytes: 0, | 39 | bytes: 0, |
| 35 | onReadCallback: null | ||
| 36 | }; | 40 | onReadCallback: null, |
| 41 | }); | ||
| 37 | 42 | ||
| 38 | this.on('newListener', event => { | 43 | this.on('newListener', (event) => { |
| 39 | if (event === 'progress') { | 44 | if (event === 'progress') { |
| 40 | if (!internals.isCaptured) { | 45 | if (!internals.isCaptured) { |
| 41 | internals.isCaptured = true; | 46 | internals.isCaptured = true; |
@@ -63,8 +68,11 @@ | |||
| 63 | const timeWindow = internals.timeWindow; | 68 | const timeWindow = internals.timeWindow; |
| 64 | 69 | ||
| 65 | const divider = 1000 / timeWindow; | 70 | const divider = 1000 / timeWindow; |
| 66 | const bytesThreshold = (maxRate / divider); | ||
| 67 | const minChunkSize = internals.minChunkSize !== false ? Math.max(internals.minChunkSize, bytesThreshold * 0.01) : 0; | 71 | const bytesThreshold = maxRate / divider; |
| 72 | const minChunkSize = | ||
| 73 | internals.minChunkSize !== false | ||
| 74 | ? Math.max(internals.minChunkSize, bytesThreshold * 0.01) | ||
| 75 | : 0; | ||
| 68 | 76 | ||
| 69 | const pushChunk = (_chunk, _callback) => { | 77 | const pushChunk = (_chunk, _callback) => { |
| 70 | const bytes = Buffer.byteLength(_chunk); | 78 | const bytes = Buffer.byteLength(_chunk); |
@@ -81,7 +89,7 @@ | |||
| 81 | process.nextTick(_callback); | 89 | process.nextTick(_callback); |
| 82 | }; | 90 | }; |
| 83 | } | 91 | } |
| 84 | } | 92 | }; |
| 85 | 93 | ||
| 86 | const transformChunk = (_chunk, _callback) => { | 94 | const transformChunk = (_chunk, _callback) => { |
| 87 | const chunkSize = Buffer.byteLength(_chunk); | 95 | const chunkSize = Buffer.byteLength(_chunk); |
@@ -93,7 +101,7 @@ | |||
| 93 | if (maxRate) { | 101 | if (maxRate) { |
| 94 | const now = Date.now(); | 102 | const now = Date.now(); |
| 95 | 103 | ||
| 96 | if (!internals.ts || (passed = (now - internals.ts)) >= timeWindow) { | 104 | if (!internals.ts || (passed = now - internals.ts) >= timeWindow) { |
| 97 | internals.ts = now; | 105 | internals.ts = now; |
| 98 | bytesLeft = bytesThreshold - internals.bytes; | 106 | bytesLeft = bytesThreshold - internals.bytes; |
| 99 | internals.bytes = bytesLeft < 0 ? -bytesLeft : 0; | 107 | internals.bytes = bytesLeft < 0 ? -bytesLeft : 0; |
@@ -116,14 +124,19 @@ | |||
| 116 | } | 124 | } |
| 117 | } | 125 | } |
| 118 | 126 | ||
| 119 | if (maxChunkSize && chunkSize > maxChunkSize && (chunkSize - maxChunkSize) > minChunkSize) { | 127 | if (maxChunkSize && chunkSize > maxChunkSize && chunkSize - maxChunkSize > minChunkSize) { |
| 120 | chunkRemainder = _chunk.subarray(maxChunkSize); | 128 | chunkRemainder = _chunk.subarray(maxChunkSize); |
| 121 | _chunk = _chunk.subarray(0, maxChunkSize); | 129 | _chunk = _chunk.subarray(0, maxChunkSize); |
| 122 | } | 130 | } |
| 123 | 131 | ||
| 124 | pushChunk(_chunk, chunkRemainder ? () => { | ||
| 125 | process.nextTick(_callback, null, chunkRemainder); | ||
| 126 | } : _callback); | 132 | pushChunk( |
| 133 | _chunk, | ||
| 134 | chunkRemainder | ||
| 135 | ? () => { | ||
| 136 | process.nextTick(_callback, null, chunkRemainder); | ||
| 137 | } | ||
| 138 | : _callback | ||
| 139 | ); | ||
| 127 | }; | 140 | }; |
| 128 | 141 | ||
| 129 | transformChunk(chunk, function transformNextChunk(err, _chunk) { | 142 | transformChunk(chunk, function transformNextChunk(err, _chunk) { |
@@ -18,7 +18,7 @@ | |||
| 18 | ')': '%29', | 18 | ')': '%29', |
| 19 | '~': '%7E', | 19 | '~': '%7E', |
| 20 | '%20': '+', | 20 | '%20': '+', |
| 21 | '%00': '\x00' | 21 | '%00': '\x00', |
| 22 | }; | 22 | }; |
| 23 | return encodeURIComponent(str).replace(/[!'()~]|%20|%00/g, function replacer(match) { | 23 | return encodeURIComponent(str).replace(/[!'()~]|%20|%00/g, function replacer(match) { |
| 24 | return charMap[match]; | 24 | return charMap[match]; |
@@ -46,13 +46,17 @@ | |||
| 46 | }; | 46 | }; |
| 47 | 47 | ||
| 48 | prototype.toString = function toString(encoder) { | 48 | prototype.toString = function toString(encoder) { |
| 49 | const _encode = encoder ? function(value) { | ||
| 50 | return encoder.call(this, value, encode); | ||
| 51 | } : encode; | 49 | const _encode = encoder |
| 50 | ? function (value) { | ||
| 51 | return encoder.call(this, value, encode); | ||
| 52 | } | ||
| 53 | : encode; | ||
| 52 | 54 | ||
| 53 | return this._pairs.map(function each(pair) { | ||
| 54 | return _encode(pair[0]) + '=' + _encode(pair[1]); | ||
| 55 | }, '').join('&'); | 55 | return this._pairs |
| 56 | .map(function each(pair) { | ||
| 57 | return _encode(pair[0]) + '=' + _encode(pair[1]); | ||
| 58 | }, '') | ||
| 59 | .join('&'); | ||
| 56 | }; | 60 | }; |
| 57 | 61 | ||
| 58 | export default AxiosURLSearchParams; | 62 | export default AxiosURLSearchParams; |
@@ -12,11 +12,11 @@ | |||
| 12 | * @returns {string} The encoded value. | 12 | * @returns {string} The encoded value. |
| 13 | */ | 13 | */ |
| 14 | function encode(val) { | 14 | function encode(val) { |
| 15 | return encodeURIComponent(val). | ||
| 16 | replace(/%3A/gi, ':'). | ||
| 17 | replace(/%24/g, '$'). | ||
| 18 | replace(/%2C/gi, ','). | ||
| 19 | replace(/%20/g, '+'); | 15 | return encodeURIComponent(val) |
| 16 | .replace(/%3A/gi, ':') | ||
| 17 | .replace(/%24/g, '$') | ||
| 18 | .replace(/%2C/gi, ',') | ||
| 19 | .replace(/%20/g, '+'); | ||
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | /** | 22 | /** |
@@ -33,11 +33,13 @@ | |||
| 33 | return url; | 33 | return url; |
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | const _encode = options && options.encode || encode; | 36 | const _encode = (options && options.encode) || encode; |
| 37 | 37 | ||
| 38 | const _options = utils.isFunction(options) ? { | ||
| 39 | serialize: options | ||
| 40 | } : options; | 38 | const _options = utils.isFunction(options) |
| 39 | ? { | ||
| 40 | serialize: options, | ||
| 41 | } | ||
| 42 | : options; | ||
| 41 | 43 | ||
| 42 | const serializeFn = _options && _options.serialize; | 44 | const serializeFn = _options && _options.serialize; |
| 43 | 45 | ||
@@ -46,13 +48,13 @@ | |||
| 46 | if (serializeFn) { | 48 | if (serializeFn) { |
| 47 | serializedParams = serializeFn(params, _options); | 49 | serializedParams = serializeFn(params, _options); |
| 48 | } else { | 50 | } else { |
| 49 | serializedParams = utils.isURLSearchParams(params) ? | ||
| 50 | params.toString() : | ||
| 51 | new AxiosURLSearchParams(params, _options).toString(_encode); | 51 | serializedParams = utils.isURLSearchParams(params) |
| 52 | ? params.toString() | ||
| 53 | : new AxiosURLSearchParams(params, _options).toString(_encode); | ||
| 52 | } | 54 | } |
| 53 | 55 | ||
| 54 | if (serializedParams) { | 56 | if (serializedParams) { |
| 55 | const hashmarkIndex = url.indexOf("#"); | 57 | const hashmarkIndex = url.indexOf('#'); |
| 56 | 58 | ||
| 57 | if (hashmarkIndex !== -1) { | 59 | if (hashmarkIndex !== -1) { |
| 58 | url = url.slice(0, hashmarkIndex); | 60 | url = url.slice(0, hashmarkIndex); |
@@ -1,16 +1,18 @@ | |||
| 1 | import utils from "../utils.js"; | 1 | import utils from '../utils.js'; |
| 2 | 2 | ||
| 3 | const callbackify = (fn, reducer) => { | 3 | const callbackify = (fn, reducer) => { |
| 4 | return utils.isAsyncFn(fn) ? function (...args) { | ||
| 5 | const cb = args.pop(); | ||
| 6 | fn.apply(this, args).then((value) => { | ||
| 7 | try { | ||
| 8 | reducer ? cb(null, ...reducer(value)) : cb(null, value); | ||
| 9 | } catch (err) { | ||
| 10 | cb(err); | 4 | return utils.isAsyncFn(fn) |
| 5 | ? function (...args) { | ||
| 6 | const cb = args.pop(); | ||
| 7 | fn.apply(this, args).then((value) => { | ||
| 8 | try { | ||
| 9 | reducer ? cb(null, ...reducer(value)) : cb(null, value); | ||
| 10 | } catch (err) { | ||
| 11 | cb(err); | ||
| 12 | } | ||
| 13 | }, cb); | ||
| 11 | } | 14 | } |
| 12 | }, cb); | ||
| 13 | } : fn; | ||
| 14 | } | 15 | : fn; |
| 16 | }; | ||
| 15 | 17 | ||
| 16 | export default callbackify; | 18 | export default callbackify; |
@@ -24,7 +24,7 @@ | |||
| 24 | const token = this; | 24 | const token = this; |
| 25 | 25 | ||
| 26 | // eslint-disable-next-line func-names | 26 | // eslint-disable-next-line func-names |
| 27 | this.promise.then(cancel => { | 27 | this.promise.then((cancel) => { |
| 28 | if (!token._listeners) return; | 28 | if (!token._listeners) return; |
| 29 | 29 | ||
| 30 | let i = token._listeners.length; | 30 | let i = token._listeners.length; |
@@ -36,10 +36,10 @@ | |||
| 36 | }); | 36 | }); |
| 37 | 37 | ||
| 38 | // eslint-disable-next-line func-names | 38 | // eslint-disable-next-line func-names |
| 39 | this.promise.then = onfulfilled => { | 39 | this.promise.then = (onfulfilled) => { |
| 40 | let _resolve; | 40 | let _resolve; |
| 41 | // eslint-disable-next-line func-names | 41 | // eslint-disable-next-line func-names |
| 42 | const promise = new Promise(resolve => { | 42 | const promise = new Promise((resolve) => { |
| 43 | token.subscribe(resolve); | 43 | token.subscribe(resolve); |
| 44 | _resolve = resolve; | 44 | _resolve = resolve; |
| 45 | }).then(onfulfilled); | 45 | }).then(onfulfilled); |
@@ -127,7 +127,7 @@ | |||
| 127 | }); | 127 | }); |
| 128 | return { | 128 | return { |
| 129 | token, | 129 | token, |
| 130 | cancel | 130 | cancel, |
| 131 | }; | 131 | }; |
| 132 | } | 132 | } |
| 133 | } | 133 | } |
@@ -1,9 +1,9 @@ | |||
| 1 | import CanceledError from "../cancel/CanceledError.js"; | ||
| 2 | import AxiosError from "../core/AxiosError.js"; | 1 | import CanceledError from '../cancel/CanceledError.js'; |
| 2 | import AxiosError from '../core/AxiosError.js'; | ||
| 3 | import utils from '../utils.js'; | 3 | import utils from '../utils.js'; |
| 4 | 4 | ||
| 5 | const composeSignals = (signals, timeout) => { | 5 | const composeSignals = (signals, timeout) => { |
| 6 | const {length} = (signals = signals ? signals.filter(Boolean) : []); | 6 | const { length } = (signals = signals ? signals.filter(Boolean) : []); |
| 7 | 7 | ||
| 8 | if (timeout || length) { | 8 | if (timeout || length) { |
| 9 | let controller = new AbortController(); | 9 | let controller = new AbortController(); |
@@ -15,34 +15,42 @@ | |||
| 15 | aborted = true; | 15 | aborted = true; |
| 16 | unsubscribe(); | 16 | unsubscribe(); |
| 17 | const err = reason instanceof Error ? reason : this.reason; | 17 | const err = reason instanceof Error ? reason : this.reason; |
| 18 | controller.abort(err instanceof AxiosError ? err : new CanceledError(err instanceof Error ? err.message : err)); | 18 | controller.abort( |
| 19 | err instanceof AxiosError | ||
| 20 | ? err | ||
| 21 | : new CanceledError(err instanceof Error ? err.message : err) | ||
| 22 | ); | ||
| 19 | } | 23 | } |
| 20 | } | 24 | }; |
| 21 | 25 | ||
| 22 | let timer = timeout && setTimeout(() => { | ||
| 23 | timer = null; | ||
| 24 | onabort(new AxiosError(`timeout of ${timeout}ms exceeded`, AxiosError.ETIMEDOUT)) | ||
| 25 | }, timeout) | 26 | let timer = |
| 27 | timeout && | ||
| 28 | setTimeout(() => { | ||
| 29 | timer = null; | ||
| 30 | onabort(new AxiosError(`timeout of ${timeout}ms exceeded`, AxiosError.ETIMEDOUT)); | ||
| 31 | }, timeout); | ||
| 26 | 32 | ||
| 27 | const unsubscribe = () => { | 33 | const unsubscribe = () => { |
| 28 | if (signals) { | 34 | if (signals) { |
| 29 | timer && clearTimeout(timer); | 35 | timer && clearTimeout(timer); |
| 30 | timer = null; | 36 | timer = null; |
| 31 | signals.forEach(signal => { | ||
| 32 | signal.unsubscribe ? signal.unsubscribe(onabort) : signal.removeEventListener('abort', onabort); | 37 | signals.forEach((signal) => { |
| 38 | signal.unsubscribe | ||
| 39 | ? signal.unsubscribe(onabort) | ||
| 40 | : signal.removeEventListener('abort', onabort); | ||
| 33 | }); | 41 | }); |
| 34 | signals = null; | 42 | signals = null; |
| 35 | } | 43 | } |
| 36 | } | 44 | }; |
| 37 | 45 | ||
| 38 | signals.forEach((signal) => signal.addEventListener('abort', onabort)); | 46 | signals.forEach((signal) => signal.addEventListener('abort', onabort)); |
| 39 | 47 | ||
| 40 | const {signal} = controller; | 48 | const { signal } = controller; |
| 41 | 49 | ||
| 42 | signal.unsubscribe = () => utils.asap(unsubscribe); | 50 | signal.unsubscribe = () => utils.asap(unsubscribe); |
| 43 | 51 | ||
| 44 | return signal; | 52 | return signal; |
| 45 | } | 53 | } |
| 46 | } | 54 | }; |
| 47 | 55 | ||
| 48 | export default composeSignals; | 56 | export default composeSignals; |
@@ -1,53 +1,48 @@ | |||
| 1 | import utils from '../utils.js'; | 1 | import utils from '../utils.js'; |
| 2 | import platform from '../platform/index.js'; | 2 | import platform from '../platform/index.js'; |
| 3 | 3 | ||
| 4 | export default platform.hasStandardBrowserEnv ? | 4 | export default platform.hasStandardBrowserEnv |
| 5 | ? // Standard browser envs support document.cookie | ||
| 6 | { | ||
| 7 | write(name, value, expires, path, domain, secure, sameSite) { | ||
| 8 | if (typeof document === 'undefined') return; | ||
| 5 | 9 | ||
| 6 | // Standard browser envs support document.cookie | ||
| 7 | { | ||
| 8 | write(name, value, expires, path, domain, secure, sameSite) { | ||
| 9 | if (typeof document === 'undefined') return; | 10 | const cookie = [`${name}=${encodeURIComponent(value)}`]; |
| 10 | 11 | ||
| 11 | const cookie = [`${name}=${encodeURIComponent(value)}`]; | 12 | if (utils.isNumber(expires)) { |
| 13 | cookie.push(`expires=${new Date(expires).toUTCString()}`); | ||
| 14 | } | ||
| 15 | if (utils.isString(path)) { | ||
| 16 | cookie.push(`path=${path}`); | ||
| 17 | } | ||
| 18 | if (utils.isString(domain)) { | ||
| 19 | cookie.push(`domain=${domain}`); | ||
| 20 | } | ||
| 21 | if (secure === true) { | ||
| 22 | cookie.push('secure'); | ||
| 23 | } | ||
| 24 | if (utils.isString(sameSite)) { | ||
| 25 | cookie.push(`SameSite=${sameSite}`); | ||
| 26 | } | ||
| 12 | 27 | ||
| 13 | if (utils.isNumber(expires)) { | ||
| 14 | cookie.push(`expires=${new Date(expires).toUTCString()}`); | ||
| 15 | } | ||
| 16 | if (utils.isString(path)) { | ||
| 17 | cookie.push(`path=${path}`); | ||
| 18 | } | ||
| 19 | if (utils.isString(domain)) { | ||
| 20 | cookie.push(`domain=${domain}`); | ||
| 21 | } | ||
| 22 | if (secure === true) { | ||
| 23 | cookie.push('secure'); | ||
| 24 | } | ||
| 25 | if (utils.isString(sameSite)) { | ||
| 26 | cookie.push(`SameSite=${sameSite}`); | ||
| 27 | } | 28 | document.cookie = cookie.join('; '); |
| 29 | }, | ||
| 28 | 30 | ||
| 29 | document.cookie = cookie.join('; '); | ||
| 30 | }, | 31 | read(name) { |
| 32 | if (typeof document === 'undefined') return null; | ||
| 33 | const match = document.cookie.match(new RegExp('(?:^|; )' + name + '=([^;]*)')); | ||
| 34 | return match ? decodeURIComponent(match[1]) : null; | ||
| 35 | }, | ||
| 31 | 36 | ||
| 32 | read(name) { | ||
| 33 | if (typeof document === 'undefined') return null; | ||
| 34 | const match = document.cookie.match(new RegExp('(?:^|; )' + name + '=([^;]*)')); | ||
| 35 | return match ? decodeURIComponent(match[1]) : null; | ||
| 36 | }, | ||
| 37 | |||
| 38 | remove(name) { | ||
| 39 | this.write(name, '', Date.now() - 86400000, '/'); | 37 | remove(name) { |
| 38 | this.write(name, '', Date.now() - 86400000, '/'); | ||
| 39 | }, | ||
| 40 | } | 40 | } |
| 41 | } | ||
| 42 | |||
| 43 | : | ||
| 44 | |||
| 45 | // Non-standard browser env (web workers, react-native) lack needed support. | ||
| 46 | { | ||
| 47 | write() {}, | ||
| 48 | read() { | ||
| 49 | return null; | ||
| 50 | }, | ||
| 51 | remove() {} | ||
| 52 | }; | ||
| 53 | 41 | : // Non-standard browser env (web workers, react-native) lack needed support. | |
| 42 | { | ||
| 43 | write() {}, | ||
| 44 | read() { | ||
| 45 | return null; | ||
| 46 | }, | ||
| 47 | remove() {}, | ||
| 48 | }; | ||
@@ -15,12 +15,17 @@ | |||
| 15 | export default function deprecatedMethod(method, instead, docs) { | 15 | export default function deprecatedMethod(method, instead, docs) { |
| 16 | try { | 16 | try { |
| 17 | console.warn( | 17 | console.warn( |
| 18 | 'DEPRECATED method `' + method + '`.' + | ||
| 19 | (instead ? ' Use `' + instead + '` instead.' : '') + | ||
| 20 | ' This method will be removed in a future release.'); | 18 | 'DEPRECATED method `' + |
| 19 | method + | ||
| 20 | '`.' + | ||
| 21 | (instead ? ' Use `' + instead + '` instead.' : '') + | ||
| 22 | ' This method will be removed in a future release.' | ||
| 23 | ); | ||
| 21 | 24 | ||
| 22 | if (docs) { | 25 | if (docs) { |
| 23 | console.warn('For more information about usage see ' + docs); | 26 | console.warn('For more information about usage see ' + docs); |
| 24 | } | 27 | } |
| 25 | } catch (e) { /* Ignore */ } | 28 | } catch (e) { |
| 29 | /* Ignore */ | ||
| 30 | } | ||
| 26 | } | 31 | } |
@@ -5,7 +5,7 @@ | |||
| 5 | import defaults from '../defaults/index.js'; | 5 | import defaults from '../defaults/index.js'; |
| 6 | import CanceledError from '../cancel/CanceledError.js'; | 6 | import CanceledError from '../cancel/CanceledError.js'; |
| 7 | import AxiosHeaders from '../core/AxiosHeaders.js'; | 7 | import AxiosHeaders from '../core/AxiosHeaders.js'; |
| 8 | import adapters from "../adapters/adapters.js"; | 8 | import adapters from '../adapters/adapters.js'; |
| 9 | 9 | ||
| 10 | /** | 10 | /** |
| 11 | * Throws a `CanceledError` if cancellation has been requested. | 11 | * Throws a `CanceledError` if cancellation has been requested. |
@@ -37,10 +37,7 @@ | |||
| 37 | config.headers = AxiosHeaders.from(config.headers); | 37 | config.headers = AxiosHeaders.from(config.headers); |
| 38 | 38 | ||
| 39 | // Transform request data | 39 | // Transform request data |
| 40 | config.data = transformData.call( | ||
| 41 | config, | ||
| 42 | config.transformRequest | ||
| 43 | ); | 40 | config.data = transformData.call(config, config.transformRequest); |
| 44 | 41 | ||
| 45 | if (['post', 'put', 'patch'].indexOf(config.method) !== -1) { | 42 | if (['post', 'put', 'patch'].indexOf(config.method) !== -1) { |
| 46 | config.headers.setContentType('application/x-www-form-urlencoded', false); | 43 | config.headers.setContentType('application/x-www-form-urlencoded', false); |
@@ -48,34 +45,33 @@ | |||
| 48 | 45 | ||
| 49 | const adapter = adapters.getAdapter(config.adapter || defaults.adapter, config); | 46 | const adapter = adapters.getAdapter(config.adapter || defaults.adapter, config); |
| 50 | 47 | ||
| 51 | return adapter(config).then(function onAdapterResolution(response) { | ||
| 52 | throwIfCancellationRequested(config); | 48 | return adapter(config).then( |
| 49 | function onAdapterResolution(response) { | ||
| 50 | throwIfCancellationRequested(config); | ||
| 53 | 51 | ||
| 54 | // Transform response data | ||
| 55 | response.data = transformData.call( | ||
| 56 | config, | ||
| 57 | config.transformResponse, | ||
| 58 | response | ||
| 59 | ); | 52 | // Transform response data |
| 53 | response.data = transformData.call(config, config.transformResponse, response); | ||
| 60 | 54 | ||
| 61 | response.headers = AxiosHeaders.from(response.headers); | 55 | response.headers = AxiosHeaders.from(response.headers); |
| 62 | 56 | ||
| 63 | return response; | ||
| 64 | }, function onAdapterRejection(reason) { | ||
| 65 | if (!isCancel(reason)) { | ||
| 66 | throwIfCancellationRequested(config); | 57 | return response; |
| 58 | }, | ||
| 59 | function onAdapterRejection(reason) { | ||
| 60 | if (!isCancel(reason)) { | ||
| 61 | throwIfCancellationRequested(config); | ||
| 67 | 62 | ||
| 68 | // Transform response data | ||
| 69 | if (reason && reason.response) { | ||
| 70 | reason.response.data = transformData.call( | ||
| 71 | config, | ||
| 72 | config.transformResponse, | ||
| 73 | reason.response | ||
| 74 | ); | ||
| 75 | reason.response.headers = AxiosHeaders.from(reason.response.headers); | 63 | // Transform response data |
| 64 | if (reason && reason.response) { | ||
| 65 | reason.response.data = transformData.call( | ||
| 66 | config, | ||
| 67 | config.transformResponse, | ||
| 68 | reason.response | ||
| 69 | ); | ||
| 70 | reason.response.headers = AxiosHeaders.from(reason.response.headers); | ||
| 71 | } | ||
| 76 | } | 72 | } |
| 73 | |||
| 74 | return Promise.reject(reason); | ||
| 77 | } | 75 | } |
| 78 | |||
| 79 | return Promise.reject(reason); | ||
| 80 | }); | 76 | ); |
| 81 | } | 77 | } |
@@ -14,7 +14,7 @@ | |||
| 14 | // foo.x.y.z | 14 | // foo.x.y.z |
| 15 | // foo-x-y-z | 15 | // foo-x-y-z |
| 16 | // foo x y z | 16 | // foo x y z |
| 17 | return utils.matchAll(/\w+|\[(\w*)]/g, name).map(match => { | 17 | return utils.matchAll(/\w+|\[(\w*)]/g, name).map((match) => { |
| 18 | return match[0] === '[]' ? '' : match[1] || match[0]; | 18 | return match[0] === '[]' ? '' : match[1] || match[0]; |
| 19 | }); | 19 | }); |
| 20 | } | 20 | } |
@@ -1,8 +1,8 @@ | |||
| 1 | import util from 'util'; | 1 | import util from 'util'; |
| 2 | import {Readable} from 'stream'; | ||
| 3 | import utils from "../utils.js"; | ||
| 4 | import readBlob from "./readBlob.js"; | ||
| 5 | import platform from "../platform/index.js"; | 2 | import { Readable } from 'stream'; |
| 3 | import utils from '../utils.js'; | ||
| 4 | import readBlob from './readBlob.js'; | ||
| 5 | import platform from '../platform/index.js'; | ||
| 6 | 6 | ||
| 7 | const BOUNDARY_ALPHABET = platform.ALPHABET.ALPHA_DIGIT + '-_'; | 7 | const BOUNDARY_ALPHABET = platform.ALPHABET.ALPHA_DIGIT + '-_'; |
| 8 | 8 | ||
@@ -14,7 +14,7 @@ | |||
| 14 | 14 | ||
| 15 | class FormDataPart { | 15 | class FormDataPart { |
| 16 | constructor(name, value) { | 16 | constructor(name, value) { |
| 17 | const {escapeName} = this.constructor; | 17 | const { escapeName } = this.constructor; |
| 18 | const isStringValue = utils.isString(value); | 18 | const isStringValue = utils.isString(value); |
| 19 | 19 | ||
| 20 | let headers = `Content-Disposition: form-data; name="${escapeName(name)}"${ | 20 | let headers = `Content-Disposition: form-data; name="${escapeName(name)}"${ |
@@ -24,7 +24,7 @@ | |||
| 24 | if (isStringValue) { | 24 | if (isStringValue) { |
| 25 | value = textEncoder.encode(String(value).replace(/\r?\n|\r\n?/g, CRLF)); | 25 | value = textEncoder.encode(String(value).replace(/\r?\n|\r\n?/g, CRLF)); |
| 26 | } else { | 26 | } else { |
| 27 | headers += `Content-Type: ${value.type || "application/octet-stream"}${CRLF}` | 27 | headers += `Content-Type: ${value.type || 'application/octet-stream'}${CRLF}`; |
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | this.headers = textEncoder.encode(headers + CRLF); | 30 | this.headers = textEncoder.encode(headers + CRLF); |
@@ -37,12 +37,12 @@ | |||
| 37 | this.value = value; | 37 | this.value = value; |
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | async *encode(){ | 40 | async *encode() { |
| 41 | yield this.headers; | 41 | yield this.headers; |
| 42 | 42 | ||
| 43 | const {value} = this; | 43 | const { value } = this; |
| 44 | 44 | ||
| 45 | if(utils.isTypedArray(value)) { | 45 | if (utils.isTypedArray(value)) { |
| 46 | yield value; | 46 | yield value; |
| 47 | } else { | 47 | } else { |
| 48 | yield* readBlob(value); | 48 | yield* readBlob(value); |
@@ -52,11 +52,15 @@ | |||
| 52 | } | 52 | } |
| 53 | 53 | ||
| 54 | static escapeName(name) { | 54 | static escapeName(name) { |
| 55 | return String(name).replace(/[\r\n"]/g, (match) => ({ | ||
| 56 | '\r' : '%0D', | ||
| 57 | '\n' : '%0A', | ||
| 58 | '"' : '%22', | ||
| 59 | }[match])); | 55 | return String(name).replace( |
| 56 | /[\r\n"]/g, | ||
| 57 | (match) => | ||
| 58 | ({ | ||
| 59 | '\r': '%0D', | ||
| 60 | '\n': '%0A', | ||
| 61 | '"': '%22', | ||
| 62 | })[match] | ||
| 63 | ); | ||
| 60 | } | 64 | } |
| 61 | } | 65 | } |
| 62 | 66 | ||
@@ -64,15 +68,15 @@ | |||
| 64 | const { | 68 | const { |
| 65 | tag = 'form-data-boundary', | 69 | tag = 'form-data-boundary', |
| 66 | size = 25, | 70 | size = 25, |
| 67 | boundary = tag + '-' + platform.generateString(size, BOUNDARY_ALPHABET) | 71 | boundary = tag + '-' + platform.generateString(size, BOUNDARY_ALPHABET), |
| 68 | } = options || {}; | 72 | } = options || {}; |
| 69 | 73 | ||
| 70 | if(!utils.isFormData(form)) { | 74 | if (!utils.isFormData(form)) { |
| 71 | throw TypeError('FormData instance required'); | 75 | throw TypeError('FormData instance required'); |
| 72 | } | 76 | } |
| 73 | 77 | ||
| 74 | if (boundary.length < 1 || boundary.length > 70) { | 78 | if (boundary.length < 1 || boundary.length > 70) { |
| 75 | throw Error('boundary must be 10-70 characters long') | 79 | throw Error('boundary must be 10-70 characters long'); |
| 76 | } | 80 | } |
| 77 | 81 | ||
| 78 | const boundaryBytes = textEncoder.encode('--' + boundary + CRLF); | 82 | const boundaryBytes = textEncoder.encode('--' + boundary + CRLF); |
@@ -90,8 +94,8 @@ | |||
| 90 | contentLength = utils.toFiniteNumber(contentLength); | 94 | contentLength = utils.toFiniteNumber(contentLength); |
| 91 | 95 | ||
| 92 | const computedHeaders = { | 96 | const computedHeaders = { |
| 93 | 'Content-Type': `multipart/form-data; boundary=${boundary}` | ||
| 94 | } | 97 | 'Content-Type': `multipart/form-data; boundary=${boundary}`, |
| 98 | }; | ||
| 95 | 99 | ||
| 96 | if (Number.isFinite(contentLength)) { | 100 | if (Number.isFinite(contentLength)) { |
| 97 | computedHeaders['Content-Length'] = contentLength; | 101 | computedHeaders['Content-Length'] = contentLength; |
@@ -99,14 +103,16 @@ | |||
| 99 | 103 | ||
| 100 | headersHandler && headersHandler(computedHeaders); | 104 | headersHandler && headersHandler(computedHeaders); |
| 101 | 105 | ||
| 102 | return Readable.from((async function *() { | ||
| 103 | for(const part of parts) { | ||
| 104 | yield boundaryBytes; | ||
| 105 | yield* part.encode(); | ||
| 106 | } | 106 | return Readable.from( |
| 107 | (async function* () { | ||
| 108 | for (const part of parts) { | ||
| 109 | yield boundaryBytes; | ||
| 110 | yield* part.encode(); | ||
| 111 | } | ||
| 107 | 112 | ||
| 108 | yield footerBytes; | ||
| 109 | })()); | 113 | yield footerBytes; |
| 114 | })() | ||
| 115 | ); | ||
| 110 | }; | 116 | }; |
| 111 | 117 | ||
| 112 | export default formDataToStream; | 118 | export default formDataToStream; |
@@ -17,7 +17,7 @@ | |||
| 17 | * @returns {Buffer|Blob} | 17 | * @returns {Buffer|Blob} |
| 18 | */ | 18 | */ |
| 19 | export default function fromDataURI(uri, asBlob, options) { | 19 | export default function fromDataURI(uri, asBlob, options) { |
| 20 | const _Blob = options && options.Blob || platform.classes.Blob; | 20 | const _Blob = (options && options.Blob) || platform.classes.Blob; |
| 21 | const protocol = parseProtocol(uri); | 21 | const protocol = parseProtocol(uri); |
| 22 | 22 | ||
| 23 | if (asBlob === undefined && _Blob) { | 23 | if (asBlob === undefined && _Blob) { |
@@ -43,7 +43,7 @@ | |||
| 43 | throw new AxiosError('Blob is not supported', AxiosError.ERR_NOT_SUPPORT); | 43 | throw new AxiosError('Blob is not supported', AxiosError.ERR_NOT_SUPPORT); |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | return new _Blob([buffer], {type: mime}); | 46 | return new _Blob([buffer], { type: mime }); |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | return buffer; | 49 | return buffer; |
@@ -19,7 +19,7 @@ | |||
| 19 | HttpStatusCode, | 19 | HttpStatusCode, |
| 20 | formToJSON, | 20 | formToJSON, |
| 21 | getAdapter, | 21 | getAdapter, |
| 22 | mergeConfig | 22 | mergeConfig, |
| 23 | } = axios; | 23 | } = axios; |
| 24 | 24 | ||
| 25 | export { | 25 | export { |
@@ -39,5 +39,5 @@ | |||
| 39 | HttpStatusCode, | 39 | HttpStatusCode, |
| 40 | formToJSON, | 40 | formToJSON, |
| 41 | getAdapter, | 41 | getAdapter, |
| 42 | mergeConfig | ||
| 43 | } | 42 | mergeConfig, |
| 43 | }; | ||
@@ -1,13 +1,13 @@ | |||
| 1 | import URLSearchParams from './classes/URLSearchParams.js' | ||
| 2 | import FormData from './classes/FormData.js' | ||
| 3 | import Blob from './classes/Blob.js' | 1 | import URLSearchParams from './classes/URLSearchParams.js'; |
| 2 | import FormData from './classes/FormData.js'; | ||
| 3 | import Blob from './classes/Blob.js'; | ||
| 4 | 4 | ||
| 5 | export default { | 5 | export default { |
| 6 | isBrowser: true, | 6 | isBrowser: true, |
| 7 | classes: { | 7 | classes: { |
| 8 | URLSearchParams, | 8 | URLSearchParams, |
| 9 | FormData, | 9 | FormData, |
| 10 | Blob | 10 | Blob, |
| 11 | }, | 11 | }, |
| 12 | protocols: ['http', 'https', 'file', 'blob', 'url', 'data'] | 12 | protocols: ['http', 'https', 'file', 'blob', 'url', 'data'], |
| 13 | }; | 13 | }; |
@@ -1,20 +1,20 @@ | |||
| 1 | import crypto from 'crypto'; | 1 | import crypto from 'crypto'; |
| 2 | import URLSearchParams from './classes/URLSearchParams.js' | ||
| 3 | import FormData from './classes/FormData.js' | 2 | import URLSearchParams from './classes/URLSearchParams.js'; |
| 3 | import FormData from './classes/FormData.js'; | ||
| 4 | 4 | ||
| 5 | const ALPHA = 'abcdefghijklmnopqrstuvwxyz' | 5 | const ALPHA = 'abcdefghijklmnopqrstuvwxyz'; |
| 6 | 6 | ||
| 7 | const DIGIT = '0123456789'; | 7 | const DIGIT = '0123456789'; |
| 8 | 8 | ||
| 9 | const ALPHABET = { | 9 | const ALPHABET = { |
| 10 | DIGIT, | 10 | DIGIT, |
| 11 | ALPHA, | 11 | ALPHA, |
| 12 | ALPHA_DIGIT: ALPHA + ALPHA.toUpperCase() + DIGIT | ||
| 13 | } | 12 | ALPHA_DIGIT: ALPHA + ALPHA.toUpperCase() + DIGIT, |
| 13 | }; | ||
| 14 | 14 | ||
| 15 | const generateString = (size = 16, alphabet = ALPHABET.ALPHA_DIGIT) => { | 15 | const generateString = (size = 16, alphabet = ALPHABET.ALPHA_DIGIT) => { |
| 16 | let str = ''; | 16 | let str = ''; |
| 17 | const {length} = alphabet; | 17 | const { length } = alphabet; |
| 18 | const randomValues = new Uint32Array(size); | 18 | const randomValues = new Uint32Array(size); |
| 19 | crypto.randomFillSync(randomValues); | 19 | crypto.randomFillSync(randomValues); |
| 20 | for (let i = 0; i < size; i++) { | 20 | for (let i = 0; i < size; i++) { |
@@ -22,17 +22,16 @@ | |||
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | return str; | 24 | return str; |
| 25 | } | 25 | }; |
| 26 | 26 | ||
| 27 | |||
| 28 | export default { | 27 | export default { |
| 29 | isNode: true, | 28 | isNode: true, |
| 30 | classes: { | 29 | classes: { |
| 31 | URLSearchParams, | 30 | URLSearchParams, |
| 32 | FormData, | 31 | FormData, |
| 33 | Blob: typeof Blob !== 'undefined' && Blob || null | 32 | Blob: (typeof Blob !== 'undefined' && Blob) || null, |
| 34 | }, | 33 | }, |
| 35 | ALPHABET, | 34 | ALPHABET, |
| 36 | generateString, | 35 | generateString, |
| 37 | protocols: [ 'http', 'https', 'file', 'data' ] | 36 | protocols: ['http', 'https', 'file', 'data'], |
| 38 | }; | 37 | }; |
@@ -21,7 +21,7 @@ | |||
| 21 | fulfilled, | 21 | fulfilled, |
| 22 | rejected, | 22 | rejected, |
| 23 | synchronous: options ? options.synchronous : false, | 23 | synchronous: options ? options.synchronous : false, |
| 24 | runWhen: options ? options.runWhen : null | 24 | runWhen: options ? options.runWhen : null, |
| 25 | }); | 25 | }); |
| 26 | return this.handlers.length - 1; | 26 | return this.handlers.length - 1; |
| 27 | } | 27 | } |
@@ -10,5 +10,5 @@ | |||
| 10 | * @returns {boolean} True if the payload is an error thrown by Axios, otherwise false | 10 | * @returns {boolean} True if the payload is an error thrown by Axios, otherwise false |
| 11 | */ | 11 | */ |
| 12 | export default function isAxiosError(payload) { | 12 | export default function isAxiosError(payload) { |
| 13 | return utils.isObject(payload) && (payload.isAxiosError === true); | 13 | return utils.isObject(payload) && payload.isAxiosError === true; |
| 14 | } | 14 | } |
@@ -1,14 +1,16 @@ | |||
| 1 | import platform from '../platform/index.js'; | 1 | import platform from '../platform/index.js'; |
| 2 | 2 | ||
| 3 | export default platform.hasStandardBrowserEnv ? ((origin, isMSIE) => (url) => { | ||
| 4 | url = new URL(url, platform.origin); | 3 | export default platform.hasStandardBrowserEnv |
| 4 | ? ((origin, isMSIE) => (url) => { | ||
| 5 | url = new URL(url, platform.origin); | ||
| 5 | 6 | ||
| 6 | return ( | ||
| 7 | origin.protocol === url.protocol && | ||
| 8 | origin.host === url.host && | ||
| 9 | (isMSIE || origin.port === url.port) | ||
| 10 | ); | ||
| 11 | })( | ||
| 12 | new URL(platform.origin), | ||
| 13 | platform.navigator && /(msie|trident)/i.test(platform.navigator.userAgent) | ||
| 14 | ) : () => true; | 7 | return ( |
| 8 | origin.protocol === url.protocol && | ||
| 9 | origin.host === url.host && | ||
| 10 | (isMSIE || origin.port === url.port) | ||
| 11 | ); | ||
| 12 | })( | ||
| 13 | new URL(platform.origin), | ||
| 14 | platform.navigator && /(msie|trident)/i.test(platform.navigator.userAgent) | ||
| 15 | ) | ||
| 16 | : () => true; | ||
@@ -1,10 +1,9 @@ | |||
| 1 | "use strict"; | 1 | 'use strict'; |
| 2 | 2 | ||
| 3 | import utils from "../utils.js"; | ||
| 4 | import AxiosHeaders from "./AxiosHeaders.js"; | 3 | import utils from '../utils.js'; |
| 4 | import AxiosHeaders from './AxiosHeaders.js'; | ||
| 5 | 5 | ||
| 6 | const headersToObject = (thing) => | ||
| 7 | thing instanceof AxiosHeaders ? { ...thing } : thing; | 6 | const headersToObject = (thing) => (thing instanceof AxiosHeaders ? { ...thing } : thing); |
| 8 | 7 | ||
| 9 | /** | 8 | /** |
| 10 | * Config-specific merge-function which creates a new config-object | 9 | * Config-specific merge-function which creates a new config-object |
@@ -97,23 +96,12 @@ | |||
| 97 | mergeDeepProperties(headersToObject(a), headersToObject(b), prop, true), | 96 | mergeDeepProperties(headersToObject(a), headersToObject(b), prop, true), |
| 98 | }; | 97 | }; |
| 99 | 98 | ||
| 100 | utils.forEach( | ||
| 101 | Object.keys({ ...config1, ...config2 }), | ||
| 102 | function computeConfigValue(prop) { | ||
| 103 | if ( | ||
| 104 | prop === "__proto__" || | ||
| 105 | prop === "constructor" || | ||
| 106 | prop === "prototype" | ||
| 107 | ) | ||
| 108 | return; | ||
| 109 | const merge = utils.hasOwnProp(mergeMap, prop) | ||
| 110 | ? mergeMap[prop] | ||
| 111 | : mergeDeepProperties; | ||
| 112 | const configValue = merge(config1[prop], config2[prop], prop); | ||
| 113 | (utils.isUndefined(configValue) && merge !== mergeDirectKeys) || | ||
| 114 | (config[prop] = configValue); | ||
| 115 | }, | ||
| 116 | ); | 99 | utils.forEach(Object.keys({ ...config1, ...config2 }), function computeConfigValue(prop) { |
| 100 | if (prop === '__proto__' || prop === 'constructor' || prop === 'prototype') return; | ||
| 101 | const merge = utils.hasOwnProp(mergeMap, prop) ? mergeMap[prop] : mergeDeepProperties; | ||
| 102 | const configValue = merge(config1[prop], config2[prop], prop); | ||
| 103 | (utils.isUndefined(configValue) && merge !== mergeDirectKeys) || (config[prop] = configValue); | ||
| 104 | }); | ||
| 117 | 105 | ||
| 118 | return config; | 106 | return config; |
| 119 | } | 107 | } |
@@ -5,10 +5,23 @@ | |||
| 5 | // RawAxiosHeaders whose duplicates are ignored by node | 5 | // RawAxiosHeaders whose duplicates are ignored by node |
| 6 | // c.f. https://nodejs.org/api/http.html#http_message_headers | 6 | // c.f. https://nodejs.org/api/http.html#http_message_headers |
| 7 | const ignoreDuplicateOf = utils.toObjectSet([ | 7 | const ignoreDuplicateOf = utils.toObjectSet([ |
| 8 | 'age', 'authorization', 'content-length', 'content-type', 'etag', | ||
| 9 | 'expires', 'from', 'host', 'if-modified-since', 'if-unmodified-since', | ||
| 10 | 'last-modified', 'location', 'max-forwards', 'proxy-authorization', | ||
| 11 | 'referer', 'retry-after', 'user-agent' | 8 | 'age', |
| 9 | 'authorization', | ||
| 10 | 'content-length', | ||
| 11 | 'content-type', | ||
| 12 | 'etag', | ||
| 13 | 'expires', | ||
| 14 | 'from', | ||
| 15 | 'host', | ||
| 16 | 'if-modified-since', | ||
| 17 | 'if-unmodified-since', | ||
| 18 | 'last-modified', | ||
| 19 | 'location', | ||
| 20 | 'max-forwards', | ||
| 21 | 'proxy-authorization', | ||
| 22 | 'referer', | ||
| 23 | 'retry-after', | ||
| 24 | 'user-agent', | ||
| 12 | ]); | 25 | ]); |
| 13 | 26 | ||
| 14 | /** | 27 | /** |
@@ -25,31 +38,32 @@ | |||
| 25 | * | 38 | * |
| 26 | * @returns {Object} Headers parsed into an object | 39 | * @returns {Object} Headers parsed into an object |
| 27 | */ | 40 | */ |
| 28 | export default rawHeaders => { | 41 | export default (rawHeaders) => { |
| 29 | const parsed = {}; | 42 | const parsed = {}; |
| 30 | let key; | 43 | let key; |
| 31 | let val; | 44 | let val; |
| 32 | let i; | 45 | let i; |
| 33 | 46 | ||
| 34 | rawHeaders && rawHeaders.split('\n').forEach(function parser(line) { | ||
| 35 | i = line.indexOf(':'); | ||
| 36 | key = line.substring(0, i).trim().toLowerCase(); | ||
| 37 | val = line.substring(i + 1).trim(); | 47 | rawHeaders && |
| 48 | rawHeaders.split('\n').forEach(function parser(line) { | ||
| 49 | i = line.indexOf(':'); | ||
| 50 | key = line.substring(0, i).trim().toLowerCase(); | ||
| 51 | val = line.substring(i + 1).trim(); | ||
| 38 | 52 | ||
| 39 | if (!key || (parsed[key] && ignoreDuplicateOf[key])) { | ||
| 40 | return; | ||
| 41 | } | 53 | if (!key || (parsed[key] && ignoreDuplicateOf[key])) { |
| 54 | return; | ||
| 55 | } | ||
| 42 | 56 | ||
| 43 | if (key === 'set-cookie') { | ||
| 44 | if (parsed[key]) { | ||
| 45 | parsed[key].push(val); | 57 | if (key === 'set-cookie') { |
| 58 | if (parsed[key]) { | ||
| 59 | parsed[key].push(val); | ||
| 60 | } else { | ||
| 61 | parsed[key] = [val]; | ||
| 62 | } | ||
| 46 | } else { | 63 | } else { |
| 47 | parsed[key] = [val]; | 64 | parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val; |
| 48 | } | 65 | } |
| 49 | } else { | ||
| 50 | parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val; | ||
| 51 | } | ||
| 52 | }); | 66 | }); |
| 53 | 67 | ||
| 54 | return parsed; | 68 | return parsed; |
| 55 | }; | 69 | }; |
@@ -1,12 +1,12 @@ | |||
| 1 | import speedometer from "./speedometer.js"; | ||
| 2 | import throttle from "./throttle.js"; | ||
| 3 | import utils from "../utils.js"; | 1 | import speedometer from './speedometer.js'; |
| 2 | import throttle from './throttle.js'; | ||
| 3 | import utils from '../utils.js'; | ||
| 4 | 4 | ||
| 5 | export const progressEventReducer = (listener, isDownloadStream, freq = 3) => { | 5 | export const progressEventReducer = (listener, isDownloadStream, freq = 3) => { |
| 6 | let bytesNotified = 0; | 6 | let bytesNotified = 0; |
| 7 | const _speedometer = speedometer(50, 250); | 7 | const _speedometer = speedometer(50, 250); |
| 8 | 8 | ||
| 9 | return throttle(e => { | 9 | return throttle((e) => { |
| 10 | const loaded = e.loaded; | 10 | const loaded = e.loaded; |
| 11 | const total = e.lengthComputable ? e.total : undefined; | 11 | const total = e.lengthComputable ? e.total : undefined; |
| 12 | const progressBytes = loaded - bytesNotified; | 12 | const progressBytes = loaded - bytesNotified; |
@@ -18,27 +18,34 @@ | |||
| 18 | const data = { | 18 | const data = { |
| 19 | loaded, | 19 | loaded, |
| 20 | total, | 20 | total, |
| 21 | progress: total ? (loaded / total) : undefined, | 21 | progress: total ? loaded / total : undefined, |
| 22 | bytes: progressBytes, | 22 | bytes: progressBytes, |
| 23 | rate: rate ? rate : undefined, | 23 | rate: rate ? rate : undefined, |
| 24 | estimated: rate && total && inRange ? (total - loaded) / rate : undefined, | 24 | estimated: rate && total && inRange ? (total - loaded) / rate : undefined, |
| 25 | event: e, | 25 | event: e, |
| 26 | lengthComputable: total != null, | 26 | lengthComputable: total != null, |
| 27 | [isDownloadStream ? 'download' : 'upload']: true | 27 | [isDownloadStream ? 'download' : 'upload']: true, |
| 28 | }; | 28 | }; |
| 29 | 29 | ||
| 30 | listener(data); | 30 | listener(data); |
| 31 | }, freq); | 31 | }, freq); |
| 32 | } | 32 | }; |
| 33 | 33 | ||
| 34 | export const progressEventDecorator = (total, throttled) => { | 34 | export const progressEventDecorator = (total, throttled) => { |
| 35 | const lengthComputable = total != null; | 35 | const lengthComputable = total != null; |
| 36 | 36 | ||
| 37 | return [(loaded) => throttled[0]({ | ||
| 38 | lengthComputable, | ||
| 39 | total, | ||
| 40 | loaded | ||
| 41 | }), throttled[1]]; | ||
| 42 | } | 37 | return [ |
| 38 | (loaded) => | ||
| 39 | throttled[0]({ | ||
| 40 | lengthComputable, | ||
| 41 | total, | ||
| 42 | loaded, | ||
| 43 | }), | ||
| 44 | throttled[1], | ||
| 45 | ]; | ||
| 46 | }; | ||
| 43 | 47 | ||
| 44 | export const asyncDecorator = (fn) => (...args) => utils.asap(() => fn(...args)); | 48 | export const asyncDecorator = |
| 49 | (fn) => | ||
| 50 | (...args) => | ||
| 51 | utils.asap(() => fn(...args)); | ||
@@ -1,15 +1,15 @@ | |||
| 1 | const {asyncIterator} = Symbol; | 1 | const { asyncIterator } = Symbol; |
| 2 | 2 | ||
| 3 | const readBlob = async function* (blob) { | 3 | const readBlob = async function* (blob) { |
| 4 | if (blob.stream) { | 4 | if (blob.stream) { |
| 5 | yield* blob.stream() | 5 | yield* blob.stream(); |
| 6 | } else if (blob.arrayBuffer) { | 6 | } else if (blob.arrayBuffer) { |
| 7 | yield await blob.arrayBuffer() | 7 | yield await blob.arrayBuffer(); |
| 8 | } else if (blob[asyncIterator]) { | 8 | } else if (blob[asyncIterator]) { |
| 9 | yield* blob[asyncIterator](); | 9 | yield* blob[asyncIterator](); |
| 10 | } else { | 10 | } else { |
| 11 | yield blob; | 11 | yield blob; |
| 12 | } | 12 | } |
| 13 | } | 13 | }; |
| 14 | 14 | ||
| 15 | export default readBlob; | 15 | export default readBlob; |
@@ -1,11 +1,11 @@ | |||
| 1 | import platform from "../platform/index.js"; | ||
| 2 | import utils from "../utils.js"; | ||
| 3 | import isURLSameOrigin from "./isURLSameOrigin.js"; | ||
| 4 | import cookies from "./cookies.js"; | ||
| 5 | import buildFullPath from "../core/buildFullPath.js"; | ||
| 6 | import mergeConfig from "../core/mergeConfig.js"; | ||
| 7 | import AxiosHeaders from "../core/AxiosHeaders.js"; | ||
| 8 | import buildURL from "./buildURL.js"; | 1 | import platform from '../platform/index.js'; |
| 2 | import utils from '../utils.js'; | ||
| 3 | import isURLSameOrigin from './isURLSameOrigin.js'; | ||
| 4 | import cookies from './cookies.js'; | ||
| 5 | import buildFullPath from '../core/buildFullPath.js'; | ||
| 6 | import mergeConfig from '../core/mergeConfig.js'; | ||
| 7 | import AxiosHeaders from '../core/AxiosHeaders.js'; | ||
| 8 | import buildURL from './buildURL.js'; | ||
| 9 | 9 | ||
| 10 | export default (config) => { | 10 | export default (config) => { |
| 11 | const newConfig = mergeConfig({}, config); | 11 | const newConfig = mergeConfig({}, config); |
@@ -14,12 +14,22 @@ | |||
| 14 | 14 | ||
| 15 | newConfig.headers = headers = AxiosHeaders.from(headers); | 15 | newConfig.headers = headers = AxiosHeaders.from(headers); |
| 16 | 16 | ||
| 17 | newConfig.url = buildURL(buildFullPath(newConfig.baseURL, newConfig.url, newConfig.allowAbsoluteUrls), config.params, config.paramsSerializer); | 17 | newConfig.url = buildURL( |
| 18 | buildFullPath(newConfig.baseURL, newConfig.url, newConfig.allowAbsoluteUrls), | ||
| 19 | config.params, | ||
| 20 | config.paramsSerializer | ||
| 21 | ); | ||
| 18 | 22 | ||
| 19 | // HTTP basic authentication | 23 | // HTTP basic authentication |
| 20 | if (auth) { | 24 | if (auth) { |
| 21 | headers.set('Authorization', 'Basic ' + | ||
| 22 | btoa((auth.username || '') + ':' + (auth.password ? unescape(encodeURIComponent(auth.password)) : '')) | 25 | headers.set( |
| 26 | 'Authorization', | ||
| 27 | 'Basic ' + | ||
| 28 | btoa( | ||
| 29 | (auth.username || '') + | ||
| 30 | ':' + | ||
| 31 | (auth.password ? unescape(encodeURIComponent(auth.password)) : '') | ||
| 32 | ) | ||
| 23 | ); | 33 | ); |
| 24 | } | 34 | } |
| 25 | 35 | ||
@@ -37,7 +47,7 @@ | |||
| 37 | } | 47 | } |
| 38 | }); | 48 | }); |
| 39 | } | 49 | } |
| 40 | } | 50 | } |
| 41 | 51 | ||
| 42 | // Add xsrf header | 52 | // Add xsrf header |
| 43 | // This is only done if running in a standard browser environment. | 53 | // This is only done if running in a standard browser environment. |
@@ -57,5 +67,4 @@ | |||
| 57 | } | 67 | } |
| 58 | 68 | ||
| 59 | return newConfig; | 69 | return newConfig; |
| 60 | } | ||
| 61 | 70 | }; | |
@@ -16,12 +16,16 @@ | |||
| 16 | if (!response.status || !validateStatus || validateStatus(response.status)) { | 16 | if (!response.status || !validateStatus || validateStatus(response.status)) { |
| 17 | resolve(response); | 17 | resolve(response); |
| 18 | } else { | 18 | } else { |
| 19 | reject(new AxiosError( | ||
| 20 | 'Request failed with status code ' + response.status, | ||
| 21 | [AxiosError.ERR_BAD_REQUEST, AxiosError.ERR_BAD_RESPONSE][Math.floor(response.status / 100) - 4], | ||
| 22 | response.config, | ||
| 23 | response.request, | ||
| 24 | response | ||
| 25 | )); | 19 | reject( |
| 20 | new AxiosError( | ||
| 21 | 'Request failed with status code ' + response.status, | ||
| 22 | [AxiosError.ERR_BAD_REQUEST, AxiosError.ERR_BAD_RESPONSE][ | ||
| 23 | Math.floor(response.status / 100) - 4 | ||
| 24 | ], | ||
| 25 | response.config, | ||
| 26 | response.request, | ||
| 27 | response | ||
| 28 | ) | ||
| 29 | ); | ||
| 26 | } | 30 | } |
| 27 | } | 31 | } |
@@ -18,23 +18,23 @@ | |||
| 18 | timer = null; | 18 | timer = null; |
| 19 | } | 19 | } |
| 20 | fn(...args); | 20 | fn(...args); |
| 21 | } | 21 | }; |
| 22 | 22 | ||
| 23 | const throttled = (...args) => { | 23 | const throttled = (...args) => { |
| 24 | const now = Date.now(); | 24 | const now = Date.now(); |
| 25 | const passed = now - timestamp; | 25 | const passed = now - timestamp; |
| 26 | if ( passed >= threshold) { | 26 | if (passed >= threshold) { |
| 27 | invoke(args, now); | 27 | invoke(args, now); |
| 28 | } else { | 28 | } else { |
| 29 | lastArgs = args; | 29 | lastArgs = args; |
| 30 | if (!timer) { | 30 | if (!timer) { |
| 31 | timer = setTimeout(() => { | 31 | timer = setTimeout(() => { |
| 32 | timer = null; | 32 | timer = null; |
| 33 | invoke(lastArgs) | 33 | invoke(lastArgs); |
| 34 | }, threshold - passed); | 34 | }, threshold - passed); |
| 35 | } | 35 | } |
| 36 | } | 36 | } |
| 37 | } | 37 | }; |
| 38 | 38 | ||
| 39 | const flush = () => lastArgs && invoke(lastArgs); | 39 | const flush = () => lastArgs && invoke(lastArgs); |
| 40 | 40 | ||
@@ -38,11 +38,14 @@ | |||
| 38 | */ | 38 | */ |
| 39 | function renderKey(path, key, dots) { | 39 | function renderKey(path, key, dots) { |
| 40 | if (!path) return key; | 40 | if (!path) return key; |
| 41 | return path.concat(key).map(function each(token, i) { | ||
| 42 | // eslint-disable-next-line no-param-reassign | ||
| 43 | token = removeBrackets(token); | ||
| 44 | return !dots && i ? '[' + token + ']' : token; | ||
| 45 | }).join(dots ? '.' : ''); | 41 | return path |
| 42 | .concat(key) | ||
| 43 | .map(function each(token, i) { | ||
| 44 | // eslint-disable-next-line no-param-reassign | ||
| 45 | token = removeBrackets(token); | ||
| 46 | return !dots && i ? '[' + token + ']' : token; | ||
| 47 | }) | ||
| 48 | .join(dots ? '.' : ''); | ||
| 46 | } | 49 | } |
| 47 | 50 | ||
| 48 | /** | 51 | /** |
@@ -92,21 +95,26 @@ | |||
| 92 | formData = formData || new (PlatformFormData || FormData)(); | 95 | formData = formData || new (PlatformFormData || FormData)(); |
| 93 | 96 | ||
| 94 | // eslint-disable-next-line no-param-reassign | 97 | // eslint-disable-next-line no-param-reassign |
| 95 | options = utils.toFlatObject(options, { | ||
| 96 | metaTokens: true, | ||
| 97 | dots: false, | ||
| 98 | indexes: false | ||
| 99 | }, false, function defined(option, source) { | ||
| 100 | // eslint-disable-next-line no-eq-null,eqeqeq | ||
| 101 | return !utils.isUndefined(source[option]); | ||
| 102 | }); | 98 | options = utils.toFlatObject( |
| 99 | options, | ||
| 100 | { | ||
| 101 | metaTokens: true, | ||
| 102 | dots: false, | ||
| 103 | indexes: false, | ||
| 104 | }, | ||
| 105 | false, | ||
| 106 | function defined(option, source) { | ||
| 107 | // eslint-disable-next-line no-eq-null,eqeqeq | ||
| 108 | return !utils.isUndefined(source[option]); | ||
| 109 | } | ||
| 110 | ); | ||
| 103 | 111 | ||
| 104 | const metaTokens = options.metaTokens; | 112 | const metaTokens = options.metaTokens; |
| 105 | // eslint-disable-next-line no-use-before-define | 113 | // eslint-disable-next-line no-use-before-define |
| 106 | const visitor = options.visitor || defaultVisitor; | 114 | const visitor = options.visitor || defaultVisitor; |
| 107 | const dots = options.dots; | 115 | const dots = options.dots; |
| 108 | const indexes = options.indexes; | 116 | const indexes = options.indexes; |
| 109 | const _Blob = options.Blob || typeof Blob !== 'undefined' && Blob; | 117 | const _Blob = options.Blob || (typeof Blob !== 'undefined' && Blob); |
| 110 | const useBlob = _Blob && utils.isSpecCompliantForm(formData); | 118 | const useBlob = _Blob && utils.isSpecCompliantForm(formData); |
| 111 | 119 | ||
| 112 | if (!utils.isFunction(visitor)) { | 120 | if (!utils.isFunction(visitor)) { |
@@ -148,6 +156,11 @@ | |||
| 148 | function defaultVisitor(value, key, path) { | 156 | function defaultVisitor(value, key, path) { |
| 149 | let arr = value; | 157 | let arr = value; |
| 150 | 158 | ||
| 159 | if (utils.isReactNative(formData) && utils.isReactNativeBlob(value)) { | ||
| 160 | formData.append(renderKey(path, key, dots), convertValue(value)); | ||
| 161 | return false; | ||
| 162 | } | ||
| 163 | |||
| 151 | if (value && !path && typeof value === 'object') { | 164 | if (value && !path && typeof value === 'object') { |
| 152 | if (utils.endsWith(key, '{}')) { | 165 | if (utils.endsWith(key, '{}')) { |
| 153 | // eslint-disable-next-line no-param-reassign | 166 | // eslint-disable-next-line no-param-reassign |
@@ -156,17 +169,22 @@ | |||
| 156 | value = JSON.stringify(value); | 169 | value = JSON.stringify(value); |
| 157 | } else if ( | 170 | } else if ( |
| 158 | (utils.isArray(value) && isFlatArray(value)) || | 171 | (utils.isArray(value) && isFlatArray(value)) || |
| 159 | ((utils.isFileList(value) || utils.endsWith(key, '[]')) && (arr = utils.toArray(value)) | ||
| 160 | )) { | 172 | ((utils.isFileList(value) || utils.endsWith(key, '[]')) && (arr = utils.toArray(value))) |
| 173 | ) { | ||
| 161 | // eslint-disable-next-line no-param-reassign | 174 | // eslint-disable-next-line no-param-reassign |
| 162 | key = removeBrackets(key); | 175 | key = removeBrackets(key); |
| 163 | 176 | ||
| 164 | arr.forEach(function each(el, index) { | 177 | arr.forEach(function each(el, index) { |
| 165 | !(utils.isUndefined(el) || el === null) && formData.append( | ||
| 166 | // eslint-disable-next-line no-nested-ternary | ||
| 167 | indexes === true ? renderKey([key], index, dots) : (indexes === null ? key : key + '[]'), | ||
| 168 | convertValue(el) | ||
| 169 | ); | 178 | !(utils.isUndefined(el) || el === null) && |
| 179 | formData.append( | ||
| 180 | // eslint-disable-next-line no-nested-ternary | ||
| 181 | indexes === true | ||
| 182 | ? renderKey([key], index, dots) | ||
| 183 | : indexes === null | ||
| 184 | ? key | ||
| 185 | : key + '[]', | ||
| 186 | convertValue(el) | ||
| 187 | ); | ||
| 170 | }); | 188 | }); |
| 171 | return false; | 189 | return false; |
| 172 | } | 190 | } |
@@ -186,7 +204,7 @@ | |||
| 186 | const exposedHelpers = Object.assign(predicates, { | 204 | const exposedHelpers = Object.assign(predicates, { |
| 187 | defaultVisitor, | 205 | defaultVisitor, |
| 188 | convertValue, | 206 | convertValue, |
| 189 | isVisitable | 207 | isVisitable, |
| 190 | }); | 208 | }); |
| 191 | 209 | ||
| 192 | function build(value, path) { | 210 | function build(value, path) { |
@@ -199,9 +217,9 @@ | |||
| 199 | stack.push(value); | 217 | stack.push(value); |
| 200 | 218 | ||
| 201 | utils.forEach(value, function each(el, key) { | 219 | utils.forEach(value, function each(el, key) { |
| 202 | const result = !(utils.isUndefined(el) || el === null) && visitor.call( | ||
| 203 | formData, el, utils.isString(key) ? key.trim() : key, path, exposedHelpers | ||
| 204 | ); | 220 | const result = |
| 221 | !(utils.isUndefined(el) || el === null) && | ||
| 222 | visitor.call(formData, el, utils.isString(key) ? key.trim() : key, path, exposedHelpers); | ||
| 205 | 223 | ||
| 206 | if (result === true) { | 224 | if (result === true) { |
| 207 | build(el, path ? path.concat(key) : [key]); | 225 | build(el, path ? path.concat(key) : [key]); |
@@ -6,7 +6,7 @@ | |||
| 6 | 6 | ||
| 7 | export default function toURLEncodedForm(data, options) { | 7 | export default function toURLEncodedForm(data, options) { |
| 8 | return toFormData(data, new platform.classes.URLSearchParams(), { | 8 | return toFormData(data, new platform.classes.URLSearchParams(), { |
| 9 | visitor: function(value, key, path, helpers) { | 9 | visitor: function (value, key, path, helpers) { |
| 10 | if (platform.isNode && utils.isBuffer(value)) { | 10 | if (platform.isNode && utils.isBuffer(value)) { |
| 11 | this.append(key, value.toString('base64')); | 11 | this.append(key, value.toString('base64')); |
| 12 | return false; | 12 | return false; |
@@ -14,6 +14,6 @@ | |||
| 14 | 14 | ||
| 15 | return helpers.defaultVisitor.apply(this, arguments); | 15 | return helpers.defaultVisitor.apply(this, arguments); |
| 16 | }, | 16 | }, |
| 17 | ...options | 17 | ...options, |
| 18 | }); | 18 | }); |
| 19 | } | 19 | } |
@@ -1,4 +1,3 @@ | |||
| 1 | |||
| 2 | export const streamChunk = function* (chunk, chunkSize) { | 1 | export const streamChunk = function* (chunk, chunkSize) { |
| 3 | let len = chunk.byteLength; | 2 | let len = chunk.byteLength; |
| 4 | 3 | ||
@@ -15,13 +14,13 @@ | |||
| 15 | yield chunk.slice(pos, end); | 14 | yield chunk.slice(pos, end); |
| 16 | pos = end; | 15 | pos = end; |
| 17 | } | 16 | } |
| 18 | } | 17 | }; |
| 19 | 18 | ||
| 20 | export const readBytes = async function* (iterable, chunkSize) { | 19 | export const readBytes = async function* (iterable, chunkSize) { |
| 21 | for await (const chunk of readStream(iterable)) { | 20 | for await (const chunk of readStream(iterable)) { |
| 22 | yield* streamChunk(chunk, chunkSize); | 21 | yield* streamChunk(chunk, chunkSize); |
| 23 | } | 22 | } |
| 24 | } | 23 | }; |
| 25 | 24 | ||
| 26 | const readStream = async function* (stream) { | 25 | const readStream = async function* (stream) { |
| 27 | if (stream[Symbol.asyncIterator]) { | 26 | if (stream[Symbol.asyncIterator]) { |
@@ -32,7 +31,7 @@ | |||
| 32 | const reader = stream.getReader(); | 31 | const reader = stream.getReader(); |
| 33 | try { | 32 | try { |
| 34 | for (;;) { | 33 | for (;;) { |
| 35 | const {done, value} = await reader.read(); | 34 | const { done, value } = await reader.read(); |
| 36 | if (done) { | 35 | if (done) { |
| 37 | break; | 36 | break; |
| 38 | } | 37 | } |
@@ -41,7 +40,7 @@ | |||
| 41 | } finally { | 40 | } finally { |
| 42 | await reader.cancel(); | 41 | await reader.cancel(); |
| 43 | } | 42 | } |
| 44 | } | 43 | }; |
| 45 | 44 | ||
| 46 | export const trackStream = (stream, chunkSize, onProgress, onFinish) => { | 45 | export const trackStream = (stream, chunkSize, onProgress, onFinish) => { |
| 47 | const iterator = readBytes(stream, chunkSize); | 46 | const iterator = readBytes(stream, chunkSize); |
@@ -53,35 +52,38 @@ | |||
| 53 | done = true; | 52 | done = true; |
| 54 | onFinish && onFinish(e); | 53 | onFinish && onFinish(e); |
| 55 | } | 54 | } |
| 56 | } | 55 | }; |
| 57 | 56 | ||
| 58 | return new ReadableStream({ | ||
| 59 | async pull(controller) { | ||
| 60 | try { | ||
| 61 | const {done, value} = await iterator.next(); | 57 | return new ReadableStream( |
| 58 | { | ||
| 59 | async pull(controller) { | ||
| 60 | try { | ||
| 61 | const { done, value } = await iterator.next(); | ||
| 62 | 62 | ||
| 63 | if (done) { | ||
| 64 | _onFinish(); | ||
| 65 | controller.close(); | ||
| 66 | return; | ||
| 67 | } | 63 | if (done) { |
| 64 | _onFinish(); | ||
| 65 | controller.close(); | ||
| 66 | return; | ||
| 67 | } | ||
| 68 | 68 | ||
| 69 | let len = value.byteLength; | ||
| 70 | if (onProgress) { | ||
| 71 | let loadedBytes = bytes += len; | ||
| 72 | onProgress(loadedBytes); | 69 | let len = value.byteLength; |
| 70 | if (onProgress) { | ||
| 71 | let loadedBytes = (bytes += len); | ||
| 72 | onProgress(loadedBytes); | ||
| 73 | } | ||
| 74 | controller.enqueue(new Uint8Array(value)); | ||
| 75 | } catch (err) { | ||
| 76 | _onFinish(err); | ||
| 77 | throw err; | ||
| 73 | } | 78 | } |
| 74 | controller.enqueue(new Uint8Array(value)); | ||
| 75 | } catch (err) { | ||
| 76 | _onFinish(err); | ||
| 77 | throw err; | ||
| 78 | } | 79 | }, |
| 80 | cancel(reason) { | ||
| 81 | _onFinish(reason); | ||
| 82 | return iterator.return(); | ||
| 83 | }, | ||
| 79 | }, | 84 | }, |
| 80 | cancel(reason) { | ||
| 81 | _onFinish(reason); | ||
| 82 | return iterator.return(); | 85 | { |
| 86 | highWaterMark: 2, | ||
| 83 | } | 87 | } |
| 84 | }, { | ||
| 85 | highWaterMark: 2 | ||
| 86 | }) | ||
| 87 | } | 88 | ); |
| 89 | }; | ||
@@ -1,6 +1,6 @@ | |||
| 1 | const hasBrowserEnv = typeof window !== 'undefined' && typeof document !== 'undefined'; | 1 | const hasBrowserEnv = typeof window !== 'undefined' && typeof document !== 'undefined'; |
| 2 | 2 | ||
| 3 | const _navigator = typeof navigator === 'object' && navigator || undefined; | 3 | const _navigator = (typeof navigator === 'object' && navigator) || undefined; |
| 4 | 4 | ||
| 5 | /** | 5 | /** |
| 6 | * Determine if we're running in a standard browser environment | 6 | * Determine if we're running in a standard browser environment |
@@ -19,7 +19,8 @@ | |||
| 19 | * | 19 | * |
| 20 | * @returns {boolean} | 20 | * @returns {boolean} |
| 21 | */ | 21 | */ |
| 22 | const hasStandardBrowserEnv = hasBrowserEnv && | 22 | const hasStandardBrowserEnv = |
| 23 | hasBrowserEnv && | ||
| 23 | (!_navigator || ['ReactNative', 'NativeScript', 'NS'].indexOf(_navigator.product) < 0); | 24 | (!_navigator || ['ReactNative', 'NativeScript', 'NS'].indexOf(_navigator.product) < 0); |
| 24 | 25 | ||
| 25 | /** | 26 | /** |
@@ -40,12 +41,12 @@ | |||
| 40 | ); | 41 | ); |
| 41 | })(); | 42 | })(); |
| 42 | 43 | ||
| 43 | const origin = hasBrowserEnv && window.location.href || 'http://localhost'; | 44 | const origin = (hasBrowserEnv && window.location.href) || 'http://localhost'; |
| 44 | 45 | ||
| 45 | export { | 46 | export { |
| 46 | hasBrowserEnv, | 47 | hasBrowserEnv, |
| 47 | hasStandardBrowserWebWorkerEnv, | 48 | hasStandardBrowserWebWorkerEnv, |
| 48 | hasStandardBrowserEnv, | 49 | hasStandardBrowserEnv, |
| 49 | _navigator as navigator, | 50 | _navigator as navigator, |
| 50 | origin | ||
| 51 | } | 51 | origin, |
| 52 | }; | ||
@@ -1,6 +1,6 @@ | |||
| 1 | 'use strict'; | 1 | 'use strict'; |
| 2 | 2 | ||
| 3 | import {VERSION} from '../env/data.js'; | 3 | import { VERSION } from '../env/data.js'; |
| 4 | import AxiosError from '../core/AxiosError.js'; | 4 | import AxiosError from '../core/AxiosError.js'; |
| 5 | 5 | ||
| 6 | const validators = {}; | 6 | const validators = {}; |
@@ -25,7 +25,15 @@ | |||
| 25 | */ | 25 | */ |
| 26 | validators.transitional = function transitional(validator, version, message) { | 26 | validators.transitional = function transitional(validator, version, message) { |
| 27 | function formatMessage(opt, desc) { | 27 | function formatMessage(opt, desc) { |
| 28 | return '[Axios v' + VERSION + '] Transitional option \'' + opt + '\'' + desc + (message ? '. ' + message : ''); | 28 | return ( |
| 29 | '[Axios v' + | ||
| 30 | VERSION + | ||
| 31 | "] Transitional option '" + | ||
| 32 | opt + | ||
| 33 | "'" + | ||
| 34 | desc + | ||
| 35 | (message ? '. ' + message : '') | ||
| 36 | ); | ||
| 29 | } | 37 | } |
| 30 | 38 | ||
| 31 | // eslint-disable-next-line func-names | 39 | // eslint-disable-next-line func-names |
@@ -57,7 +65,7 @@ | |||
| 57 | // eslint-disable-next-line no-console | 65 | // eslint-disable-next-line no-console |
| 58 | console.warn(`${opt} is likely a misspelling of ${correctSpelling}`); | 66 | console.warn(`${opt} is likely a misspelling of ${correctSpelling}`); |
| 59 | return true; | 67 | return true; |
| 60 | } | 68 | }; |
| 61 | }; | 69 | }; |
| 62 | 70 | ||
| 63 | /** | 71 | /** |
@@ -83,7 +91,10 @@ | |||
| 83 | const value = options[opt]; | 91 | const value = options[opt]; |
| 84 | const result = value === undefined || validator(value, opt, options); | 92 | const result = value === undefined || validator(value, opt, options); |
| 85 | if (result !== true) { | 93 | if (result !== true) { |
| 86 | throw new AxiosError('option ' + opt + ' must be ' + result, AxiosError.ERR_BAD_OPTION_VALUE); | 94 | throw new AxiosError( |
| 95 | 'option ' + opt + ' must be ' + result, | ||
| 96 | AxiosError.ERR_BAD_OPTION_VALUE | ||
| 97 | ); | ||
| 87 | } | 98 | } |
| 88 | continue; | 99 | continue; |
| 89 | } | 100 | } |
@@ -95,5 +106,5 @@ | |||
| 95 | 106 | ||
| 96 | export default { | 107 | export default { |
| 97 | assertOptions, | 108 | assertOptions, |
| 98 | validators | 109 | validators, |
| 99 | }; | 110 | }; |
@@ -1,6 +1,6 @@ | |||
| 1 | "use strict"; | 1 | 'use strict'; |
| 2 | 2 | ||
| 3 | import stream from "stream"; | 3 | import stream from 'stream'; |
| 4 | 4 | ||
| 5 | class ZlibHeaderTransformStream extends stream.Transform { | 5 | class ZlibHeaderTransformStream extends stream.Transform { |
| 6 | __transform(chunk, encoding, callback) { | 6 | __transform(chunk, encoding, callback) { |
@@ -13,10 +13,11 @@ | |||
| 13 | this._transform = this.__transform; | 13 | this._transform = this.__transform; |
| 14 | 14 | ||
| 15 | // Add Default Compression headers if no zlib headers are present | 15 | // Add Default Compression headers if no zlib headers are present |
| 16 | if (chunk[0] !== 120) { // Hex: 78 | 16 | if (chunk[0] !== 120) { |
| 17 | // Hex: 78 | ||
| 17 | const header = Buffer.alloc(2); | 18 | const header = Buffer.alloc(2); |
| 18 | header[0] = 120; // Hex: 78 | 19 | header[0] = 120; // Hex: 78 |
| 19 | header[1] = 156; // Hex: 9C | 20 | header[1] = 156; // Hex: 9C |
| 20 | this.push(header, encoding); | 21 | this.push(header, encoding); |
| 21 | } | 22 | } |
| 22 | } | 23 | } |
@@ -1,8 +1,8 @@ | |||
| 1 | { | 1 | { |
| 2 | "name": "axios", | 2 | "name": "axios", |
| 3 | "version": "1.13.5", | 3 | "version": "1.13.6", |
| 4 | "description": "Promise based HTTP client for the browser and node.js", | 4 | "description": "Promise based HTTP client for the browser and node.js", |
| 5 | "main": "./dist/node/axios.cjs", | 5 | "main": "./index.js", |
| 6 | "module": "./index.js", | 6 | "module": "./index.js", |
| 7 | "exports": { | 7 | "exports": { |
| 8 | ".": { | 8 | ".": { |
@@ -63,7 +63,6 @@ | |||
| 63 | "prepublishOnly": "npm run test:build:version", | 63 | "prepublishOnly": "npm run test:build:version", |
| 64 | "build": "gulp clear && cross-env NODE_ENV=production rollup -c -m", | 64 | "build": "gulp clear && cross-env NODE_ENV=production rollup -c -m", |
| 65 | "examples": "node ./examples/server.js", | 65 | "examples": "node ./examples/server.js", |
| 66 | "coveralls": "cat coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js", | ||
| 67 | "fix": "eslint --fix lib/**/*.js", | 66 | "fix": "eslint --fix lib/**/*.js", |
| 68 | "prepare": "husky install && npm run prepare:hooks", | 67 | "prepare": "husky install && npm run prepare:hooks", |
| 69 | "prepare:hooks": "npx husky set .husky/commit-msg \"npx commitlint --edit $1\"" | 68 | "prepare:hooks": "npx husky set .husky/commit-msg \"npx commitlint --edit $1\"" |
@@ -96,7 +95,7 @@ | |||
| 96 | "@commitlint/cli": "^20.3.1", | 95 | "@commitlint/cli": "^20.3.1", |
| 97 | "@commitlint/config-conventional": "^20.3.1", | 96 | "@commitlint/config-conventional": "^20.3.1", |
| 98 | "@rollup/plugin-alias": "^5.1.1", | 97 | "@rollup/plugin-alias": "^5.1.1", |
| 99 | "@rollup/plugin-babel": "^5.3.1", | 98 | "@rollup/plugin-babel": "^6.1.0", |
| 100 | "@rollup/plugin-commonjs": "^15.1.0", | 99 | "@rollup/plugin-commonjs": "^15.1.0", |
| 101 | "@rollup/plugin-json": "^4.1.0", | 100 | "@rollup/plugin-json": "^4.1.0", |
| 102 | "@rollup/plugin-multi-entry": "^4.1.0", | 101 | "@rollup/plugin-multi-entry": "^4.1.0", |
@@ -131,11 +130,13 @@ | |||
| 131 | "karma-sauce-launcher": "^4.3.6", | 130 | "karma-sauce-launcher": "^4.3.6", |
| 132 | "karma-sinon": "^1.0.5", | 131 | "karma-sinon": "^1.0.5", |
| 133 | "karma-sourcemap-loader": "^0.4.0", | 132 | "karma-sourcemap-loader": "^0.4.0", |
| 133 | "lint-staged": "^15.2.10", | ||
| 134 | "memoizee": "^0.4.17", | 134 | "memoizee": "^0.4.17", |
| 135 | "minimist": "^1.2.8", | 135 | "minimist": "^1.2.8", |
| 136 | "mocha": "^10.8.2", | 136 | "mocha": "^10.8.2", |
| 137 | "multer": "^1.4.4", | 137 | "multer": "^1.4.4", |
| 138 | "pacote": "^20.0.0", | 138 | "pacote": "^20.0.0", |
| 139 | "prettier": "^3.8.1", | ||
| 139 | "pretty-bytes": "^6.1.1", | 140 | "pretty-bytes": "^6.1.1", |
| 140 | "rollup": "^2.79.2", | 141 | "rollup": "^2.79.2", |
| 141 | "rollup-plugin-auto-external": "^2.0.0", | 142 | "rollup-plugin-auto-external": "^2.0.0", |
@@ -149,11 +150,13 @@ | |||
| 149 | "typescript": "^4.9.5" | 150 | "typescript": "^4.9.5" |
| 150 | }, | 151 | }, |
| 151 | "browser": { | 152 | "browser": { |
| 153 | "./dist/node/axios.cjs": "./dist/browser/axios.cjs", | ||
| 152 | "./lib/adapters/http.js": "./lib/helpers/null.js", | 154 | "./lib/adapters/http.js": "./lib/helpers/null.js", |
| 153 | "./lib/platform/node/index.js": "./lib/platform/browser/index.js", | 155 | "./lib/platform/node/index.js": "./lib/platform/browser/index.js", |
| 154 | "./lib/platform/node/classes/FormData.js": "./lib/helpers/null.js" | 156 | "./lib/platform/node/classes/FormData.js": "./lib/helpers/null.js" |
| 155 | }, | 157 | }, |
| 156 | "react-native": { | 158 | "react-native": { |
| 159 | "./dist/node/axios.cjs": "./dist/browser/axios.cjs", | ||
| 157 | "./lib/adapters/http.js": "./lib/helpers/null.js", | 160 | "./lib/adapters/http.js": "./lib/helpers/null.js", |
| 158 | "./lib/platform/node/index.js": "./lib/platform/browser/index.js", | 161 | "./lib/platform/node/index.js": "./lib/platform/browser/index.js", |
| 159 | "./lib/platform/node/classes/FormData.js": "./lib/helpers/null.js" | 162 | "./lib/platform/node/classes/FormData.js": "./lib/helpers/null.js" |
@@ -200,6 +203,9 @@ | |||
| 200 | "@commitlint/config-conventional" | 203 | "@commitlint/config-conventional" |
| 201 | ] | 204 | ] |
| 202 | }, | 205 | }, |
| 206 | "lint-staged": { | ||
| 207 | "*.{js,cjs,mjs,ts,json,md,yml,yaml}": "prettier --write" | ||
| 208 | }, | ||
| 203 | "c8": { | 209 | "c8": { |
| 204 | "all": true, | 210 | "all": true, |
| 205 | "include": [ | 211 | "include": [ |
@@ -12,19 +12,18 @@ | |||
| 12 | // - config has been merged with defaults | 12 | // - config has been merged with defaults |
| 13 | // - request transformers have already run | 13 | // - request transformers have already run |
| 14 | // - request interceptors have already run | 14 | // - request interceptors have already run |
| 15 | 15 | ||
| 16 | // Make the request using config provided | 16 | // Make the request using config provided |
| 17 | // Upon response settle the Promise | 17 | // Upon response settle the Promise |
| 18 | 18 | ||
| 19 | return new Promise(function(resolve, reject) { | ||
| 20 | 19 | return new Promise(function (resolve, reject) { | |
| 21 | var response = { | 20 | var response = { |
| 22 | data: responseData, | 21 | data: responseData, |
| 23 | status: request.status, | 22 | status: request.status, |
| 24 | statusText: request.statusText, | 23 | statusText: request.statusText, |
| 25 | headers: responseHeaders, | 24 | headers: responseHeaders, |
| 26 | config: config, | 25 | config: config, |
| 27 | request: request | 26 | request: request, |
| 28 | }; | 27 | }; |
| 29 | 28 | ||
| 30 | settle(resolve, reject, response); | 29 | settle(resolve, reject, response); |
@@ -33,5 +32,5 @@ | |||
| 33 | // - response transformers will run | 32 | // - response transformers will run |
| 34 | // - response interceptors will run | 33 | // - response interceptors will run |
| 35 | }); | 34 | }); |
| 36 | } | 35 | }; |
| 37 | ``` | 36 | ``` |