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 🙏

© 2024 – Pkg Stats / Ryan Hefner

axios-merge

v1.0.11

Published

axios-merge is an axios helper library for merging identical requests.

Downloads

11

Readme

axios-merge

Description

axios-merge is an axios helper library for merging identical requests. The library provides the following features:

  1. merge identical requests; subsequent requests will be merged into the preceding request, preserving the result of the preceding request.
  2. identical-requests-cancel; the preceding request will be cancelled and the result of the subsequent request will be kept.

Usage

Packaged build

npm run build
npm pack

Install

// node
npm install axios-merge --save

// browser
<script src="axios-merge/dist/index.min.js">

parameter signature

/**
 * Create merge helper function example
 * @params { axiosinstance } axiosInstance axios instance
 * @params { function } [customerAdaptar] axios custom adapter
 **/
const axiosmerge = new AxiosMerge(axiosInstance, customerAdaptar)

/**
 * @params { object } config request configuration, same as axios native configuration
 * @params { boolean } config.checkParams checks if the same request checks for parameters default true
 * @params { string } config.strategy set the processing strategy when this request is repeated. USE_FIRST keep the first result, USE_LAST keep the last result, USE_TUNNEL use the current result, default is USE_TUNNEL
 * @params { boolean } config.distributionResponse Distribute the final response to all identical requests, default is true
 * @params { function } config.cancelFn Optional parameters. function to cancel the request Note: This parameter only takes effect when strategy=USE_LAST https://axios-http.com/zh/docs/cancellation
 * @params { AxiosCancenToken } config.cancelToken Optional parameters. The beacon to cancel the request Note: This parameter only takes effect when strategy=USE_LAST https://axios-http.com/zh/docs/cancellation
 **/
instance.request(config)
instance.get(url[, config])
instance.delete(url[, config])
instance.head(url[, config])
instance.options(url[, config])
instance.post(url[, data[, config]])
instance.put(url[, data[, config]])
instance.patch(url[, data[, config]])

Create an instance

import axios from "axios";
import AXiosMerge, { strategy } from "axios-merge";

const instance = axios.create({ baseURL: "/" });
const axiosmerge = new AxiosMerge(instance);
// const axiosmerge = new AxiosMerge(axios)

Use within request interceptors

const CancelToken = axios;

instance.interceptors.request.use(
  function (config) {
    let fn = null;
    const cancelToken = new CancelToken((cancel) => {
      fn = cancel;
    });
    config.cancelToken = cancelToken; // beacon to cancel the request
    config.cancelFn = fn; // cancel function
    config.strategy = strategy.USE_FIRST; // USE_LAST USE_TUNNEL
    // do something before sending the request
    return config;
  },
  function (error) {
    // What to do about request errors
    return Promise.reject(error);
  }
);