1 | 'use strict';
|
---|
2 |
|
---|
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 | import AxiosHeaders from "./core/AxiosHeaders.js";
|
---|
18 | import adapters from './adapters/adapters.js';
|
---|
19 | import HttpStatusCode from './helpers/HttpStatusCode.js';
|
---|
20 |
|
---|
21 | /**
|
---|
22 | * Create an instance of Axios
|
---|
23 | *
|
---|
24 | * @param {Object} defaultConfig The default config for the instance
|
---|
25 | *
|
---|
26 | * @returns {Axios} A new instance of Axios
|
---|
27 | */
|
---|
28 | function createInstance(defaultConfig) {
|
---|
29 | const context = new Axios(defaultConfig);
|
---|
30 | const instance = bind(Axios.prototype.request, context);
|
---|
31 |
|
---|
32 | // Copy axios.prototype to instance
|
---|
33 | utils.extend(instance, Axios.prototype, context, {allOwnKeys: true});
|
---|
34 |
|
---|
35 | // Copy context to instance
|
---|
36 | utils.extend(instance, context, null, {allOwnKeys: true});
|
---|
37 |
|
---|
38 | // Factory for creating new instances
|
---|
39 | instance.create = function create(instanceConfig) {
|
---|
40 | return createInstance(mergeConfig(defaultConfig, instanceConfig));
|
---|
41 | };
|
---|
42 |
|
---|
43 | return instance;
|
---|
44 | }
|
---|
45 |
|
---|
46 | // Create the default instance to be exported
|
---|
47 | const axios = createInstance(defaults);
|
---|
48 |
|
---|
49 | // Expose Axios class to allow class inheritance
|
---|
50 | axios.Axios = Axios;
|
---|
51 |
|
---|
52 | // Expose Cancel & CancelToken
|
---|
53 | axios.CanceledError = CanceledError;
|
---|
54 | axios.CancelToken = CancelToken;
|
---|
55 | axios.isCancel = isCancel;
|
---|
56 | axios.VERSION = VERSION;
|
---|
57 | axios.toFormData = toFormData;
|
---|
58 |
|
---|
59 | // Expose AxiosError class
|
---|
60 | axios.AxiosError = AxiosError;
|
---|
61 |
|
---|
62 | // alias for CanceledError for backward compatibility
|
---|
63 | axios.Cancel = axios.CanceledError;
|
---|
64 |
|
---|
65 | // Expose all/spread
|
---|
66 | axios.all = function all(promises) {
|
---|
67 | return Promise.all(promises);
|
---|
68 | };
|
---|
69 |
|
---|
70 | axios.spread = spread;
|
---|
71 |
|
---|
72 | // Expose isAxiosError
|
---|
73 | axios.isAxiosError = isAxiosError;
|
---|
74 |
|
---|
75 | // Expose mergeConfig
|
---|
76 | axios.mergeConfig = mergeConfig;
|
---|
77 |
|
---|
78 | axios.AxiosHeaders = AxiosHeaders;
|
---|
79 |
|
---|
80 | axios.formToJSON = thing => formDataToJSON(utils.isHTMLForm(thing) ? new FormData(thing) : thing);
|
---|
81 |
|
---|
82 | axios.getAdapter = adapters.getAdapter;
|
---|
83 |
|
---|
84 | axios.HttpStatusCode = HttpStatusCode;
|
---|
85 |
|
---|
86 | axios.default = axios;
|
---|
87 |
|
---|
88 | // this module should only have a default export
|
---|
89 | export default axios
|
---|