fetch-switcher

1.0.1 • Public • Published

fetch-switcher

GitHub Repo stars Node.js CI npm Coverage Status

An utility dispatching to multiple implementations of fetch() depending on the URL scheme.

Installation

npm install fetch-switcher

Usage

import { fetchSwitcher } from 'fetch-switcher'
// or
const { fetchSwitcher } = require('fetch-switcher')

// assuming you have multiple fetch() implementations
const fetchGeneric = ...
const fetchFile = ...
const fetchFtp = ...

const fetch = fetchSwitcher({
  '': fetchGeneric, // '' is the default
  'file': fetchFile,
  'ftp': fetchFtp
})

fetch('http://example.com') // will dispatch to fetchGeneric
fetch('https://example.com') // will also dispatch to fetchGeneric
fetch('file:///example.txt') // will dispatch to fetchFile
fetch('ftp://exampleftp.com') // will dispacth to fetchFtp

Compatibility

fetch-switcher has no dependencies and is simple enough that it should work on all browsers and Node versions. (Which may of course not the case of the fetch() implementations you choose to use.)

Changelog

The changelog.

Contribution Guide

The contribution guide

License

The license.

Package Sidebar

Install

npm i fetch-switcher

Weekly Downloads

2

Version

1.0.1

License

MIT

Unpacked Size

14.7 kB

Total Files

7

Last publish

Collaborators

  • nicolas-van