fetch-with-file-support
Advanced tools
Comparing version 1.2.0 to 2.0.0
@@ -1,8 +0,2 @@ | ||
import { fetch as fetchUnbound } from "./index.node.js"; | ||
const fetch = fetchUnbound.bind({ | ||
fetch: globalThis.fetch, | ||
Request, | ||
Response, | ||
Headers, | ||
}); | ||
import { fetch } from "./index.node.js"; | ||
globalThis.fetch = fetch; |
@@ -1,6 +0,1 @@ | ||
export declare function fetch(this: undefined | any | { | ||
fetch: typeof globalThis.fetch; | ||
Request: typeof globalThis.Request; | ||
Response: typeof globalThis.Response; | ||
Headers: typeof globalThis.Headers; | ||
}, input: RequestInfo, init?: RequestInit | undefined): Promise<any>; | ||
export declare const fetch: typeof globalThis.fetch; |
@@ -1,4 +0,1 @@ | ||
export async function fetch(input, init = {}) { | ||
const { fetch = globalThis.fetch, Request = globalThis.Request, Response = globalThis.Response, Headers = globalThis.Headers, } = this ?? globalThis; | ||
return await fetch(input, init); | ||
} | ||
export const { fetch } = globalThis; |
@@ -1,6 +0,1 @@ | ||
export declare function fetch(this: undefined | any | { | ||
fetch: typeof globalThis.fetch; | ||
Request: typeof globalThis.Request; | ||
Response: typeof globalThis.Response; | ||
Headers: typeof globalThis.Headers; | ||
}, input: RequestInfo, init?: RequestInit | undefined): Promise<any>; | ||
export declare const fetch: typeof globalThis.fetch; |
@@ -1,4 +0,1 @@ | ||
export async function fetch(input, init = {}) { | ||
const { fetch = globalThis.fetch, Request = globalThis.Request, Response = globalThis.Response, Headers = globalThis.Headers, } = this ?? globalThis; | ||
return await fetch(input, init); | ||
} | ||
export const { fetch } = globalThis; |
@@ -1,6 +0,1 @@ | ||
export declare function fetch(this: undefined | any | { | ||
fetch: typeof globalThis.fetch; | ||
Request: typeof globalThis.Request; | ||
Response: typeof globalThis.Response; | ||
Headers: typeof globalThis.Headers; | ||
}, input: RequestInfo, init?: RequestInit | undefined): Promise<any>; | ||
export declare function fetch(input: RequestInfo, init?: RequestInit | undefined): Promise<Response>; |
import openAsBlob from "./lib/node-fs-openAsBlob.js"; | ||
const { fetch: globalThisFetch, Request, Response, Headers } = globalThis; | ||
export async function fetch(input, init = {}) { | ||
const { fetch = globalThis.fetch, Request = globalThis.Request, Response = globalThis.Response, Headers = globalThis.Headers, } = this ?? globalThis; | ||
const request = input instanceof Request && !init ? input : new Request(input, init); | ||
@@ -22,4 +22,4 @@ if (request.url.startsWith("file:")) { | ||
else { | ||
return await fetch(request); | ||
return await globalThisFetch(request); | ||
} | ||
} |
{ | ||
"name": "fetch-with-file-support", | ||
"version": "1.2.0", | ||
"version": "2.0.0", | ||
"description": "📂 fetch() but with support for file:///my/file.txt URLs", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -86,16 +86,2 @@ # `fetch()` with `file:` support | ||
If you want to bring your own `fetch()` implementation, you can bind the `this` | ||
context of the `fetch()` function to an object with `options.fetch`, | ||
`options.Request`, `options.Response`, and `options.Headers` properties. The | ||
implementation will use these instead of the globals. | ||
```js | ||
import * as undici from "undici"; | ||
import { fetch as fetchUnbound } from "fetch-with-file-support"; | ||
const fetch = fetchUnbound.bind(undici); | ||
const response = await fetch(new URL("./package.json", import.meta.url)); | ||
const json = await response.json(); | ||
``` | ||
🌎 If you prefer global polyfills, you can import | ||
@@ -102,0 +88,0 @@ `fetch-with-file-support/auto`. |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
1
7713
48
106