![Namecheap Takes Down Polyfill.io Service Following Supply Chain Attack](https://cdn.sanity.io/images/cgdhsj6q/production/6af25114feaaac7179b18127c83327568ff592d1-1024x1024.webp?w=800&fit=max&auto=format)
Security News
Namecheap Takes Down Polyfill.io Service Following Supply Chain Attack
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
@fetch-impl/fetcher
Advanced tools
Readme
Can be used as a global fetch implementation or as a local fetch implementation specific to a package.
The default fetch implementation is globalThis.fetch
. Which works in almost all modern environments (browsers, Node.js, Deno, Cloudflare Workers, etc).
import fetch from "@fetch-impl/fetcher";
// use fetch as usual
fetch("https://example.com").then(async (res) => {
console.log(res.status, await res.text());
});
You can replace the default fetch implementation with a custom one using fetcher.set
:
import fetch, { fetcher } from "@fetch-impl/fetcher";
// configure fetch to use a custom fetch implementation
fetcher.set(async (...args) => {
return new Response("Hello, World!", { status: 200 });
});
// use fetch as usual, but it will use the custom fetch implementation and always return "Hello, World!"
fetch("https://example.com").then(async (res) => {
console.log(res.status, await res.text());
});
If you are a package author and want to let your users configure the fetch implementation, you can use Fetcher
to create a configurable local fetch implementation:
// add a fetch.ts file like this to your package
import { Fetcher } from "@fetch-impl/fetcher";
export const fetcher = new Fetcher();
export const fetch = (...args) => fetcher.fetch(...args);
export default fetch;
// and use your own fetch implementation like this
import fetch from "./fetch";
// use fetch as usual
export async function makeRequest(url: string): Promise<string> {
const res = await fetch(url);
return res.text();
}
// don't forget to re-export the fetcher instance so that your users can configure the fetch implementation
export * from "./fetch";
Your users can then configure the fetch implementation like this:
import { makeRequest, fetcher } from "your-package";
import { useCrossFetch } from "@fetch-impl/cross-fetch";
// user configure fetch to use a custom fetch implementation
useCrossFetch(fetcher);
// user use makeRequest as usual, but it will use the custom fetch implementation
makeRequest("https://example.com").then((text) => {
console.log(text);
});
FAQs
User Configurable Fetch Implementation.
The npm package @fetch-impl/fetcher receives a total of 58 weekly downloads. As such, @fetch-impl/fetcher popularity was classified as not popular.
We found that @fetch-impl/fetcher demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.
Security News
A JavaScript library maintainer is under fire after merging a controversial PR to support legacy versions of Node.js.