npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

fetch-js-wrapper

v0.1.8

Published

fetch-js-wrapper was designed to be used as a lightweight, drop-in replacement for axios when using the native Fetch API

Readme

fetch-js-wrapper

fetch-js-wrapper was designed to be used as a lightweight, drop-in replacement for axios when using the native Fetch API. fetch-js-wrapper aims to do as little as possible but provides some of the basic functionality we're used to from libraries such as axios.

Usage

Basic

Below are some example usages. These are not complete examples, these are intended to demonstrate how you could use the library.

For all available options see options

// Basic HTTP request

import FetchWrapper from './index.js';

const http = new FetchWrapper( {
    baseURL: 'https://api.example.com'
} );

const response = await http.get( '/example/endpoint' );

if ( !response.ok ) {
    // Handle it
}

const something = await response.json();

// Use it

Utilising Middleware

// Use middleware for JWT authentication

import FetchWrapper from './index.js';

const http = new FetchWrapper( {
    baseURL: 'https://api.example.com'
} );

http.use( ( request ) => {
    // Get the token from somewhere and set the header
    const accessToken = localStorage.getItem( 'accessToken' );

    request.headers[ 'Authorization' ] = accessToken;

    return request;
}, 'before' );

http.use( async ( response, request ) => {
    if ( response.status === 401 ) {
        
        const refreshResponse = fetch( '/refresh', {
            headers: {
                'Authorization': localStorage.getItem( 'refreshToken' )
            }
        } );

        if ( !refreshResponse.ok ) {
            // Handle it...
        }

        const tokens = await refreshResponse.json();
        localStorage.setItem( 'accessToken', tokens.access );
        localStorage.setItem( 'refreshToken', tokens.refresh );

        // Retry the original request that failed...
        return http.request( response.url, request );
    }

    return response;
}, 'after' );

const response = await http.get( '/example/endpoint' );

// Do what you need to do

Available Options

Below are all of the options available when creating a new instance of FetchWrapper. Pass a single object to the constructor.

| Key | Type | Default Value | Description | |--- |--- |--- |--- | baseURL | String | "" | A URL to prefix all relative requests with. | | | | |

Example of passing options

new FetchWrapper( {
    baseURL: 'https://api.example.com'
} );

Installing

Using npm:

$ npm install fetch-js-wrapper

Browser Support

If you need to support older browsers that do not natively support ES6 (classes, let, const etc.) you can import index.min.js, see our package.json for browserlist support configuration.

The main bundle comes as-is, i.e. without polyfills, not transpiled or minified in anyway. If you need any of these feature please submit as a feature request or pull request, or feel free to fork the repository and make the changes you require!

Running the tests

Coming soon!

And coding style tests

We use ESLint for managing code style. See .eslintrc for the complete configuration.

Contributing

Coming soon!

Authors

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowledgments

  • Thanks axios for the inspiration!