1919 * @property {Headers } [headers] Request headers
2020 * @property {FormData|string|object } [body] a body, optionally encoded, to send
2121 * @property {'text'|'json'|'stream'|'blob'|'arrayBuffer'|'formData'|'stream' } [responseType="text"] An encoding to use for the response
22+ * @property {Record<string,any>|URLSearchParams } [params] querystring parameters
23+ * @property {(params: Options['params']) => string } [paramsSerializer] custom function to stringify querystring parameters
2224 * @property {boolean } [withCredentials] Send the request with credentials like cookies
2325 * @property {string } [auth] Authorization header value to send with the request
2426 * @property {string } [xsrfCookieName] Pass an Cross-site Request Forgery prevention cookie value as a header defined by `xsrfHeaderName`
@@ -78,31 +80,19 @@ export default (function create(/** @type {Options} */ defaults) {
7880 return ( url , data , config ) => redaxios ( url , Object . assign ( { method, data } , config ) ) ;
7981 }
8082
81- /**
82- * Builds request url based on query string parameters
83- * @private
84- * @param {string } url
85- * @param {object|URLSearchParams } [params]
86- * @param {function } [serializer]
87- * @returns {string }
88- */
89- function buildUrl ( url , params , serializer ) {
90- if ( ! params ) {
91- return url ;
92- }
93-
94- let serializedParams ;
95- if ( serializer ) {
96- serializedParams = serializer ( params ) ;
97- } else if ( params instanceof URLSearchParams ) {
98- serializedParams = params . toString ( ) ;
99- } else {
100- serializedParams = ( new URLSearchParams ( params ) ) . toString ( ) ;
101- }
102-
103- const divider = url . indexOf ( '?' ) === - 1 ? '?' : '&' ;
104- return url + divider + serializedParams ;
105- }
83+ // /**
84+ // * Builds request url based on query string parameters
85+ // * @private
86+ // * @param {string } url
87+ // * @param {Record<string,string>|URLSearchParams } [params]
88+ // * @param {function } [serializer]
89+ // * @returns {string }
90+ // */
91+ // function buildUrl(url, params, serializer) {
92+ // const serializedParams = serializer ? serializer(params) : new URLSearchParams(params);
93+ // const divider = ~url.indexOf('?') ? '&' : '?';
94+ // return url + divider + serializedParams;
95+ // }
10696
10797 /**
10898 * @public
@@ -188,12 +178,21 @@ export default (function create(/** @type {Options} */ defaults) {
188178 url = config . url ;
189179 }
190180
181+ const userConfig = /** @type {Options } */ ( config || { } ) ;
182+
183+ const response = /** @type {Response<any> } */ ( { config : userConfig } ) ;
184+
191185 /**
192186 * @type {Options }
193187 */
194- const options = deepMerge ( defaults , config || { } ) ;
188+ const options = deepMerge ( defaults , userConfig ) ;
189+
195190 let data = options . data ;
196- url = buildUrl ( url , options . params , options . paramsSerializer ) ;
191+
192+ /**
193+ * @type {{'Content-Type':'application/json';Authorization: string} & Headers }
194+ */
195+ const customHeaders = { } ;
197196
198197 if ( options . transformRequest ) {
199198 for ( let i = 0 ; i < options . transformRequest . length ; i ++ ) {
@@ -204,12 +203,6 @@ export default (function create(/** @type {Options} */ defaults) {
204203 }
205204 }
206205
207- const fetchFunc = options . fetch || fetch ;
208- /**
209- * @type {{'Content-Type':'application/json';Authorization: string} & Headers }
210- */
211- const customHeaders = { } ;
212-
213206 if ( data && typeof data === 'object' && typeof data . append !== 'function' ) {
214207 data = JSON . stringify ( data ) ;
215208 customHeaders [ 'Content-Type' ] = 'application/json' ;
@@ -233,9 +226,15 @@ export default (function create(/** @type {Options} */ defaults) {
233226 url = new URL ( url , options . baseURL ) + '' ;
234227 }
235228
236- /** @type {Response<any> } */
237- const response = { } ;
238- response . config = /** @type {Options } */ ( config ) ;
229+ if ( options . params ) {
230+ const divider = ~ url . indexOf ( '?' ) ? '&' : '?' ;
231+ const query = options . paramsSerializer
232+ ? options . paramsSerializer ( options . params )
233+ : new URLSearchParams ( options . params ) ;
234+ url += divider + query ;
235+ }
236+
237+ const fetchFunc = options . fetch || fetch ;
239238
240239 return fetchFunc ( url , {
241240 method : options . method ,
0 commit comments