| | 'use strict'; |
| |
|
| | import utils from '../utils.js'; |
| | import AxiosURLSearchParams from '../helpers/AxiosURLSearchParams.js'; |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | function encode(val) { |
| | return encodeURIComponent(val). |
| | replace(/%3A/gi, ':'). |
| | replace(/%24/g, '$'). |
| | replace(/%2C/gi, ','). |
| | replace(/%20/g, '+'). |
| | replace(/%5B/gi, '['). |
| | replace(/%5D/gi, ']'); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | export default function buildURL(url, params, options) { |
| | |
| | if (!params) { |
| | return url; |
| | } |
| | |
| | const _encode = options && options.encode || encode; |
| |
|
| | if (utils.isFunction(options)) { |
| | options = { |
| | serialize: options |
| | }; |
| | } |
| |
|
| | const serializeFn = options && options.serialize; |
| |
|
| | let serializedParams; |
| |
|
| | if (serializeFn) { |
| | serializedParams = serializeFn(params, options); |
| | } else { |
| | serializedParams = utils.isURLSearchParams(params) ? |
| | params.toString() : |
| | new AxiosURLSearchParams(params, options).toString(_encode); |
| | } |
| |
|
| | if (serializedParams) { |
| | const hashmarkIndex = url.indexOf("#"); |
| |
|
| | if (hashmarkIndex !== -1) { |
| | url = url.slice(0, hashmarkIndex); |
| | } |
| | url += (url.indexOf('?') === -1 ? '?' : '&') + serializedParams; |
| | } |
| |
|
| | return url; |
| | } |
| |
|