axios-miniprogram/src/request/transformURL.ts

19 lines
666 B
TypeScript
Raw Normal View History

import { isPlainObject } from '../helpers/isTypes';
2023-03-28 21:32:54 +08:00
import { buildURL } from '../helpers/buildURL';
import { combineURL } from '../helpers/combineURL';
import { dynamicURL } from '../helpers/dynamicURL';
2023-03-28 21:32:54 +08:00
import { isAbsoluteURL } from '../helpers/isAbsoluteURL';
2023-04-21 18:09:32 +08:00
import { AxiosRequestConfig } from '../core/Axios';
2023-03-23 20:09:00 +08:00
2023-04-09 15:20:10 +08:00
export function transformURL(config: AxiosRequestConfig) {
2023-03-23 20:09:00 +08:00
let url = config.url ?? '';
2023-04-01 23:11:55 +08:00
if (!isAbsoluteURL(url)) url = combineURL(config.baseURL ?? '', url);
2023-04-21 18:09:32 +08:00
const data = isPlainObject(config.data) ? config.data : {};
url = dynamicURL(url, config.params, data);
2023-03-23 20:09:00 +08:00
url = buildURL(url, config.params, config.paramsSerializer);
return url;
}