(url, params, options)
| 29 | * @returns {string} The formatted url |
| 30 | */ |
| 31 | export default function buildURL(url, params, options) { |
| 32 | if (!params) { |
| 33 | return url; |
| 34 | } |
| 35 | url = url || class="st">''; |
| 36 | |
| 37 | const _options = utils.isFunction(options) |
| 38 | ? { |
| 39 | serialize: options, |
| 40 | } |
| 41 | : options; |
| 42 | |
| 43 | class="cm">// Read serializer options pollution-safely: own properties and methods on a |
| 44 | class="cm">// class/template prototype are honored, but values injected onto a polluted |
| 45 | class="cm">// Object.prototype are ignored. |
| 46 | const _encode = utils.getSafeProp(_options, class="st">'encode') || encode; |
| 47 | const serializeFn = utils.getSafeProp(_options, class="st">'serialize'); |
| 48 | |
| 49 | let serializedParams; |
| 50 | |
| 51 | if (serializeFn) { |
| 52 | serializedParams = serializeFn(params, _options); |
| 53 | } else { |
| 54 | serializedParams = utils.isURLSearchParams(params) |
| 55 | ? params.toString() |
| 56 | : new AxiosURLSearchParams(params, _options).toString(_encode); |
| 57 | } |
| 58 | |
| 59 | if (serializedParams) { |
| 60 | const hashmarkIndex = url.indexOf(class="st">'#'); |
| 61 | |
| 62 | if (hashmarkIndex !== -1) { |
| 63 | url = url.slice(0, hashmarkIndex); |
| 64 | } |
| 65 | url += (url.indexOf(class="st">'?') === -1 ? class="st">'?' : class="st">'&') + serializedParams; |
| 66 | } |
| 67 | |
| 68 | return url; |
| 69 | } |
no test coverage detected