mirror of
https://github.com/tenrok/axios.git
synced 2026-05-15 11:59:42 +03:00
feat: export getAdapter function (#5324)
This commit is contained in:
@@ -523,6 +523,7 @@ declare namespace axios {
|
||||
isAxiosError<T = any, D = any>(payload: any): payload is AxiosError<T, D>;
|
||||
toFormData(sourceObj: object, targetFormData?: GenericFormData, options?: FormSerializerOptions): GenericFormData;
|
||||
formToJSON(form: GenericFormData|GenericHTMLFormElement): object;
|
||||
getAdapter(adapters: AxiosAdapterConfig | AxiosAdapterConfig[] | undefined): AxiosAdapter;
|
||||
AxiosHeaders: typeof AxiosHeaders;
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+3
@@ -512,6 +512,8 @@ export interface GenericHTMLFormElement {
|
||||
submit(): void;
|
||||
}
|
||||
|
||||
export function getAdapter(adapters: AxiosAdapterConfig | AxiosAdapterConfig[] | undefined): AxiosAdapter;
|
||||
|
||||
export function toFormData(sourceObj: object, targetFormData?: GenericFormData, options?: FormSerializerOptions): GenericFormData;
|
||||
|
||||
export function formToJSON(form: GenericFormData|GenericHTMLFormElement): object;
|
||||
@@ -538,6 +540,7 @@ export interface AxiosStatic extends AxiosInstance {
|
||||
isAxiosError: typeof isAxiosError;
|
||||
toFormData: typeof toFormData;
|
||||
formToJSON: typeof formToJSON;
|
||||
getAdapter: typeof getAdapter;
|
||||
CanceledError: typeof CanceledError;
|
||||
AxiosHeaders: typeof AxiosHeaders;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ const {
|
||||
AxiosHeaders,
|
||||
HttpStatusCode,
|
||||
formToJSON,
|
||||
getAdapter,
|
||||
mergeConfig
|
||||
} = axios;
|
||||
|
||||
@@ -37,5 +38,6 @@ export {
|
||||
AxiosHeaders,
|
||||
HttpStatusCode,
|
||||
formToJSON,
|
||||
getAdapter,
|
||||
mergeConfig
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import AxiosError from './core/AxiosError.js';
|
||||
import spread from './helpers/spread.js';
|
||||
import isAxiosError from './helpers/isAxiosError.js';
|
||||
import AxiosHeaders from "./core/AxiosHeaders.js";
|
||||
import adapters from './adapters/adapters.js';
|
||||
import HttpStatusCode from './helpers/HttpStatusCode.js';
|
||||
|
||||
/**
|
||||
@@ -78,6 +79,8 @@ axios.AxiosHeaders = AxiosHeaders;
|
||||
|
||||
axios.formToJSON = thing => formDataToJSON(utils.isHTMLForm(thing) ? new FormData(thing) : thing);
|
||||
|
||||
axios.getAdapter = adapters.getAdapter;
|
||||
|
||||
axios.HttpStatusCode = HttpStatusCode;
|
||||
|
||||
axios.default = axios;
|
||||
|
||||
@@ -16,6 +16,7 @@ import axios, {
|
||||
ParamsSerializerOptions,
|
||||
toFormData,
|
||||
formToJSON,
|
||||
getAdapter,
|
||||
all,
|
||||
isCancel,
|
||||
isAxiosError,
|
||||
@@ -570,6 +571,33 @@ axios.get('/user', {
|
||||
adapter: ['xhr', 'http']
|
||||
});
|
||||
|
||||
|
||||
{
|
||||
// getAdapter
|
||||
|
||||
getAdapter(axios.create().defaults.adapter);
|
||||
getAdapter(undefined);
|
||||
getAdapter([]);
|
||||
getAdapter(['xhr']);
|
||||
getAdapter([adapter]);
|
||||
getAdapter(['xhr', 'http']);
|
||||
getAdapter([adapter, 'xhr']);
|
||||
getAdapter([adapter, adapter]);
|
||||
getAdapter('xhr');
|
||||
getAdapter(adapter);
|
||||
const _: AxiosAdapter = getAdapter('xhr');
|
||||
const __: AxiosAdapter = getAdapter(['xhr']);
|
||||
|
||||
// @ts-expect-error
|
||||
getAdapter();
|
||||
// @ts-expect-error
|
||||
getAdapter(123);
|
||||
// @ts-expect-error
|
||||
getAdapter([123]);
|
||||
// @ts-expect-error
|
||||
getAdapter('xhr', 'http');
|
||||
}
|
||||
|
||||
// AxiosHeaders
|
||||
|
||||
// iterator
|
||||
|
||||
@@ -54,6 +54,10 @@ describe('static api', function () {
|
||||
it('should have mergeConfig properties', function () {
|
||||
expect(typeof axios.mergeConfig).toEqual('function');
|
||||
});
|
||||
|
||||
it('should have getAdapter properties', function () {
|
||||
expect(typeof axios.getAdapter).toEqual('function');
|
||||
});
|
||||
});
|
||||
|
||||
describe('instance api', function () {
|
||||
|
||||
@@ -24,6 +24,7 @@ describe('instance', function () {
|
||||
'getUri',
|
||||
'isAxiosError',
|
||||
'mergeConfig',
|
||||
'getAdapter',
|
||||
'VERSION',
|
||||
'default',
|
||||
'toFormData',
|
||||
|
||||
Reference in New Issue
Block a user