1
1
import { HTTPMethod , Interceptors , ValueOf , RouteAndOptions } from './types'
2
- import { isObject , invariant , isBrowser , isString } from './utils'
2
+ import { invariant , isBrowser , isString , isBodyObject } from './utils'
3
3
4
4
const { GET } = HTTPMethod
5
5
@@ -14,11 +14,11 @@ export default async function makeRouteAndOptions(
14
14
requestInterceptor ?: ValueOf < Pick < Interceptors , 'request' > >
15
15
) : Promise < RouteAndOptions > {
16
16
invariant (
17
- ! ( isObject ( routeOrBody ) && isObject ( bodyAs2ndParam ) ) ,
17
+ ! ( isBodyObject ( routeOrBody ) && isBodyObject ( bodyAs2ndParam ) ) ,
18
18
`If first argument of ${ method . toLowerCase ( ) } () is an object, you cannot have a 2nd argument. 😜` ,
19
19
)
20
20
invariant (
21
- ! ( method === GET && isObject ( routeOrBody ) ) ,
21
+ ! ( method === GET && isBodyObject ( routeOrBody ) ) ,
22
22
`You can only have query params as 1st argument of request.get()` ,
23
23
)
24
24
invariant (
@@ -33,15 +33,15 @@ export default async function makeRouteAndOptions(
33
33
} ) ( )
34
34
35
35
const body = ( ( ) : BodyInit | null => {
36
- if ( isObject ( routeOrBody ) ) return JSON . stringify ( routeOrBody )
37
- if ( isObject ( bodyAs2ndParam ) ) return JSON . stringify ( bodyAs2ndParam )
36
+ if ( isBodyObject ( routeOrBody ) ) return JSON . stringify ( routeOrBody )
37
+ if ( isBodyObject ( bodyAs2ndParam ) ) return JSON . stringify ( bodyAs2ndParam )
38
38
if (
39
39
isBrowser &&
40
40
( ( bodyAs2ndParam as any ) instanceof FormData ||
41
41
( bodyAs2ndParam as any ) instanceof URLSearchParams )
42
42
)
43
43
return bodyAs2ndParam as string
44
- if ( isObject ( initialOptions . body ) ) return JSON . stringify ( initialOptions . body )
44
+ if ( isBodyObject ( initialOptions . body ) ) return JSON . stringify ( initialOptions . body )
45
45
return null
46
46
} ) ( )
47
47
0 commit comments