11ty/eleventy-fetch

Support passing an `URL` instance

groenroos opened this issue ยท 1 comments

It'd be handy if fetch() could also accept a URL instance as the source;

const url = new URL('...');
const data = await fetch(url);

Currently this throws an error:

TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received an instance of URL

Using URL to generate the source URL can be a common use case, in case you need to safely add query parameters, or control the base/host of the request between environments.

I know it's an easy fix to use url.toString() instead, but it can be a gotcha - it'd be a nifty ergonomic improvement if this was handled automagically!

v5.0 will support anything that can be converted via toString ๐Ÿ‘๐Ÿป