...**/!(*.map|*.min.js)Size
Gzip
Dependencies
Publish
Install
Publish
Install
@@ -1,19 +1,7 @@ | |||
| 1 | Copyright (c) 2014-present Matt Zabriskie | 1 | # Copyright (c) 2014-present Matt Zabriskie & Collaborators |
| 2 | 2 | ||
| 3 | Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| 4 | of this software and associated documentation files (the "Software"), to deal | ||
| 5 | in the Software without restriction, including without limitation the rights | ||
| 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| 7 | copies of the Software, and to permit persons to whom the Software is | ||
| 8 | furnished to do so, subject to the following conditions: | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: |
| 9 | 4 | ||
| 10 | The above copyright notice and this permission notice shall be included in | ||
| 11 | all copies or substantial portions of the Software. | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. |
| 12 | 6 | ||
| 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| 19 | THE SOFTWARE. | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
@@ -1,26 +1,36 @@ | |||
| 1 | 'use strict'; | 1 | 'use strict'; |
| 2 | 2 | ||
| 3 | var utils = require('./utils'); | ||
| 4 | var bind = require('./helpers/bind'); | ||
| 5 | var Axios = require('./core/Axios'); | ||
| 6 | var mergeConfig = require('./core/mergeConfig'); | ||
| 7 | var defaults = require('./defaults'); | ||
| 8 | var formDataToJSON = require('./helpers/formDataToJSON'); | 3 | import utils from './utils.js'; |
| 4 | import bind from './helpers/bind.js'; | ||
| 5 | import Axios from './core/Axios.js'; | ||
| 6 | import mergeConfig from './core/mergeConfig.js'; | ||
| 7 | import defaults from './defaults/index.js'; | ||
| 8 | import formDataToJSON from './helpers/formDataToJSON.js'; | ||
| 9 | import CanceledError from './cancel/CanceledError.js'; | ||
| 10 | import CancelToken from'./cancel/CancelToken.js'; | ||
| 11 | import isCancel from'./cancel/isCancel.js'; | ||
| 12 | import {VERSION} from './env/data.js'; | ||
| 13 | import toFormData from './helpers/toFormData.js'; | ||
| 14 | import AxiosError from './core/AxiosError.js'; | ||
| 15 | import spread from './helpers/spread.js'; | ||
| 16 | import isAxiosError from './helpers/isAxiosError.js'; | ||
| 17 | |||
| 9 | /** | 18 | /** |
| 10 | * Create an instance of Axios | 19 | * Create an instance of Axios |
| 11 | * | 20 | * |
| 12 | * @param {Object} defaultConfig The default config for the instance | 21 | * @param {Object} defaultConfig The default config for the instance |
| 13 | * @return {Axios} A new instance of Axios | 22 | * |
| 23 | * @returns {Axios} A new instance of Axios | ||
| 14 | */ | 24 | */ |
| 15 | function createInstance(defaultConfig) { | 25 | function createInstance(defaultConfig) { |
| 16 | var context = new Axios(defaultConfig); | ||
| 17 | var instance = bind(Axios.prototype.request, context); | 26 | const context = new Axios(defaultConfig); |
| 27 | const instance = bind(Axios.prototype.request, context); | ||
| 18 | 28 | ||
| 19 | // Copy axios.prototype to instance | 29 | // Copy axios.prototype to instance |
| 20 | utils.extend(instance, Axios.prototype, context); | 30 | utils.extend(instance, Axios.prototype, context, {allOwnKeys: true}); |
| 21 | 31 | ||
| 22 | // Copy context to instance | 32 | // Copy context to instance |
| 23 | utils.extend(instance, context); | 33 | utils.extend(instance, context, null, {allOwnKeys: true}); |
| 24 | 34 | ||
| 25 | // Factory for creating new instances | 35 | // Factory for creating new instances |
| 26 | instance.create = function create(instanceConfig) { | 36 | instance.create = function create(instanceConfig) { |
@@ -31,20 +41,20 @@ | |||
| 31 | } | 41 | } |
| 32 | 42 | ||
| 33 | // Create the default instance to be exported | 43 | // Create the default instance to be exported |
| 34 | var axios = createInstance(defaults); | 44 | const axios = createInstance(defaults); |
| 35 | 45 | ||
| 36 | // Expose Axios class to allow class inheritance | 46 | // Expose Axios class to allow class inheritance |
| 37 | axios.Axios = Axios; | 47 | axios.Axios = Axios; |
| 38 | 48 | ||
| 39 | // Expose Cancel & CancelToken | 49 | // Expose Cancel & CancelToken |
| 40 | axios.CanceledError = require('./cancel/CanceledError'); | ||
| 41 | axios.CancelToken = require('./cancel/CancelToken'); | ||
| 42 | axios.isCancel = require('./cancel/isCancel'); | ||
| 43 | axios.VERSION = require('./env/data').version; | ||
| 44 | axios.toFormData = require('./helpers/toFormData'); | 50 | axios.CanceledError = CanceledError; |
| 51 | axios.CancelToken = CancelToken; | ||
| 52 | axios.isCancel = isCancel; | ||
| 53 | axios.VERSION = VERSION; | ||
| 54 | axios.toFormData = toFormData; | ||
| 45 | 55 | ||
| 46 | // Expose AxiosError class | 56 | // Expose AxiosError class |
| 47 | axios.AxiosError = require('../lib/core/AxiosError'); | 57 | axios.AxiosError = AxiosError; |
| 48 | 58 | ||
| 49 | // alias for CanceledError for backward compatibility | 59 | // alias for CanceledError for backward compatibility |
| 50 | axios.Cancel = axios.CanceledError; | 60 | axios.Cancel = axios.CanceledError; |
@@ -53,16 +63,14 @@ | |||
| 53 | axios.all = function all(promises) { | 63 | axios.all = function all(promises) { |
| 54 | return Promise.all(promises); | 64 | return Promise.all(promises); |
| 55 | }; | 65 | }; |
| 56 | axios.spread = require('./helpers/spread'); | ||
| 57 | 66 | ||
| 67 | axios.spread = spread; | ||
| 68 | |||
| 58 | // Expose isAxiosError | 69 | // Expose isAxiosError |
| 59 | axios.isAxiosError = require('./helpers/isAxiosError'); | 70 | axios.isAxiosError = isAxiosError; |
| 60 | 71 | ||
| 61 | axios.formToJSON = function(thing) { | 72 | axios.formToJSON = thing => { |
| 62 | return formDataToJSON(utils.isHTMLForm(thing) ? new FormData(thing) : thing); | 73 | return formDataToJSON(utils.isHTMLForm(thing) ? new FormData(thing) : thing); |
| 63 | }; | 74 | }; |
| 64 | 75 | ||
| 65 | module.exports = axios; | ||
| 66 | |||
| 67 | // Allow use of default import syntax in TypeScript | ||
| 68 | module.exports.default = axios; | 76 | export default axios; |
@@ -1,6 +1,6 @@ | |||
| 1 | 'use strict'; | 1 | 'use strict'; |
| 2 | 2 | ||
| 3 | var utils = require('../utils'); | 3 | import utils from '../utils.js'; |
| 4 | 4 | ||
| 5 | /** | 5 | /** |
| 6 | * Create an Error with the specified message, config, error code, request and response. | 6 | * Create an Error with the specified message, config, error code, request and response. |
@@ -10,6 +10,7 @@ | |||
| 10 | * @param {Object} [config] The config. | 10 | * @param {Object} [config] The config. |
| 11 | * @param {Object} [request] The request. | 11 | * @param {Object} [request] The request. |
| 12 | * @param {Object} [response] The response. | 12 | * @param {Object} [response] The response. |
| 13 | * | ||
| 13 | * @returns {Error} The created error. | 14 | * @returns {Error} The created error. |
| 14 | */ | 15 | */ |
| 15 | function AxiosError(message, code, config, request, response) { | 16 | function AxiosError(message, code, config, request, response) { |
@@ -51,8 +52,8 @@ | |||
| 51 | } | 52 | } |
| 52 | }); | 53 | }); |
| 53 | 54 | ||
| 54 | var prototype = AxiosError.prototype; | ||
| 55 | var descriptors = {}; | 55 | const prototype = AxiosError.prototype; |
| 56 | const descriptors = {}; | ||
| 56 | 57 | ||
| 57 | [ | 58 | [ |
| 58 | 'ERR_BAD_OPTION_VALUE', | 59 | 'ERR_BAD_OPTION_VALUE', |
@@ -68,7 +69,7 @@ | |||
| 68 | 'ERR_NOT_SUPPORT', | 69 | 'ERR_NOT_SUPPORT', |
| 69 | 'ERR_INVALID_URL' | 70 | 'ERR_INVALID_URL' |
| 70 | // eslint-disable-next-line func-names | 71 | // eslint-disable-next-line func-names |
| 71 | ].forEach(function(code) { | 72 | ].forEach(code => { |
| 72 | descriptors[code] = {value: code}; | 73 | descriptors[code] = {value: code}; |
| 73 | }); | 74 | }); |
| 74 | 75 | ||
@@ -76,11 +77,13 @@ | |||
| 76 | Object.defineProperty(prototype, 'isAxiosError', {value: true}); | 77 | Object.defineProperty(prototype, 'isAxiosError', {value: true}); |
| 77 | 78 | ||
| 78 | // eslint-disable-next-line func-names | 79 | // eslint-disable-next-line func-names |
| 79 | AxiosError.from = function(error, code, config, request, response, customProps) { | ||
| 80 | var axiosError = Object.create(prototype); | 80 | AxiosError.from = (error, code, config, request, response, customProps) => { |
| 81 | const axiosError = Object.create(prototype); | ||
| 81 | 82 | ||
| 82 | utils.toFlatObject(error, axiosError, function filter(obj) { | 83 | utils.toFlatObject(error, axiosError, function filter(obj) { |
| 83 | return obj !== Error.prototype; | 84 | return obj !== Error.prototype; |
| 85 | }, prop => { | ||
| 86 | return prop !== 'isAxiosError'; | ||
| 84 | }); | 87 | }); |
| 85 | 88 | ||
| 86 | AxiosError.call(axiosError, error.message, code, config, request, response); | 89 | AxiosError.call(axiosError, error.message, code, config, request, response); |
@@ -94,4 +97,4 @@ | |||
| 94 | return axiosError; | 97 | return axiosError; |
| 95 | }; | 98 | }; |
| 96 | 99 | ||
| 97 | module.exports = AxiosError; | 100 | export default AxiosError; |
@@ -1,9 +1,17 @@ | |||
| 1 | 'use strict'; | 1 | 'use strict'; |
| 2 | 2 | ||
| 3 | var toFormData = require('./toFormData'); | 3 | import toFormData from './toFormData.js'; |
| 4 | 4 | ||
| 5 | /** | ||
| 6 | * It encodes a string by replacing all characters that are not in the unreserved set with | ||
| 7 | * their percent-encoded equivalents | ||
| 8 | * | ||
| 9 | * @param {string} str - The string to encode. | ||
| 10 | * | ||
| 11 | * @returns {string} The encoded string. | ||
| 12 | */ | ||
| 5 | function encode(str) { | 13 | function encode(str) { |
| 6 | var charMap = { | 14 | const charMap = { |
| 7 | '!': '%21', | 15 | '!': '%21', |
| 8 | "'": '%27', | 16 | "'": '%27', |
| 9 | '(': '%28', | 17 | '(': '%28', |
@@ -12,25 +20,33 @@ | |||
| 12 | '%20': '+', | 20 | '%20': '+', |
| 13 | '%00': '\x00' | 21 | '%00': '\x00' |
| 14 | }; | 22 | }; |
| 15 | return encodeURIComponent(str).replace(/[!'\(\)~]|%20|%00/g, function replacer(match) { | 23 | return encodeURIComponent(str).replace(/[!'()~]|%20|%00/g, function replacer(match) { |
| 16 | return charMap[match]; | 24 | return charMap[match]; |
| 17 | }); | 25 | }); |
| 18 | } | 26 | } |
| 19 | 27 | ||
| 28 | /** | ||
| 29 | * It takes a params object and converts it to a FormData object | ||
| 30 | * | ||
| 31 | * @param {Object<string, any>} params - The parameters to be converted to a FormData object. | ||
| 32 | * @param {Object<string, any>} options - The options object passed to the Axios constructor. | ||
| 33 | * | ||
| 34 | * @returns {void} | ||
| 35 | */ | ||
| 20 | function AxiosURLSearchParams(params, options) { | 36 | function AxiosURLSearchParams(params, options) { |
| 21 | this._pairs = []; | 37 | this._pairs = []; |
| 22 | 38 | ||
| 23 | params && toFormData(params, this, options); | 39 | params && toFormData(params, this, options); |
| 24 | } | 40 | } |
| 25 | 41 | ||
| 26 | var prototype = AxiosURLSearchParams.prototype; | 42 | const prototype = AxiosURLSearchParams.prototype; |
| 27 | 43 | ||
| 28 | prototype.append = function append(name, value) { | 44 | prototype.append = function append(name, value) { |
| 29 | this._pairs.push([name, value]); | 45 | this._pairs.push([name, value]); |
| 30 | }; | 46 | }; |
| 31 | 47 | ||
| 32 | prototype.toString = function toString(encoder) { | 48 | prototype.toString = function toString(encoder) { |
| 33 | var _encode = encoder ? function(value) { | 49 | const _encode = encoder ? function(value) { |
| 34 | return encoder.call(this, value, encode); | 50 | return encoder.call(this, value, encode); |
| 35 | } : encode; | 51 | } : encode; |
| 36 | 52 | ||
@@ -39,4 +55,4 @@ | |||
| 39 | }, '').join('&'); | 55 | }, '').join('&'); |
| 40 | }; | 56 | }; |
| 41 | 57 | ||
| 42 | module.exports = AxiosURLSearchParams; | 58 | export default AxiosURLSearchParams; |
@@ -1,7 +1,7 @@ | |||
| 1 | 'use strict'; | 1 | 'use strict'; |
| 2 | 2 | ||
| 3 | var isAbsoluteURL = require('../helpers/isAbsoluteURL'); | ||
| 4 | var combineURLs = require('../helpers/combineURLs'); | 3 | import isAbsoluteURL from '../helpers/isAbsoluteURL.js'; |
| 4 | import combineURLs from '../helpers/combineURLs.js'; | ||
| 5 | 5 | ||
| 6 | /** | 6 | /** |
| 7 | * Creates a new URL by combining the baseURL with the requestedURL, | 7 | * Creates a new URL by combining the baseURL with the requestedURL, |
@@ -10,14 +10,12 @@ | |||
| 10 | * | 10 | * |
| 11 | * @param {string} baseURL The base URL | 11 | * @param {string} baseURL The base URL |
| 12 | * @param {string} requestedURL Absolute or relative URL to combine | 12 | * @param {string} requestedURL Absolute or relative URL to combine |
| 13 | * @param {boolean} allowAbsoluteUrls Set to true to allow absolute URLs | ||
| 14 | * | 13 | * |
| 15 | * @returns {string} The combined full path | 14 | * @returns {string} The combined full path |
| 16 | */ | 15 | */ |
| 17 | module.exports = function buildFullPath(baseURL, requestedURL, allowAbsoluteUrls) { | ||
| 18 | var isRelativeURL = !isAbsoluteURL(requestedURL); | ||
| 19 | if (baseURL && (isRelativeURL || allowAbsoluteUrls === false)) { | 16 | export default function buildFullPath(baseURL, requestedURL) { |
| 17 | if (baseURL && !isAbsoluteURL(requestedURL)) { | ||
| 20 | return combineURLs(baseURL, requestedURL); | 18 | return combineURLs(baseURL, requestedURL); |
| 21 | } | 19 | } |
| 22 | return requestedURL; | 20 | return requestedURL; |
| 23 | }; | 21 | } |
@@ -1,8 +1,16 @@ | |||
| 1 | 'use strict'; | 1 | 'use strict'; |
| 2 | 2 | ||
| 3 | var utils = require('../utils'); | ||
| 4 | var AxiosURLSearchParams = require('../helpers/AxiosURLSearchParams'); | 3 | import utils from '../utils.js'; |
| 4 | import AxiosURLSearchParams from '../helpers/AxiosURLSearchParams.js'; | ||
| 5 | 5 | ||
| 6 | /** | ||
| 7 | * It replaces all instances of the characters `:`, `$`, `,`, `+`, `[`, and `]` with their | ||
| 8 | * URI encoded counterparts | ||
| 9 | * | ||
| 10 | * @param {string} val The value to be encoded. | ||
| 11 | * | ||
| 12 | * @returns {string} The encoded value. | ||
| 13 | */ | ||
| 6 | function encode(val) { | 14 | function encode(val) { |
| 7 | return encodeURIComponent(val). | 15 | return encodeURIComponent(val). |
| 8 | replace(/%3A/gi, ':'). | 16 | replace(/%3A/gi, ':'). |
@@ -19,37 +27,30 @@ | |||
| 19 | * @param {string} url The base of the url (e.g., http://www.google.com) | 27 | * @param {string} url The base of the url (e.g., http://www.google.com) |
| 20 | * @param {object} [params] The params to be appended | 28 | * @param {object} [params] The params to be appended |
| 21 | * @param {?object} options | 29 | * @param {?object} options |
| 30 | * | ||
| 22 | * @returns {string} The formatted url | 31 | * @returns {string} The formatted url |
| 23 | */ | 32 | */ |
| 24 | module.exports = function buildURL(url, params, options) { | 33 | export default function buildURL(url, params, options) { |
| 25 | /*eslint no-param-reassign:0*/ | 34 | /*eslint no-param-reassign:0*/ |
| 26 | if (!params) { | 35 | if (!params) { |
| 27 | return url; | 36 | return url; |
| 28 | } | 37 | } |
| 29 | 38 | ||
| 30 | var hashmarkIndex = url.indexOf('#'); | 39 | const hashmarkIndex = url.indexOf('#'); |
| 31 | 40 | ||
| 32 | if (hashmarkIndex !== -1) { | 41 | if (hashmarkIndex !== -1) { |
| 33 | url = url.slice(0, hashmarkIndex); | 42 | url = url.slice(0, hashmarkIndex); |
| 34 | } | 43 | } |
| 35 | 44 | ||
| 36 | var _encode = options && options.encode || encode; | 45 | const _encode = options && options.encode || encode; |
| 37 | 46 | ||
| 38 | var serializeFn = options && options.serialize; | 47 | const serializerParams = utils.isURLSearchParams(params) ? |
| 48 | params.toString() : | ||
| 49 | new AxiosURLSearchParams(params, options).toString(_encode); | ||
| 39 | 50 | ||
| 40 | var serializedParams; | ||
| 41 | |||
| 42 | if (serializeFn) { | ||
| 43 | serializedParams = serializeFn(params, options); | ||
| 44 | } else { | ||
| 45 | serializedParams = utils.isURLSearchParams(params) ? | ||
| 46 | params.toString() : | ||
| 47 | new AxiosURLSearchParams(params, options).toString(_encode); | 51 | if (serializerParams) { |
| 52 | url += (url.indexOf('?') === -1 ? '?' : '&') + serializerParams; | ||
| 48 | } | 53 | } |
| 49 | 54 | ||
| 50 | if (serializedParams) { | ||
| 51 | url += (url.indexOf('?') === -1 ? '?' : '&') + serializedParams; | ||
| 52 | } | ||
| 53 | |||
| 54 | return url; | 55 | return url; |
| 55 | }; | 56 | } |
@@ -1,15 +1,16 @@ | |||
| 1 | 'use strict'; | 1 | 'use strict'; |
| 2 | 2 | ||
| 3 | var AxiosError = require('../core/AxiosError'); | ||
| 4 | var utils = require('../utils'); | 3 | import AxiosError from '../core/AxiosError.js'; |
| 4 | import utils from '../utils.js'; | ||
| 5 | 5 | ||
| 6 | /** | 6 | /** |
| 7 | * A `CanceledError` is an object that is thrown when an operation is canceled. | 7 | * A `CanceledError` is an object that is thrown when an operation is canceled. |
| 8 | * | 8 | * |
| 9 | * @class | ||
| 10 | * @param {string=} message The message. | 9 | * @param {string=} message The message. |
| 11 | * @param {Object=} config The config. | 10 | * @param {Object=} config The config. |
| 12 | * @param {Object=} request The request. | 11 | * @param {Object=} request The request. |
| 12 | * | ||
| 13 | * @returns {CanceledError} The created error. | ||
| 13 | */ | 14 | */ |
| 14 | function CanceledError(message, config, request) { | 15 | function CanceledError(message, config, request) { |
| 15 | // eslint-disable-next-line no-eq-null,eqeqeq | 16 | // eslint-disable-next-line no-eq-null,eqeqeq |
@@ -21,4 +22,4 @@ | |||
| 21 | __CANCEL__: true | 22 | __CANCEL__: true |
| 22 | }); | 23 | }); |
| 23 | 24 | ||
| 24 | module.exports = CanceledError; | 25 | export default CanceledError; |
@@ -5,10 +5,11 @@ | |||
| 5 | * | 5 | * |
| 6 | * @param {string} baseURL The base URL | 6 | * @param {string} baseURL The base URL |
| 7 | * @param {string} relativeURL The relative URL | 7 | * @param {string} relativeURL The relative URL |
| 8 | * | ||
| 8 | * @returns {string} The combined URL | 9 | * @returns {string} The combined URL |
| 9 | */ | 10 | */ |
| 10 | module.exports = function combineURLs(baseURL, relativeURL) { | 11 | export default function combineURLs(baseURL, relativeURL) { |
| 11 | return relativeURL | 12 | return relativeURL |
| 12 | ? baseURL.replace(/\/?\/$/, '') + '/' + relativeURL.replace(/^\/+/, '') | 13 | ? baseURL.replace(/\/+$/, '') + '/' + relativeURL.replace(/^\/+/, '') |
| 13 | : baseURL; | 14 | : baseURL; |
| 14 | }; | 15 | } |
@@ -1,53 +1,52 @@ | |||
| 1 | 'use strict'; | 1 | 'use strict'; |
| 2 | 2 | ||
| 3 | var utils = require('./../utils'); | 3 | import utils from './../utils.js'; |
| 4 | import platform from '../platform/index.js'; | ||
| 4 | 5 | ||
| 5 | module.exports = ( | ||
| 6 | utils.isStandardBrowserEnv() ? | 6 | export default platform.isStandardBrowserEnv ? |
| 7 | 7 | ||
| 8 | // Standard browser envs support document.cookie | ||
| 9 | (function standardBrowserEnv() { | ||
| 10 | return { | ||
| 11 | write: function write(name, value, expires, path, domain, secure) { | ||
| 12 | var cookie = []; | ||
| 13 | cookie.push(name + '=' + encodeURIComponent(value)); | 8 | // Standard browser envs support document.cookie |
| 9 | (function standardBrowserEnv() { | ||
| 10 | return { | ||
| 11 | write: function write(name, value, expires, path, domain, secure) { | ||
| 12 | const cookie = []; | ||
| 13 | cookie.push(name + '=' + encodeURIComponent(value)); | ||
| 14 | 14 | ||
| 15 | if (utils.isNumber(expires)) { | ||
| 16 | cookie.push('expires=' + new Date(expires).toGMTString()); | ||
| 17 | } | 15 | if (utils.isNumber(expires)) { |
| 16 | cookie.push('expires=' + new Date(expires).toGMTString()); | ||
| 17 | } | ||
| 18 | 18 | ||
| 19 | if (utils.isString(path)) { | ||
| 20 | cookie.push('path=' + path); | ||
| 21 | } | 19 | if (utils.isString(path)) { |
| 20 | cookie.push('path=' + path); | ||
| 21 | } | ||
| 22 | 22 | ||
| 23 | if (utils.isString(domain)) { | ||
| 24 | cookie.push('domain=' + domain); | ||
| 25 | } | 23 | if (utils.isString(domain)) { |
| 24 | cookie.push('domain=' + domain); | ||
| 25 | } | ||
| 26 | 26 | ||
| 27 | if (secure === true) { | ||
| 28 | cookie.push('secure'); | ||
| 29 | } | 27 | if (secure === true) { |
| 28 | cookie.push('secure'); | ||
| 29 | } | ||
| 30 | 30 | ||
| 31 | document.cookie = cookie.join('; '); | ||
| 32 | }, | 31 | document.cookie = cookie.join('; '); |
| 32 | }, | ||
| 33 | 33 | ||
| 34 | read: function read(name) { | ||
| 35 | var match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)')); | ||
| 36 | return (match ? decodeURIComponent(match[3]) : null); | ||
| 37 | }, | 34 | read: function read(name) { |
| 35 | const match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)')); | ||
| 36 | return (match ? decodeURIComponent(match[3]) : null); | ||
| 37 | }, | ||
| 38 | 38 | ||
| 39 | remove: function remove(name) { | ||
| 40 | this.write(name, '', Date.now() - 86400000); | ||
| 41 | } | ||
| 42 | }; | ||
| 43 | })() : | 39 | remove: function remove(name) { |
| 40 | this.write(name, '', Date.now() - 86400000); | ||
| 41 | } | ||
| 42 | }; | ||
| 43 | })() : | ||
| 44 | 44 | ||
| 45 | // Non standard browser env (web workers, react-native) lack needed support. | ||
| 46 | (function nonStandardBrowserEnv() { | ||
| 47 | return { | ||
| 48 | write: function write() {}, | ||
| 49 | read: function read() { return null; }, | ||
| 50 | remove: function remove() {} | ||
| 51 | }; | ||
| 52 | })() | ||
| 53 | ); | 45 | // Non standard browser env (web workers, react-native) lack needed support. |
| 46 | (function nonStandardBrowserEnv() { | ||
| 47 | return { | ||
| 48 | write: function write() {}, | ||
| 49 | read: function read() { return null; }, | ||
| 50 | remove: function remove() {} | ||
| 51 | }; | ||
| 52 | })(); | ||
@@ -9,8 +9,10 @@ | |||
| 9 | * @param {string} method The name of the deprecated method | 9 | * @param {string} method The name of the deprecated method |
| 10 | * @param {string} [instead] The alternate method to use if applicable | 10 | * @param {string} [instead] The alternate method to use if applicable |
| 11 | * @param {string} [docs] The documentation URL to get further details | 11 | * @param {string} [docs] The documentation URL to get further details |
| 12 | * | ||
| 13 | * @returns {void} | ||
| 12 | */ | 14 | */ |
| 13 | module.exports = function deprecatedMethod(method, instead, docs) { | 15 | export default function deprecatedMethod(method, instead, docs) { |
| 14 | try { | 16 | try { |
| 15 | console.warn( | 17 | console.warn( |
| 16 | 'DEPRECATED method `' + method + '`.' + | 18 | 'DEPRECATED method `' + method + '`.' + |
@@ -21,4 +23,4 @@ | |||
| 21 | console.warn('For more information about usage see ' + docs); | 23 | console.warn('For more information about usage see ' + docs); |
| 22 | } | 24 | } |
| 23 | } catch (e) { /* Ignore */ } | 25 | } catch (e) { /* Ignore */ } |
| 24 | }; | 26 | } |
@@ -1,14 +1,17 @@ | |||
| 1 | 'use strict'; | 1 | 'use strict'; |
| 2 | 2 | ||
| 3 | var utils = require('./../utils'); | ||
| 4 | var transformData = require('./transformData'); | ||
| 5 | var isCancel = require('../cancel/isCancel'); | ||
| 6 | var defaults = require('../defaults'); | ||
| 7 | var CanceledError = require('../cancel/CanceledError'); | ||
| 8 | var normalizeHeaderName = require('../helpers/normalizeHeaderName'); | 3 | import transformData from './transformData.js'; |
| 4 | import isCancel from '../cancel/isCancel.js'; | ||
| 5 | import defaults from '../defaults/index.js'; | ||
| 6 | import CanceledError from '../cancel/CanceledError.js'; | ||
| 7 | import AxiosHeaders from '../core/AxiosHeaders.js'; | ||
| 9 | 8 | ||
| 10 | /** | 9 | /** |
| 11 | * Throws a `CanceledError` if cancellation has been requested. | 10 | * Throws a `CanceledError` if cancellation has been requested. |
| 11 | * | ||
| 12 | * @param {Object} config The config that is to be used for the request | ||
| 13 | * | ||
| 14 | * @returns {void} | ||
| 12 | */ | 15 | */ |
| 13 | function throwIfCancellationRequested(config) { | 16 | function throwIfCancellationRequested(config) { |
| 14 | if (config.cancelToken) { | 17 | if (config.cancelToken) { |
@@ -24,54 +27,34 @@ | |||
| 24 | * Dispatch a request to the server using the configured adapter. | 27 | * Dispatch a request to the server using the configured adapter. |
| 25 | * | 28 | * |
| 26 | * @param {object} config The config that is to be used for the request | 29 | * @param {object} config The config that is to be used for the request |
| 30 | * | ||
| 27 | * @returns {Promise} The Promise to be fulfilled | 31 | * @returns {Promise} The Promise to be fulfilled |
| 28 | */ | 32 | */ |
| 29 | module.exports = function dispatchRequest(config) { | 33 | export default function dispatchRequest(config) { |
| 30 | throwIfCancellationRequested(config); | 34 | throwIfCancellationRequested(config); |
| 31 | 35 | ||
| 32 | // Ensure headers exist | ||
| 33 | config.headers = config.headers || {}; | 36 | config.headers = AxiosHeaders.from(config.headers); |
| 34 | 37 | ||
| 35 | // Transform request data | 38 | // Transform request data |
| 36 | config.data = transformData.call( | 39 | config.data = transformData.call( |
| 37 | config, | 40 | config, |
| 38 | config.data, | ||
| 39 | config.headers, | ||
| 40 | null, | ||
| 41 | config.transformRequest | 41 | config.transformRequest |
| 42 | ); | 42 | ); |
| 43 | 43 | ||
| 44 | normalizeHeaderName(config.headers, 'Accept'); | ||
| 45 | normalizeHeaderName(config.headers, 'Content-Type'); | 44 | const adapter = config.adapter || defaults.adapter; |
| 46 | 45 | ||
| 47 | // Flatten headers | ||
| 48 | config.headers = utils.merge( | ||
| 49 | config.headers.common || {}, | ||
| 50 | config.headers[config.method] || {}, | ||
| 51 | config.headers | ||
| 52 | ); | ||
| 53 | |||
| 54 | utils.forEach( | ||
| 55 | ['delete', 'get', 'head', 'post', 'put', 'patch', 'common'], | ||
| 56 | function cleanHeaderConfig(method) { | ||
| 57 | delete config.headers[method]; | ||
| 58 | } | ||
| 59 | ); | ||
| 60 | |||
| 61 | var adapter = config.adapter || defaults.adapter; | ||
| 62 | |||
| 63 | return adapter(config).then(function onAdapterResolution(response) { | 46 | return adapter(config).then(function onAdapterResolution(response) { |
| 64 | throwIfCancellationRequested(config); | 47 | throwIfCancellationRequested(config); |
| 65 | 48 | ||
| 66 | // Transform response data | 49 | // Transform response data |
| 67 | response.data = transformData.call( | 50 | response.data = transformData.call( |
| 68 | config, | 51 | config, |
| 69 | response.data, | ||
| 70 | response.headers, | ||
| 71 | response.status, | ||
| 72 | config.transformResponse | 52 | config.transformResponse, |
| 53 | response | ||
| 73 | ); | 54 | ); |
| 74 | 55 | ||
| 56 | response.headers = AxiosHeaders.from(response.headers); | ||
| 57 | |||
| 75 | return response; | 58 | return response; |
| 76 | }, function onAdapterRejection(reason) { | 59 | }, function onAdapterRejection(reason) { |
| 77 | if (!isCancel(reason)) { | 60 | if (!isCancel(reason)) { |
@@ -81,14 +64,13 @@ | |||
| 81 | if (reason && reason.response) { | 64 | if (reason && reason.response) { |
| 82 | reason.response.data = transformData.call( | 65 | reason.response.data = transformData.call( |
| 83 | config, | 66 | config, |
| 84 | reason.response.data, | ||
| 85 | reason.response.headers, | ||
| 86 | reason.response.status, | ||
| 87 | config.transformResponse | 67 | config.transformResponse, |
| 68 | reason.response | ||
| 88 | ); | 69 | ); |
| 70 | reason.response.headers = AxiosHeaders.from(reason.response.headers); | ||
| 89 | } | 71 | } |
| 90 | } | 72 | } |
| 91 | 73 | ||
| 92 | return Promise.reject(reason); | 74 | return Promise.reject(reason); |
| 93 | }); | 75 | }); |
| 94 | }; | 76 | } |
@@ -1,23 +1,37 @@ | |||
| 1 | 'use strict'; | 1 | 'use strict'; |
| 2 | 2 | ||
| 3 | var utils = require('../utils'); | 3 | import utils from '../utils.js'; |
| 4 | 4 | ||
| 5 | /** | ||
| 6 | * It takes a string like `foo[x][y][z]` and returns an array like `['foo', 'x', 'y', 'z'] | ||
| 7 | * | ||
| 8 | * @param {string} name - The name of the property to get. | ||
| 9 | * | ||
| 10 | * @returns An array of strings. | ||
| 11 | */ | ||
| 5 | function parsePropPath(name) { | 12 | function parsePropPath(name) { |
| 6 | // foo[x][y][z] | 13 | // foo[x][y][z] |
| 7 | // foo.x.y.z | 14 | // foo.x.y.z |
| 8 | // foo-x-y-z | 15 | // foo-x-y-z |
| 9 | // foo x y z | 16 | // foo x y z |
| 10 | return utils.matchAll(/\w+|\[(\w*)]/g, name).map(function(match) { | 17 | return utils.matchAll(/\w+|\[(\w*)]/g, name).map(match => { |
| 11 | return match[0] === '[]' ? '' : match[1] || match[0]; | 18 | return match[0] === '[]' ? '' : match[1] || match[0]; |
| 12 | }); | 19 | }); |
| 13 | } | 20 | } |
| 14 | 21 | ||
| 22 | /** | ||
| 23 | * Convert an array to an object. | ||
| 24 | * | ||
| 25 | * @param {Array<any>} arr - The array to convert to an object. | ||
| 26 | * | ||
| 27 | * @returns An object with the same keys and values as the array. | ||
| 28 | */ | ||
| 15 | function arrayToObject(arr) { | 29 | function arrayToObject(arr) { |
| 16 | var obj = {}; | ||
| 17 | var keys = Object.keys(arr); | ||
| 18 | var i; | ||
| 19 | var len = keys.length; | ||
| 20 | var key; | 30 | const obj = {}; |
| 31 | const keys = Object.keys(arr); | ||
| 32 | let i; | ||
| 33 | const len = keys.length; | ||
| 34 | let key; | ||
| 21 | for (i = 0; i < len; i++) { | 35 | for (i = 0; i < len; i++) { |
| 22 | key = keys[i]; | 36 | key = keys[i]; |
| 23 | obj[key] = arr[key]; | 37 | obj[key] = arr[key]; |
@@ -25,18 +39,22 @@ | |||
| 25 | return obj; | 39 | return obj; |
| 26 | } | 40 | } |
| 27 | 41 | ||
| 42 | /** | ||
| 43 | * It takes a FormData object and returns a JavaScript object | ||
| 44 | * | ||
| 45 | * @param {string} formData The FormData object to convert to JSON. | ||
| 46 | * | ||
| 47 | * @returns {Object<string, any> | null} The converted object. | ||
| 48 | */ | ||
| 28 | function formDataToJSON(formData) { | 49 | function formDataToJSON(formData) { |
| 29 | function buildPath(path, value, target, index) { | 50 | function buildPath(path, value, target, index) { |
| 30 | var name = path[index++]; | ||
| 31 | |||
| 32 | if (name === '__proto__') return true; | ||
| 33 | |||
| 34 | var isNumericKey = Number.isFinite(+name); | ||
| 35 | var isLast = index >= path.length; | 51 | let name = path[index++]; |
| 52 | const isNumericKey = Number.isFinite(+name); | ||
| 53 | const isLast = index >= path.length; | ||
| 36 | name = !name && utils.isArray(target) ? target.length : name; | 54 | name = !name && utils.isArray(target) ? target.length : name; |
| 37 | 55 | ||
| 38 | if (isLast) { | 56 | if (isLast) { |
| 39 | if (utils.hasOwnProperty(target, name)) { | 57 | if (utils.hasOwnProp(target, name)) { |
| 40 | target[name] = [target[name], value]; | 58 | target[name] = [target[name], value]; |
| 41 | } else { | 59 | } else { |
| 42 | target[name] = value; | 60 | target[name] = value; |
@@ -49,7 +67,7 @@ | |||
| 49 | target[name] = []; | 67 | target[name] = []; |
| 50 | } | 68 | } |
| 51 | 69 | ||
| 52 | var result = buildPath(path, value, target[name], index); | 70 | const result = buildPath(path, value, target[name], index); |
| 53 | 71 | ||
| 54 | if (result && utils.isArray(target[name])) { | 72 | if (result && utils.isArray(target[name])) { |
| 55 | target[name] = arrayToObject(target[name]); | 73 | target[name] = arrayToObject(target[name]); |
@@ -59,9 +77,9 @@ | |||
| 59 | } | 77 | } |
| 60 | 78 | ||
| 61 | if (utils.isFormData(formData) && utils.isFunction(formData.entries)) { | 79 | if (utils.isFormData(formData) && utils.isFunction(formData.entries)) { |
| 62 | var obj = {}; | 80 | const obj = {}; |
| 63 | 81 | ||
| 64 | utils.forEachEntry(formData, function(name, value) { | 82 | utils.forEachEntry(formData, (name, value) => { |
| 65 | buildPath(parsePropPath(name), value, obj, 0); | 83 | buildPath(parsePropPath(name), value, obj, 0); |
| 66 | }); | 84 | }); |
| 67 | 85 | ||
@@ -71,4 +89,4 @@ | |||
| 71 | return null; | 89 | return null; |
| 72 | } | 90 | } |
| 73 | 91 | ||
| 74 | module.exports = formDataToJSON; | 92 | export default formDataToJSON; |
@@ -1,22 +1,24 @@ | |||
| 1 | 'use strict'; | 1 | 'use strict'; |
| 2 | 2 | ||
| 3 | var AxiosError = require('../core/AxiosError'); | ||
| 4 | var parseProtocol = require('./parseProtocol'); | ||
| 5 | var platform = require('../platform'); | 3 | import AxiosError from '../core/AxiosError.js'; |
| 4 | import parseProtocol from './parseProtocol.js'; | ||
| 5 | import platform from '../platform/index.js'; | ||
| 6 | 6 | ||
| 7 | var DATA_URL_PATTERN = /^(?:([^;]+);)?(?:[^;]+;)?(base64|),([\s\S]*)$/; | 7 | const DATA_URL_PATTERN = /^(?:([^;]+);)?(?:[^;]+;)?(base64|),([\s\S]*)$/; |
| 8 | 8 | ||
| 9 | /** | 9 | /** |
| 10 | * Parse data uri to a Buffer or Blob | 10 | * Parse data uri to a Buffer or Blob |
| 11 | * | ||
| 11 | * @param {String} uri | 12 | * @param {String} uri |
| 12 | * @param {?Boolean} asBlob | 13 | * @param {?Boolean} asBlob |
| 13 | * @param {?Object} options | 14 | * @param {?Object} options |
| 14 | * @param {?Function} options.Blob | 15 | * @param {?Function} options.Blob |
| 16 | * | ||
| 15 | * @returns {Buffer|Blob} | 17 | * @returns {Buffer|Blob} |
| 16 | */ | 18 | */ |
| 17 | module.exports = function fromDataURI(uri, asBlob, options) { | ||
| 18 | var _Blob = options && options.Blob || platform.classes.Blob; | ||
| 19 | var protocol = parseProtocol(uri); | 19 | export default function fromDataURI(uri, asBlob, options) { |
| 20 | const _Blob = options && options.Blob || platform.classes.Blob; | ||
| 21 | const protocol = parseProtocol(uri); | ||
| 20 | 22 | ||
| 21 | if (asBlob === undefined && _Blob) { | 23 | if (asBlob === undefined && _Blob) { |
| 22 | asBlob = true; | 24 | asBlob = true; |
@@ -25,16 +27,16 @@ | |||
| 25 | if (protocol === 'data') { | 27 | if (protocol === 'data') { |
| 26 | uri = protocol.length ? uri.slice(protocol.length + 1) : uri; | 28 | uri = protocol.length ? uri.slice(protocol.length + 1) : uri; |
| 27 | 29 | ||
| 28 | var match = DATA_URL_PATTERN.exec(uri); | 30 | const match = DATA_URL_PATTERN.exec(uri); |
| 29 | 31 | ||
| 30 | if (!match) { | 32 | if (!match) { |
| 31 | throw new AxiosError('Invalid URL', AxiosError.ERR_INVALID_URL); | 33 | throw new AxiosError('Invalid URL', AxiosError.ERR_INVALID_URL); |
| 32 | } | 34 | } |
| 33 | 35 | ||
| 34 | var mime = match[1]; | ||
| 35 | var isBase64 = match[2]; | ||
| 36 | var body = match[3]; | ||
| 37 | var buffer = Buffer.from(decodeURIComponent(body), isBase64 ? 'base64' : 'utf8'); | 36 | const mime = match[1]; |
| 37 | const isBase64 = match[2]; | ||
| 38 | const body = match[3]; | ||
| 39 | const buffer = Buffer.from(decodeURIComponent(body), isBase64 ? 'base64' : 'utf8'); | ||
| 38 | 40 | ||
| 39 | if (asBlob) { | 41 | if (asBlob) { |
| 40 | if (!_Blob) { | 42 | if (!_Blob) { |
@@ -48,4 +50,4 @@ | |||
| 48 | } | 50 | } |
| 49 | 51 | ||
| 50 | throw new AxiosError('Unsupported protocol ' + protocol, AxiosError.ERR_NOT_SUPPORT); | 52 | throw new AxiosError('Unsupported protocol ' + protocol, AxiosError.ERR_NOT_SUPPORT); |
| 51 | }; | 53 | } |
@@ -1,11 +1,43 @@ | |||
| 1 | 'use strict'; | 1 | import URLSearchParams from './classes/URLSearchParams.js' |
| 2 | import FormData from './classes/FormData.js' | ||
| 2 | 3 | ||
| 3 | module.exports = { | 4 | /** |
| 5 | * Determine if we're running in a standard browser environment | ||
| 6 | * | ||
| 7 | * This allows axios to run in a web worker, and react-native. | ||
| 8 | * Both environments support XMLHttpRequest, but not fully standard globals. | ||
| 9 | * | ||
| 10 | * web workers: | ||
| 11 | * typeof window -> undefined | ||
| 12 | * typeof document -> undefined | ||
| 13 | * | ||
| 14 | * react-native: | ||
| 15 | * navigator.product -> 'ReactNative' | ||
| 16 | * nativescript | ||
| 17 | * navigator.product -> 'NativeScript' or 'NS' | ||
| 18 | * | ||
| 19 | * @returns {boolean} | ||
| 20 | */ | ||
| 21 | const isStandardBrowserEnv = (() => { | ||
| 22 | let product; | ||
| 23 | if (typeof navigator !== 'undefined' && ( | ||
| 24 | (product = navigator.product) === 'ReactNative' || | ||
| 25 | product === 'NativeScript' || | ||
| 26 | product === 'NS') | ||
| 27 | ) { | ||
| 28 | return false; | ||
| 29 | } | ||
| 30 | |||
| 31 | return typeof window !== 'undefined' && typeof document !== 'undefined'; | ||
| 32 | })(); | ||
| 33 | |||
| 34 | export default { | ||
| 4 | isBrowser: true, | 35 | isBrowser: true, |
| 5 | classes: { | 36 | classes: { |
| 6 | URLSearchParams: require('./classes/URLSearchParams'), | ||
| 7 | FormData: require('./classes/FormData'), | ||
| 8 | Blob: Blob | 37 | URLSearchParams, |
| 38 | FormData, | ||
| 39 | Blob | ||
| 9 | }, | 40 | }, |
| 41 | isStandardBrowserEnv, | ||
| 10 | protocols: ['http', 'https', 'file', 'blob', 'url', 'data'] | 42 | protocols: ['http', 'https', 'file', 'blob', 'url', 'data'] |
| 11 | }; | 43 | }; |
@@ -1,10 +1,11 @@ | |||
| 1 | 'use strict'; | 1 | import URLSearchParams from './classes/URLSearchParams.js' |
| 2 | import FormData from './classes/FormData.js' | ||
| 2 | 3 | ||
| 3 | module.exports = { | 4 | export default { |
| 4 | isNode: true, | 5 | isNode: true, |
| 5 | classes: { | 6 | classes: { |
| 6 | URLSearchParams: require('./classes/URLSearchParams'), | ||
| 7 | FormData: require('./classes/FormData'), | 7 | URLSearchParams, |
| 8 | FormData, | ||
| 8 | Blob: typeof Blob !== 'undefined' && Blob || null | 9 | Blob: typeof Blob !== 'undefined' && Blob || null |
| 9 | }, | 10 | }, |
| 10 | protocols: [ 'http', 'https', 'file', 'data' ] | 11 | protocols: [ 'http', 'https', 'file', 'data' ] |
@@ -1,63 +1,71 @@ | |||
| 1 | 'use strict'; | 1 | 'use strict'; |
| 2 | 2 | ||
| 3 | var utils = require('./../utils'); | 3 | import utils from './../utils.js'; |
| 4 | 4 | ||
| 5 | function InterceptorManager() { | ||
| 6 | this.handlers = []; | ||
| 7 | } | 5 | class InterceptorManager { |
| 6 | constructor() { | ||
| 7 | this.handlers = []; | ||
| 8 | } | ||
| 8 | 9 | ||
| 9 | /** | ||
| 10 | * Add a new interceptor to the stack | ||
| 11 | * | ||
| 12 | * @param {Function} fulfilled The function to handle `then` for a `Promise` | ||
| 13 | * @param {Function} rejected The function to handle `reject` for a `Promise` | ||
| 14 | * | ||
| 15 | * @return {Number} An ID used to remove interceptor later | ||
| 16 | */ | ||
| 17 | InterceptorManager.prototype.use = function use(fulfilled, rejected, options) { | ||
| 18 | this.handlers.push({ | ||
| 19 | fulfilled: fulfilled, | ||
| 20 | rejected: rejected, | ||
| 21 | synchronous: options ? options.synchronous : false, | ||
| 22 | runWhen: options ? options.runWhen : null | ||
| 23 | }); | ||
| 24 | return this.handlers.length - 1; | ||
| 25 | }; | ||
| 26 | |||
| 27 | /** | ||
| 28 | * Remove an interceptor from the stack | ||
| 29 | * | ||
| 30 | * @param {Number} id The ID that was returned by `use` | ||
| 31 | */ | ||
| 32 | InterceptorManager.prototype.eject = function eject(id) { | ||
| 33 | if (this.handlers[id]) { | ||
| 34 | this.handlers[id] = null; | 10 | /** |
| 11 | * Add a new interceptor to the stack | ||
| 12 | * | ||
| 13 | * @param {Function} fulfilled The function to handle `then` for a `Promise` | ||
| 14 | * @param {Function} rejected The function to handle `reject` for a `Promise` | ||
| 15 | * | ||
| 16 | * @return {Number} An ID used to remove interceptor later | ||
| 17 | */ | ||
| 18 | use(fulfilled, rejected, options) { | ||
| 19 | this.handlers.push({ | ||
| 20 | fulfilled, | ||
| 21 | rejected, | ||
| 22 | synchronous: options ? options.synchronous : false, | ||
| 23 | runWhen: options ? options.runWhen : null | ||
| 24 | }); | ||
| 25 | return this.handlers.length - 1; | ||
| 35 | } | 26 | } |
| 36 | }; | ||
| 37 | 27 | ||
| 38 | /** | ||
| 39 | * Clear all interceptors from the stack | ||
| 40 | */ | ||
| 41 | InterceptorManager.prototype.clear = function clear() { | ||
| 42 | if (this.handlers) { | ||
| 43 | this.handlers = []; | 28 | /** |
| 29 | * Remove an interceptor from the stack | ||
| 30 | * | ||
| 31 | * @param {Number} id The ID that was returned by `use` | ||
| 32 | * | ||
| 33 | * @returns {Boolean} `true` if the interceptor was removed, `false` otherwise | ||
| 34 | */ | ||
| 35 | eject(id) { | ||
| 36 | if (this.handlers[id]) { | ||
| 37 | this.handlers[id] = null; | ||
| 38 | } | ||
| 44 | } | 39 | } |
| 45 | }; | ||
| 46 | 40 | ||
| 47 | /** | ||
| 48 | * Iterate over all the registered interceptors | ||
| 49 | * | ||
| 50 | * This method is particularly useful for skipping over any | ||
| 51 | * interceptors that may have become `null` calling `eject`. | ||
| 52 | * | ||
| 53 | * @param {Function} fn The function to call for each interceptor | ||
| 54 | */ | ||
| 55 | InterceptorManager.prototype.forEach = function forEach(fn) { | ||
| 56 | utils.forEach(this.handlers, function forEachHandler(h) { | ||
| 57 | if (h !== null) { | ||
| 58 | fn(h); | 41 | /** |
| 42 | * Clear all interceptors from the stack | ||
| 43 | * | ||
| 44 | * @returns {void} | ||
| 45 | */ | ||
| 46 | clear() { | ||
| 47 | if (this.handlers) { | ||
| 48 | this.handlers = []; | ||
| 59 | } | 49 | } |
| 60 | }); | ||
| 61 | }; | 50 | } |
| 62 | 51 | ||
| 63 | module.exports = InterceptorManager; | 52 | /** |
| 53 | * Iterate over all the registered interceptors | ||
| 54 | * | ||
| 55 | * This method is particularly useful for skipping over any | ||
| 56 | * interceptors that may have become `null` calling `eject`. | ||
| 57 | * | ||
| 58 | * @param {Function} fn The function to call for each interceptor | ||
| 59 | * | ||
| 60 | * @returns {void} | ||
| 61 | */ | ||
| 62 | forEach(fn) { | ||
| 63 | utils.forEach(this.handlers, function forEachHandler(h) { | ||
| 64 | if (h !== null) { | ||
| 65 | fn(h); | ||
| 66 | } | ||
| 67 | }); | ||
| 68 | } | ||
| 69 | } | ||
| 70 | |||
| 71 | export default InterceptorManager; | ||
@@ -4,11 +4,12 @@ | |||
| 4 | * Determines whether the specified URL is absolute | 4 | * Determines whether the specified URL is absolute |
| 5 | * | 5 | * |
| 6 | * @param {string} url The URL to test | 6 | * @param {string} url The URL to test |
| 7 | * | ||
| 7 | * @returns {boolean} True if the specified URL is absolute, otherwise false | 8 | * @returns {boolean} True if the specified URL is absolute, otherwise false |
| 8 | */ | 9 | */ |
| 9 | module.exports = function isAbsoluteURL(url) { | 10 | export default function isAbsoluteURL(url) { |
| 10 | // A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL). | 11 | // A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL). |
| 11 | // RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed | 12 | // RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed |
| 12 | // by any combination of letters, digits, plus, period, or hyphen. | 13 | // by any combination of letters, digits, plus, period, or hyphen. |
| 13 | return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url); | 14 | return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url); |
| 14 | }; | 15 | } |
@@ -1,13 +1,14 @@ | |||
| 1 | 'use strict'; | 1 | 'use strict'; |
| 2 | 2 | ||
| 3 | var utils = require('./../utils'); | 3 | import utils from './../utils.js'; |
| 4 | 4 | ||
| 5 | /** | 5 | /** |
| 6 | * Determines whether the payload is an error thrown by Axios | 6 | * Determines whether the payload is an error thrown by Axios |
| 7 | * | 7 | * |
| 8 | * @param {*} payload The value to test | 8 | * @param {*} payload The value to test |
| 9 | * | ||
| 9 | * @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 |
| 10 | */ | 11 | */ |
| 11 | module.exports = function isAxiosError(payload) { | 12 | export default function isAxiosError(payload) { |
| 12 | return utils.isObject(payload) && (payload.isAxiosError === true); | 13 | return utils.isObject(payload) && (payload.isAxiosError === true); |
| 13 | }; | 14 | } |
@@ -1,68 +1,67 @@ | |||
| 1 | 'use strict'; | 1 | 'use strict'; |
| 2 | 2 | ||
| 3 | var utils = require('./../utils'); | 3 | import utils from './../utils.js'; |
| 4 | import platform from '../platform/index.js'; | ||
| 4 | 5 | ||
| 5 | module.exports = ( | ||
| 6 | utils.isStandardBrowserEnv() ? | 6 | export default platform.isStandardBrowserEnv ? |
| 7 | 7 | ||
| 8 | // Standard browser envs have full support of the APIs needed to test | ||
| 9 | // whether the request URL is of the same origin as current location. | ||
| 10 | (function standardBrowserEnv() { | ||
| 11 | var msie = /(msie|trident)/i.test(navigator.userAgent); | ||
| 12 | var urlParsingNode = document.createElement('a'); | ||
| 13 | var originURL; | 8 | // Standard browser envs have full support of the APIs needed to test |
| 9 | // whether the request URL is of the same origin as current location. | ||
| 10 | (function standardBrowserEnv() { | ||
| 11 | const msie = /(msie|trident)/i.test(navigator.userAgent); | ||
| 12 | const urlParsingNode = document.createElement('a'); | ||
| 13 | let originURL; | ||
| 14 | 14 | ||
| 15 | /** | ||
| 16 | * Parse a URL to discover it's components | ||
| 17 | * | ||
| 18 | * @param {String} url The URL to be parsed | ||
| 19 | * @returns {Object} | ||
| 20 | */ | ||
| 21 | function resolveURL(url) { | ||
| 22 | var href = url; | 15 | /** |
| 16 | * Parse a URL to discover it's components | ||
| 17 | * | ||
| 18 | * @param {String} url The URL to be parsed | ||
| 19 | * @returns {Object} | ||
| 20 | */ | ||
| 21 | function resolveURL(url) { | ||
| 22 | let href = url; | ||
| 23 | 23 | ||
| 24 | if (msie) { | ||
| 25 | // IE needs attribute set twice to normalize properties | ||
| 26 | urlParsingNode.setAttribute('href', href); | ||
| 27 | href = urlParsingNode.href; | ||
| 28 | } | ||
| 29 | 24 | if (msie) { | |
| 25 | // IE needs attribute set twice to normalize properties | ||
| 30 | urlParsingNode.setAttribute('href', href); | 26 | urlParsingNode.setAttribute('href', href); |
| 31 | |||
| 32 | // urlParsingNode provides the UrlUtils interface - http://url.spec.whatwg.org/#urlutils | ||
| 33 | return { | ||
| 34 | href: urlParsingNode.href, | ||
| 35 | protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, '') : '', | ||
| 36 | host: urlParsingNode.host, | ||
| 37 | search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, '') : '', | ||
| 38 | hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, '') : '', | ||
| 39 | hostname: urlParsingNode.hostname, | ||
| 40 | port: urlParsingNode.port, | ||
| 41 | pathname: (urlParsingNode.pathname.charAt(0) === '/') ? | ||
| 42 | urlParsingNode.pathname : | ||
| 43 | '/' + urlParsingNode.pathname | ||
| 44 | }; | 27 | href = urlParsingNode.href; |
| 45 | } | 28 | } |
| 46 | 29 | ||
| 47 | originURL = resolveURL(window.location.href); | 30 | urlParsingNode.setAttribute('href', href); |
| 48 | 31 | ||
| 49 | /** | ||
| 50 | * Determine if a URL shares the same origin as the current location | ||
| 51 | * | ||
| 52 | * @param {String} requestURL The URL to test | ||
| 53 | * @returns {boolean} True if URL shares the same origin, otherwise false | ||
| 54 | */ | ||
| 55 | return function isURLSameOrigin(requestURL) { | ||
| 56 | var parsed = (utils.isString(requestURL)) ? resolveURL(requestURL) : requestURL; | ||
| 57 | return (parsed.protocol === originURL.protocol && | ||
| 58 | parsed.host === originURL.host); | 32 | // urlParsingNode provides the UrlUtils interface - http://url.spec.whatwg.org/#urlutils |
| 33 | return { | ||
| 34 | href: urlParsingNode.href, | ||
| 35 | protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, '') : '', | ||
| 36 | host: urlParsingNode.host, | ||
| 37 | search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, '') : '', | ||
| 38 | hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, '') : '', | ||
| 39 | hostname: urlParsingNode.hostname, | ||
| 40 | port: urlParsingNode.port, | ||
| 41 | pathname: (urlParsingNode.pathname.charAt(0) === '/') ? | ||
| 42 | urlParsingNode.pathname : | ||
| 43 | '/' + urlParsingNode.pathname | ||
| 59 | }; | 44 | }; |
| 60 | })() : | 45 | } |
| 61 | 46 | ||
| 62 | // Non standard browser envs (web workers, react-native) lack needed support. | ||
| 63 | (function nonStandardBrowserEnv() { | ||
| 64 | return function isURLSameOrigin() { | ||
| 65 | return true; | ||
| 66 | }; | ||
| 67 | })() | ||
| 68 | ); | 47 | originURL = resolveURL(window.location.href); |
| 48 | |||
| 49 | /** | ||
| 50 | * Determine if a URL shares the same origin as the current location | ||
| 51 | * | ||
| 52 | * @param {String} requestURL The URL to test | ||
| 53 | * @returns {boolean} True if URL shares the same origin, otherwise false | ||
| 54 | */ | ||
| 55 | return function isURLSameOrigin(requestURL) { | ||
| 56 | const parsed = (utils.isString(requestURL)) ? resolveURL(requestURL) : requestURL; | ||
| 57 | return (parsed.protocol === originURL.protocol && | ||
| 58 | parsed.host === originURL.host); | ||
| 59 | }; | ||
| 60 | })() : | ||
| 61 | |||
| 62 | // Non standard browser envs (web workers, react-native) lack needed support. | ||
| 63 | (function nonStandardBrowserEnv() { | ||
| 64 | return function isURLSameOrigin() { | ||
| 65 | return true; | ||
| 66 | }; | ||
| 67 | })(); | ||
@@ -1,6 +1,6 @@ | |||
| 1 | 'use strict'; | 1 | 'use strict'; |
| 2 | 2 | ||
| 3 | var utils = require('../utils'); | 3 | import utils from '../utils.js'; |
| 4 | 4 | ||
| 5 | /** | 5 | /** |
| 6 | * Config-specific merge-function which creates a new config-object | 6 | * Config-specific merge-function which creates a new config-object |
@@ -8,18 +8,17 @@ | |||
| 8 | * | 8 | * |
| 9 | * @param {Object} config1 | 9 | * @param {Object} config1 |
| 10 | * @param {Object} config2 | 10 | * @param {Object} config2 |
| 11 | * | ||
| 11 | * @returns {Object} New object resulting from merging config2 to config1 | 12 | * @returns {Object} New object resulting from merging config2 to config1 |
| 12 | */ | 13 | */ |
| 13 | module.exports = function mergeConfig(config1, config2) { | 14 | export default function mergeConfig(config1, config2) { |
| 14 | // eslint-disable-next-line no-param-reassign | 15 | // eslint-disable-next-line no-param-reassign |
| 15 | config2 = config2 || {}; | 16 | config2 = config2 || {}; |
| 16 | var config = {}; | 17 | const config = {}; |
| 17 | 18 | ||
| 18 | function getMergedValue(target, source) { | 19 | function getMergedValue(target, source) { |
| 19 | if (utils.isPlainObject(target) && utils.isPlainObject(source)) { | 20 | if (utils.isPlainObject(target) && utils.isPlainObject(source)) { |
| 20 | return utils.merge(target, source); | 21 | return utils.merge(target, source); |
| 21 | } else if (utils.isEmptyObject(source)) { | ||
| 22 | return utils.merge({}, target); | ||
| 23 | } else if (utils.isPlainObject(source)) { | 22 | } else if (utils.isPlainObject(source)) { |
| 24 | return utils.merge({}, source); | 23 | return utils.merge({}, source); |
| 25 | } else if (utils.isArray(source)) { | 24 | } else if (utils.isArray(source)) { |
@@ -62,7 +61,7 @@ | |||
| 62 | } | 61 | } |
| 63 | } | 62 | } |
| 64 | 63 | ||
| 65 | var mergeMap = { | 64 | const mergeMap = { |
| 66 | 'url': valueFromConfig2, | 65 | 'url': valueFromConfig2, |
| 67 | 'method': valueFromConfig2, | 66 | 'method': valueFromConfig2, |
| 68 | 'data': valueFromConfig2, | 67 | 'data': valueFromConfig2, |
@@ -73,7 +72,6 @@ | |||
| 73 | 'timeout': defaultToConfig2, | 72 | 'timeout': defaultToConfig2, |
| 74 | 'timeoutMessage': defaultToConfig2, | 73 | 'timeoutMessage': defaultToConfig2, |
| 75 | 'withCredentials': defaultToConfig2, | 74 | 'withCredentials': defaultToConfig2, |
| 76 | 'withXSRFToken': defaultToConfig2, | ||
| 77 | 'adapter': defaultToConfig2, | 75 | 'adapter': defaultToConfig2, |
| 78 | 'responseType': defaultToConfig2, | 76 | 'responseType': defaultToConfig2, |
| 79 | 'xsrfCookieName': defaultToConfig2, | 77 | 'xsrfCookieName': defaultToConfig2, |
@@ -94,13 +92,10 @@ | |||
| 94 | }; | 92 | }; |
| 95 | 93 | ||
| 96 | utils.forEach(Object.keys(config1).concat(Object.keys(config2)), function computeConfigValue(prop) { | 94 | utils.forEach(Object.keys(config1).concat(Object.keys(config2)), function computeConfigValue(prop) { |
| 97 | if (prop === '__proto__' || prop === 'constructor' || prop === 'prototype') { | ||
| 98 | return; | ||
| 99 | } | ||
| 100 | var merge = utils.hasOwnProperty(mergeMap, prop) ? mergeMap[prop] : mergeDeepProperties; | ||
| 101 | var configValue = merge(prop); | 95 | const merge = mergeMap[prop] || mergeDeepProperties; |
| 96 | const configValue = merge(prop); | ||
| 102 | (utils.isUndefined(configValue) && merge !== mergeDirectKeys) || (config[prop] = configValue); | 97 | (utils.isUndefined(configValue) && merge !== mergeDirectKeys) || (config[prop] = configValue); |
| 103 | }); | 98 | }); |
| 104 | 99 | ||
| 105 | return config; | 100 | return config; |
| 106 | }; | 101 | } |
@@ -1,15 +1,15 @@ | |||
| 1 | 'use strict'; | 1 | 'use strict'; |
| 2 | 2 | ||
| 3 | var utils = require('./../utils'); | 3 | import utils from './../utils.js'; |
| 4 | 4 | ||
| 5 | // Headers 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 | var ignoreDuplicateOf = [ | 7 | const ignoreDuplicateOf = utils.toObjectSet([ |
| 8 | 'age', 'authorization', 'content-length', 'content-type', 'etag', | 8 | 'age', 'authorization', 'content-length', 'content-type', 'etag', |
| 9 | 'expires', 'from', 'host', 'if-modified-since', 'if-unmodified-since', | 9 | 'expires', 'from', 'host', 'if-modified-since', 'if-unmodified-since', |
| 10 | 'last-modified', 'location', 'max-forwards', 'proxy-authorization', | 10 | 'last-modified', 'location', 'max-forwards', 'proxy-authorization', |
| 11 | 'referer', 'retry-after', 'user-agent' | 11 | 'referer', 'retry-after', 'user-agent' |
| 12 | ]; | 12 | ]); |
| 13 | 13 | ||
| 14 | /** | 14 | /** |
| 15 | * Parse headers into an object | 15 | * Parse headers into an object |
@@ -21,31 +21,33 @@ | |||
| 21 | * Transfer-Encoding: chunked | 21 | * Transfer-Encoding: chunked |
| 22 | * ``` | 22 | * ``` |
| 23 | * | 23 | * |
| 24 | * @param {String} headers Headers needing to be parsed | 24 | * @param {String} rawHeaders Headers needing to be parsed |
| 25 | * | ||
| 25 | * @returns {Object} Headers parsed into an object | 26 | * @returns {Object} Headers parsed into an object |
| 26 | */ | 27 | */ |
| 27 | module.exports = function parseHeaders(headers) { | ||
| 28 | var parsed = {}; | ||
| 29 | var key; | ||
| 30 | var val; | ||
| 31 | var i; | 28 | export default rawHeaders => { |
| 29 | const parsed = {}; | ||
| 30 | let key; | ||
| 31 | let val; | ||
| 32 | let i; | ||
| 32 | 33 | ||
| 33 | if (!headers) { return parsed; } | ||
| 34 | |||
| 35 | utils.forEach(headers.split('\n'), function parser(line) { | 34 | rawHeaders && rawHeaders.split('\n').forEach(function parser(line) { |
| 36 | i = line.indexOf(':'); | 35 | i = line.indexOf(':'); |
| 37 | key = utils.trim(line.slice(0, i)).toLowerCase(); | ||
| 38 | val = utils.trim(line.slice(i + 1)); | 36 | key = line.substring(0, i).trim().toLowerCase(); |
| 37 | val = line.substring(i + 1).trim(); | ||
| 39 | 38 | ||
| 40 | if (key) { | ||
| 41 | if (parsed[key] && ignoreDuplicateOf.indexOf(key) >= 0) { | ||
| 42 | return; | ||
| 43 | } | ||
| 44 | if (key === 'set-cookie') { | ||
| 45 | parsed[key] = (parsed[key] ? parsed[key] : []).concat([val]); | 39 | if (!key || (parsed[key] && ignoreDuplicateOf[key])) { |
| 40 | return; | ||
| 41 | } | ||
| 42 | |||
| 43 | if (key === 'set-cookie') { | ||
| 44 | if (parsed[key]) { | ||
| 45 | parsed[key].push(val); | ||
| 46 | } else { | 46 | } else { |
| 47 | parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val; | 47 | parsed[key] = [val]; |
| 48 | } | 48 | } |
| 49 | } else { | ||
| 50 | parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val; | ||
| 49 | } | 51 | } |
| 50 | }); | 52 | }); |
| 51 | 53 | ||
@@ -1,6 +1,6 @@ | |||
| 1 | 'use strict'; | 1 | 'use strict'; |
| 2 | 2 | ||
| 3 | module.exports = function parseProtocol(url) { | ||
| 4 | var match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url); | 3 | export default function parseProtocol(url) { |
| 4 | const match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url); | ||
| 5 | return match && match[1] || ''; | 5 | return match && match[1] || ''; |
| 6 | }; | 6 | } |
@@ -2,13 +2,16 @@ | |||
| 2 | import commonjs from '@rollup/plugin-commonjs'; | 2 | import commonjs from '@rollup/plugin-commonjs'; |
| 3 | import {terser} from "rollup-plugin-terser"; | 3 | import {terser} from "rollup-plugin-terser"; |
| 4 | import json from '@rollup/plugin-json'; | 4 | import json from '@rollup/plugin-json'; |
| 5 | import { babel } from '@rollup/plugin-babel'; | ||
| 6 | import autoExternal from 'rollup-plugin-auto-external'; | ||
| 7 | import bundleSize from 'rollup-plugin-bundle-size' | ||
| 5 | 8 | ||
| 6 | const lib = require("./package.json"); | 9 | const lib = require("./package.json"); |
| 7 | const outputFileName = 'axios'; | 10 | const outputFileName = 'axios'; |
| 8 | const name = "axios"; | 11 | const name = "axios"; |
| 9 | const input = './lib/axios.js'; | 12 | const input = './lib/axios.js'; |
| 10 | 13 | ||
| 11 | const buildConfig = (config) => { | 14 | const buildConfig = ({es5, browser = true, minifiedVersion = true, ...config}) => { |
| 12 | 15 | ||
| 13 | const build = ({minified}) => ({ | 16 | const build = ({minified}) => ({ |
| 14 | input, | 17 | input, |
@@ -19,25 +22,36 @@ | |||
| 19 | }, | 22 | }, |
| 20 | plugins: [ | 23 | plugins: [ |
| 21 | json(), | 24 | json(), |
| 22 | resolve({browser: true}), | 25 | resolve({browser}), |
| 23 | commonjs(), | 26 | commonjs(), |
| 24 | minified && terser(), | 27 | minified && terser(), |
| 28 | minified && bundleSize(), | ||
| 29 | ...(es5 ? [babel({ | ||
| 30 | babelHelpers: 'bundled', | ||
| 31 | presets: ['@babel/preset-env'] | ||
| 32 | })] : []), | ||
| 25 | ...(config.plugins || []), | 33 | ...(config.plugins || []), |
| 26 | ] | 34 | ] |
| 27 | }); | 35 | }); |
| 28 | 36 | ||
| 29 | return [ | 37 | const configs = [ |
| 30 | build({minified: false}), | 38 | build({minified: false}), |
| 31 | build({minified: true}), | ||
| 32 | ]; | 39 | ]; |
| 40 | |||
| 41 | if (minifiedVersion) { | ||
| 42 | configs.push(build({minified: true})) | ||
| 43 | } | ||
| 44 | |||
| 45 | return configs; | ||
| 33 | }; | 46 | }; |
| 34 | 47 | ||
| 35 | export default async () => { | 48 | export default async () => { |
| 36 | const year = new Date().getFullYear(); | 49 | const year = new Date().getFullYear(); |
| 37 | const banner = `// ${lib.name} v${lib.version} Copyright (c) ${year} ${lib.author}`; | 50 | const banner = `// Axios v${lib.version} Copyright (c) ${year} ${lib.author} and contributors`; |
| 38 | 51 | ||
| 39 | return [ | 52 | return [ |
| 40 | ...buildConfig({ | 53 | ...buildConfig({ |
| 54 | es5: true, | ||
| 41 | output: { | 55 | output: { |
| 42 | file: `dist/${outputFileName}`, | 56 | file: `dist/${outputFileName}`, |
| 43 | name, | 57 | name, |
@@ -55,6 +69,22 @@ | |||
| 55 | exports: "named", | 69 | exports: "named", |
| 56 | banner | 70 | banner |
| 57 | } | 71 | } |
| 58 | }) | 72 | }), |
| 73 | // Node.js commonjs build | ||
| 74 | { | ||
| 75 | input, | ||
| 76 | output: { | ||
| 77 | file: `dist/node/${name}.cjs`, | ||
| 78 | format: "cjs", | ||
| 79 | preferConst: true, | ||
| 80 | exports: "default", | ||
| 81 | banner | ||
| 82 | }, | ||
| 83 | plugins: [ | ||
| 84 | autoExternal(), | ||
| 85 | resolve(), | ||
| 86 | commonjs() | ||
| 87 | ] | ||
| 88 | } | ||
| 59 | ] | 89 | ] |
| 60 | }; | 90 | }; |
@@ -1,6 +1,6 @@ | |||
| 1 | 'use strict'; | 1 | 'use strict'; |
| 2 | 2 | ||
| 3 | var AxiosError = require('./AxiosError'); | 3 | import AxiosError from './AxiosError.js'; |
| 4 | 4 | ||
| 5 | /** | 5 | /** |
| 6 | * Resolve or reject a Promise based on response status. | 6 | * Resolve or reject a Promise based on response status. |
@@ -8,9 +8,11 @@ | |||
| 8 | * @param {Function} resolve A function that resolves the promise. | 8 | * @param {Function} resolve A function that resolves the promise. |
| 9 | * @param {Function} reject A function that rejects the promise. | 9 | * @param {Function} reject A function that rejects the promise. |
| 10 | * @param {object} response The response. | 10 | * @param {object} response The response. |
| 11 | * | ||
| 12 | * @returns {object} The response. | ||
| 11 | */ | 13 | */ |
| 12 | module.exports = function settle(resolve, reject, response) { | ||
| 13 | var validateStatus = response.config.validateStatus; | 14 | export default function settle(resolve, reject, response) { |
| 15 | const validateStatus = response.config.validateStatus; | ||
| 14 | if (!response.status || !validateStatus || validateStatus(response.status)) { | 16 | if (!response.status || !validateStatus || validateStatus(response.status)) { |
| 15 | resolve(response); | 17 | resolve(response); |
| 16 | } else { | 18 | } else { |
@@ -22,4 +24,4 @@ | |||
| 22 | response | 24 | response |
| 23 | )); | 25 | )); |
| 24 | } | 26 | } |
| 25 | }; | 27 | } |
@@ -18,10 +18,11 @@ | |||
| 18 | * ``` | 18 | * ``` |
| 19 | * | 19 | * |
| 20 | * @param {Function} callback | 20 | * @param {Function} callback |
| 21 | * | ||
| 21 | * @returns {Function} | 22 | * @returns {Function} |
| 22 | */ | 23 | */ |
| 23 | module.exports = function spread(callback) { | 24 | export default function spread(callback) { |
| 24 | return function wrap(arr) { | 25 | return function wrap(arr) { |
| 25 | return callback.apply(null, arr); | 26 | return callback.apply(null, arr); |
| 26 | }; | 27 | }; |
| 27 | }; | 28 | } |
@@ -1,10 +1,10 @@ | |||
| 1 | 'use strict'; | 1 | 'use strict'; |
| 2 | 2 | ||
| 3 | var utils = require('../utils'); | ||
| 4 | var toFormData = require('./toFormData'); | ||
| 5 | var platform = require('../platform/'); | 3 | import utils from '../utils.js'; |
| 4 | import toFormData from './toFormData.js'; | ||
| 5 | import platform from '../platform/index.js'; | ||
| 6 | 6 | ||
| 7 | module.exports = function toURLEncodedForm(data, options) { | 7 | export default function toURLEncodedForm(data, options) { |
| 8 | return toFormData(data, new platform.classes.URLSearchParams(), Object.assign({ | 8 | return toFormData(data, new platform.classes.URLSearchParams(), Object.assign({ |
| 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)) { |
@@ -15,4 +15,4 @@ | |||
| 15 | return helpers.defaultVisitor.apply(this, arguments); | 15 | return helpers.defaultVisitor.apply(this, arguments); |
| 16 | } | 16 | } |
| 17 | }, options)); | 17 | }, options)); |
| 18 | }; | 18 | } |
@@ -1,23 +1,28 @@ | |||
| 1 | 'use strict'; | 1 | 'use strict'; |
| 2 | 2 | ||
| 3 | var utils = require('./../utils'); | ||
| 4 | var defaults = require('../defaults'); | 3 | import utils from './../utils.js'; |
| 4 | import defaults from '../defaults/index.js'; | ||
| 5 | import AxiosHeaders from '../core/AxiosHeaders.js'; | ||
| 5 | 6 | ||
| 6 | /** | 7 | /** |
| 7 | * Transform the data for a request or a response | 8 | * Transform the data for a request or a response |
| 8 | * | 9 | * |
| 9 | * @param {Object|String} data The data to be transformed | ||
| 10 | * @param {Array} headers The headers for the request or response | ||
| 11 | * @param {Number} status HTTP status code | ||
| 12 | * @param {Array|Function} fns A single function or Array of functions | 10 | * @param {Array|Function} fns A single function or Array of functions |
| 11 | * @param {?Object} response The response object | ||
| 12 | * | ||
| 13 | * @returns {*} The resulting transformed data | 13 | * @returns {*} The resulting transformed data |
| 14 | */ | 14 | */ |
| 15 | module.exports = function transformData(data, headers, status, fns) { | ||
| 16 | var context = this || defaults; | ||
| 17 | /*eslint no-param-reassign:0*/ | 15 | export default function transformData(fns, response) { |
| 16 | const config = this || defaults; | ||
| 17 | const context = response || config; | ||
| 18 | const headers = AxiosHeaders.from(context.headers); | ||
| 19 | let data = context.data; | ||
| 20 | |||
| 18 | utils.forEach(fns, function transform(fn) { | 21 | utils.forEach(fns, function transform(fn) { |
| 19 | data = fn.call(context, data, headers, status); | 22 | data = fn.call(config, data, headers.normalize(), response ? response.status : undefined); |
| 20 | }); | 23 | }); |
| 21 | 24 | ||
| 25 | headers.normalize(); | ||
| 26 | |||
| 22 | return data; | 27 | return data; |
| 23 | }; | 28 | } |
@@ -1,5 +1,4 @@ | |||
| 1 | 'use strict'; | 1 | 'use strict'; |
| 2 | 2 | ||
| 3 | var AxiosURLSearchParams = require('../../../helpers/AxiosURLSearchParams'); | ||
| 4 | |||
| 5 | module.exports = typeof URLSearchParams !== 'undefined' ? URLSearchParams : AxiosURLSearchParams; | 3 | import AxiosURLSearchParams from '../../../helpers/AxiosURLSearchParams.js'; |
| 4 | export default typeof URLSearchParams !== 'undefined' ? URLSearchParams : AxiosURLSearchParams; | ||
@@ -1,24 +1,26 @@ | |||
| 1 | 'use strict'; | 1 | 'use strict'; |
| 2 | 2 | ||
| 3 | var VERSION = require('../env/data').version; | ||
| 4 | var AxiosError = require('../core/AxiosError'); | 3 | import {VERSION} from '../env/data.js'; |
| 4 | import AxiosError from '../core/AxiosError.js'; | ||
| 5 | 5 | ||
| 6 | var validators = {}; | 6 | const validators = {}; |
| 7 | 7 | ||
| 8 | // eslint-disable-next-line func-names | 8 | // eslint-disable-next-line func-names |
| 9 | ['object', 'boolean', 'number', 'function', 'string', 'symbol'].forEach(function(type, i) { | 9 | ['object', 'boolean', 'number', 'function', 'string', 'symbol'].forEach((type, i) => { |
| 10 | validators[type] = function validator(thing) { | 10 | validators[type] = function validator(thing) { |
| 11 | return typeof thing === type || 'a' + (i < 1 ? 'n ' : ' ') + type; | 11 | return typeof thing === type || 'a' + (i < 1 ? 'n ' : ' ') + type; |
| 12 | }; | 12 | }; |
| 13 | }); | 13 | }); |
| 14 | 14 | ||
| 15 | var deprecatedWarnings = {}; | 15 | const deprecatedWarnings = {}; |
| 16 | 16 | ||
| 17 | /** | 17 | /** |
| 18 | * Transitional option validator | 18 | * Transitional option validator |
| 19 | * | ||
| 19 | * @param {function|boolean?} validator - set to false if the transitional option has been removed | 20 | * @param {function|boolean?} validator - set to false if the transitional option has been removed |
| 20 | * @param {string?} version - deprecated version / removed since version | 21 | * @param {string?} version - deprecated version / removed since version |
| 21 | * @param {string?} message - some message with additional info | 22 | * @param {string?} message - some message with additional info |
| 23 | * | ||
| 22 | * @returns {function} | 24 | * @returns {function} |
| 23 | */ | 25 | */ |
| 24 | validators.transitional = function transitional(validator, version, message) { | 26 | validators.transitional = function transitional(validator, version, message) { |
@@ -27,7 +29,7 @@ | |||
| 27 | } | 29 | } |
| 28 | 30 | ||
| 29 | // eslint-disable-next-line func-names | 31 | // eslint-disable-next-line func-names |
| 30 | return function(value, opt, opts) { | 32 | return (value, opt, opts) => { |
| 31 | if (validator === false) { | 33 | if (validator === false) { |
| 32 | throw new AxiosError( | 34 | throw new AxiosError( |
| 33 | formatMessage(opt, ' has been removed' + (version ? ' in ' + version : '')), | 35 | formatMessage(opt, ' has been removed' + (version ? ' in ' + version : '')), |
@@ -52,23 +54,26 @@ | |||
| 52 | 54 | ||
| 53 | /** | 55 | /** |
| 54 | * Assert object's properties type | 56 | * Assert object's properties type |
| 57 | * | ||
| 55 | * @param {object} options | 58 | * @param {object} options |
| 56 | * @param {object} schema | 59 | * @param {object} schema |
| 57 | * @param {boolean?} allowUnknown | 60 | * @param {boolean?} allowUnknown |
| 61 | * | ||
| 62 | * @returns {object} | ||
| 58 | */ | 63 | */ |
| 59 | 64 | ||
| 60 | function assertOptions(options, schema, allowUnknown) { | 65 | function assertOptions(options, schema, allowUnknown) { |
| 61 | if (typeof options !== 'object') { | 66 | if (typeof options !== 'object') { |
| 62 | throw new AxiosError('options must be an object', AxiosError.ERR_BAD_OPTION_VALUE); | 67 | throw new AxiosError('options must be an object', AxiosError.ERR_BAD_OPTION_VALUE); |
| 63 | } | 68 | } |
| 64 | var keys = Object.keys(options); | ||
| 65 | var i = keys.length; | 69 | const keys = Object.keys(options); |
| 70 | let i = keys.length; | ||
| 66 | while (i-- > 0) { | 71 | while (i-- > 0) { |
| 67 | var opt = keys[i]; | ||
| 68 | var validator = schema[opt]; | 72 | const opt = keys[i]; |
| 73 | const validator = schema[opt]; | ||
| 69 | if (validator) { | 74 | if (validator) { |
| 70 | var value = options[opt]; | ||
| 71 | var result = value === undefined || validator(value, opt, options); | 75 | const value = options[opt]; |
| 76 | const result = value === undefined || validator(value, opt, options); | ||
| 72 | if (result !== true) { | 77 | if (result !== true) { |
| 73 | throw new AxiosError('option ' + opt + ' must be ' + result, AxiosError.ERR_BAD_OPTION_VALUE); | 78 | throw new AxiosError('option ' + opt + ' must be ' + result, AxiosError.ERR_BAD_OPTION_VALUE); |
| 74 | } | 79 | } |
@@ -80,7 +85,7 @@ | |||
| 80 | } | 85 | } |
| 81 | } | 86 | } |
| 82 | 87 | ||
| 83 | module.exports = { | ||
| 84 | assertOptions: assertOptions, | ||
| 85 | validators: validators | 88 | export default { |
| 89 | assertOptions, | ||
| 90 | validators | ||
| 86 | }; | 91 | }; |
@@ -1,5 +1,6 @@ | |||
| 1 | # Reporting a Vulnerability | 1 | # Reporting a Vulnerability |
| 2 | 2 | ||
| 3 | If you discover a security vulnerability within axios, please submit a report via [huntr.dev](https://huntr.dev/bounties/?target=https%3A%2F%2Fgithub.com%2Faxios%2Faxios). Bounties and CVEs are automatically managed and allocated via the platform. | 3 | If you discover a security vulnerability in axios please disclose it via [our huntr page](https://huntr.dev/repos/axios/axios/). Bounty eligibility, CVE assignment, response times and past reports are all there. |
| 4 | 4 | ||
| 5 | All security vulnerabilities will be promptly addressed. | 5 | |
| 6 | Thank you for improving the security of axios. | ||
@@ -0,0 +1,88 @@ | |
| 1 | import gulp from 'gulp'; |
| 2 | import fs from 'fs-extra'; |
| 3 | import axios from './index.js'; |
| 4 | |
| 5 | gulp.task('default', async function(){ |
| 6 | console.log('hello!'); |
| 7 | }); |
| 8 | |
| 9 | const clear = gulp.task('clear', async function() { |
| 10 | await fs.emptyDir('./dist/') |
| 11 | }); |
| 12 | |
| 13 | const bower = gulp.task('bower', async function () { |
| 14 | const npm = JSON.parse(await fs.readFile('package.json')); |
| 15 | const bower = JSON.parse(await fs.readFile('bower.json')); |
| 16 | |
| 17 | const fields = [ |
| 18 | 'name', |
| 19 | 'description', |
| 20 | 'version', |
| 21 | 'homepage', |
| 22 | 'license', |
| 23 | 'keywords' |
| 24 | ]; |
| 25 | |
| 26 | for (let i = 0, l = fields.length; i < l; i++) { |
| 27 | const field = fields[i]; |
| 28 | bower[field] = npm[field]; |
| 29 | } |
| 30 | |
| 31 | await fs.writeFile('bower.json', JSON.stringify(bower, null, 2)); |
| 32 | }); |
| 33 | |
| 34 | async function getContributors(user, repo, maxCount = 1) { |
| 35 | const contributors = (await axios.get( |
| 36 | `https://api.github.com/repos/${encodeURIComponent(user)}/${encodeURIComponent(repo)}/contributors`, |
| 37 | { params: { per_page: maxCount } } |
| 38 | )).data; |
| 39 | |
| 40 | return Promise.all(contributors.map(async (contributor)=> { |
| 41 | return {...contributor, ...(await axios.get( |
| 42 | `https://api.github.com/users/${encodeURIComponent(contributor.login)}` |
| 43 | )).data}; |
| 44 | })) |
| 45 | } |
| 46 | |
| 47 | const packageJSON = gulp.task('package', async function () { |
| 48 | const CONTRIBUTION_THRESHOLD = 3; |
| 49 | |
| 50 | const npm = JSON.parse(await fs.readFile('package.json')); |
| 51 | |
| 52 | try { |
| 53 | const contributors = await getContributors('axios', 'axios', 15); |
| 54 | |
| 55 | npm.contributors = contributors |
| 56 | .filter( |
| 57 | ({type, contributions}) => type.toLowerCase() === 'user' && contributions >= CONTRIBUTION_THRESHOLD |
| 58 | ) |
| 59 | .map(({login, name, url}) => `${name || login} (https://github.com/${login})`); |
| 60 | |
| 61 | await fs.writeFile('package.json', JSON.stringify(npm, null, 2)); |
| 62 | } catch (err) { |
| 63 | if (axios.isAxiosError(err) && err.response && err.response.status === 403) { |
| 64 | throw Error(`GitHub API Error: ${err.response.data && err.response.data.message}`); |
| 65 | } |
| 66 | throw err; |
| 67 | } |
| 68 | }); |
| 69 | |
| 70 | const env = gulp.task('env', async function () { |
| 71 | var npm = JSON.parse(await fs.readFile('package.json')); |
| 72 | |
| 73 | await fs.writeFile('./lib/env/data.js', Object.entries({ |
| 74 | VERSION: npm.version |
| 75 | }).map(([key, value]) => { |
| 76 | return `export const ${key} = ${JSON.stringify(value)};` |
| 77 | }).join('\n')); |
| 78 | }); |
| 79 | |
| 80 | const version = gulp.series('bower', 'env', 'package'); |
| 81 | |
| 82 | export { |
| 83 | bower, |
| 84 | env, |
| 85 | clear, |
| 86 | version, |
| 87 | packageJSON |
| 88 | } |