Socket
Socket
Sign inDemoInstall

@js-bits/fetch

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@js-bits/fetch

Cross-environment (nodejs/web) fetch API


Version published
Weekly downloads
139
increased by12.1%
Maintainers
1
Weekly downloads
 
Created
Source

Cross-environment (nodejs/web) fetch APi

This package exports window.fetch object in a browser and node-fetch module in a Node.js environment. Which is helpful when you develop a package compatible with both environments and use fetch for HTTP requests. Allows to avoid conditional imports.

Also exports AbortController (abort-controller module for Node.js) for both environments.

Installation

Install with npm:

npm install @js-bits/fetch

Install with yarn:

yarn add @js-bits/fetch

Import where you need it:

import { fetch, AbortController } from '@js-bits/fetch';

How to use

fetch('http://example.com/movies.json')
  .then(response => response.json())
  .then(data => console.log(data));

Notes

  • The package versions are aligned with node-fetch versions.
  • CommonJS module export removed since version 3
  • version 2 of this package supports version 2 of node-fetch.
  • Minimal size (bytes) in a browser since Fetch API is natively supported. Does not include any polyfills, which means that Internet Explorer is not supported.

Keywords

FAQs

Package last updated on 27 Mar 2022

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc