@@ -145,26 +145,25 @@ const DEFAULTS: RequiredOptions<Payload> = {
145
145
onJSON : ( json ) => json ,
146
146
}
147
147
148
- function defaultSerialize ( input : SearchParams ) : URLSearchParams {
148
+ function serialize ( input : SearchParams ) : URLSearchParams {
149
149
const params = new URLSearchParams ( )
150
150
151
- for ( const key of Object . keys ( input ) ) {
152
- if ( Array . isArray ( input [ key ] ) ) {
153
- // @ts -expect-error checked the variable inside if statement
154
- input [ key ] . forEach ( ( item ) => params . append ( key , item ) )
155
- } else {
151
+ for ( const [ key , value ] of Object . entries ( input ) ) {
152
+ if ( Array . isArray ( value ) ) {
153
+ value . forEach ( ( item ) => params . append ( key , item ) )
154
+ } else if ( value != null ) {
156
155
params . append ( key , input [ key ] )
157
156
}
158
157
}
159
158
160
159
return params
161
160
}
162
161
163
- function mergeMaps < Init , Request extends URLSearchParams | Headers > (
162
+ const mergeMaps = < Init , Request extends URLSearchParams | Headers > (
164
163
M : new ( init ?: Init ) => Request ,
165
164
left ?: Init ,
166
165
right ?: Init
167
- ) : Request {
166
+ ) : Request => {
168
167
const result = new M ( left )
169
168
170
169
new M ( right ) . forEach ( ( value , key ) => result . append ( key , value ) )
@@ -173,12 +172,12 @@ function mergeMaps<Init, Request extends URLSearchParams | Headers>(
173
172
}
174
173
175
174
const normalizeParams = (
176
- serialize : Serialize = defaultSerialize ,
175
+ transform : Serialize = serialize ,
177
176
params : SearchParams | URLSearchParams | string = ''
178
177
) =>
179
178
typeof params === 'string' || params instanceof URLSearchParams
180
179
? params
181
- : serialize ( params )
180
+ : transform ( params )
182
181
183
182
const mergeOptions = < A extends Options < Payload > , B extends Options < Payload > > (
184
183
left : A ,
@@ -255,9 +254,11 @@ function request<P extends Payload>(
255
254
. then ( options . onResponse )
256
255
. then ( options . onSuccess , options . onFailure ) as ResponsePromise < P >
257
256
258
- for ( const key of Object . keys ( CONTENT_TYPES ) as Array < keyof BodyMethods > ) {
257
+ for ( const [ key , value ] of Object . entries ( CONTENT_TYPES ) as Array <
258
+ [ keyof BodyMethods , string ]
259
+ > ) {
259
260
promise [ key ] = ( ) => {
260
- options . headers . set ( 'accept' , CONTENT_TYPES [ key ] )
261
+ options . headers . set ( 'accept' , value )
261
262
return promise
262
263
. then ( ( result ) => ( key === 'void' ? undefined : result . clone ( ) [ key ] ( ) ) )
263
264
. then ( ( parsed ) => ( key === 'json' ? options . onJSON ( parsed ) : parsed ) )
@@ -309,7 +310,7 @@ export {
309
310
ResponseError ,
310
311
TimeoutError ,
311
312
Serialize ,
312
- defaultSerialize as serialize ,
313
+ serialize ,
313
314
request ,
314
315
create ,
315
316
get ,
0 commit comments