1. isomorphic-unfetch
Switches between unfetch & node-fetch for client & server.
isomorphic-unfetch
Package: isomorphic-unfetch
Created by: developit
Last modified: Tue, 03 Jan 2023 02:29:58 GMT
Version: 4.0.2
License: MIT
Downloads: 11,246,745
Repository: https://github.com/developit/unfetch

Install

npm install isomorphic-unfetch
yarn add isomorphic-unfetch

Isomorphic Unfetch

Switches between unfetch & node-fetch for client & server.

Install

This project uses node and npm. Go check them out if you don't have them locally installed.

Note: This module uses node-fetch 3.x, which is ES Module and requires Node >= 12.20.0.

 $ npm i isomorphic-unfetch

Then with a module bundler like rollup or webpack, use as you would anything else:

 // using ES6 modules
import fetch from "isomorphic-unfetch";

// using CommonJS modules
const fetch = require("isomorphic-unfetch");

Usage

As a ponyfill:

 import fetch from "isomorphic-unfetch";

fetch("/foo.json")
  .then((r) => r.json())
  .then((data) => {
    console.log(data);
  });

Globally, as a polyfill:

 import "isomorphic-unfetch";

// "fetch" is now installed globally if it wasn't already available

fetch("/foo.json")
  .then((r) => r.json())
  .then((data) => {
    console.log(data);
  });

License

MIT License © Jason Miller

RELATED POST

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin