(fetchArgs: unknown[])
| 254 | * Exported for tests only. |
| 255 | */ |
| 256 | export function parseFetchArgs(fetchArgs: unknown[]): { method: string; url: string } { |
| 257 | if (fetchArgs.length === 0) { |
| 258 | return { method: 'GET', url: '' }; |
| 259 | } |
| 260 | |
| 261 | if (fetchArgs.length === 2) { |
| 262 | const [resource, options] = fetchArgs as [FetchResource, object]; |
| 263 | |
| 264 | return { |
| 265 | url: getUrlFromResource(resource), |
| 266 | method: hasProp(options, 'method') |
| 267 | ? String(options.method).toUpperCase() |
| 268 | : // Request object as first argument |
| 269 | isRequest(resource) && hasProp(resource, 'method') |
| 270 | ? String(resource.method).toUpperCase() |
| 271 | : 'GET', |
| 272 | }; |
| 273 | } |
| 274 | |
| 275 | const arg = fetchArgs[0]; |
| 276 | return { |
| 277 | url: getUrlFromResource(arg as FetchResource), |
| 278 | method: hasProp(arg, 'method') ? String(arg.method).toUpperCase() : 'GET', |
| 279 | }; |
| 280 | } |
| 281 | |
| 282 | function getHeadersFromFetchArgs(fetchArgs: unknown[]): WebFetchHeaders | undefined { |
| 283 | const [requestArgument, optionsArgument] = fetchArgs; |
no test coverage detected