123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- '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;
- 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;
- }
|