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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@krabby/axios

v0.0.9

Published

- 带中间件的axios,在axios基础上添加before、success、error三个中间件 - 使用 ```js import axios from '@krabby/axios'

Readme

  • 带中间件的axios,在axios基础上添加before、success、error三个中间件
  • 使用
import axios from '@krabby/axios'

function before(config) {
    console.log("before")
    return config
}

function success(res) {
    console.log("success")
    let { data } = res || {}
    return data
}

function error(err) {
    console.log("error")
    return err
}

const app = axios.create(
    { before, success, error }
)

app.get('http://baidu.com')

每次请求依次挂载请求前、成功、失败三个钩子,用于自定义返回体、token处理、全局loading等等

如有自定义情况,则在请求时也可指定此三个钩子,此时会替换掉默认钩子

function cuError(err) {
    console.log("cuError")
    return 1
}

app.get('http://baidu.com',{error:cuError})

同时支持数组类型中间件传入,同步方法依次执行,异步方法并行执行

async function cuSuccess1(res) {
    console.log("cuSuccess1")
    return "ok1"
}


async function cuSuccess2(res) {
    console.log("cuSuccess2")
    return "ok2"
}
app.get("http://baidu.com", {success:[cuSuccess1,cuSuccess2]})

以下是完整的demo

import axios,{TAxiosRequestConfig,AxiosResponse, AxiosError} from '@krabby/axios'


function before(config) {
    console.log("before")
    return config
}

function success(res) {
    console.log("success")
    let { data } = res || {}
    return data
}

function error(err) {
    console.log("error")
    return err
}

function cuBefore(config) {
    console.log("cuBefore")
    config.url = "http://baidu.com"
    return config
}


function cuSuccess(res) {
    console.log("cuSuccess")
    return "ok"
}


async function cuSuccess1(res) {
    console.log("cuSuccess1")
    return "ok1"
}


async function cuSuccess2(res) {
    console.log("cuSuccess2")
    return "ok2"
}

function cuError(err) {
    console.log("cuError")
    throw new Error(err.message)
}
function cuError1(err) {
    console.log("cuError1")
}
function cuError2(err) {
    console.log("cuError2")
}

const app = axios.create(
    { before, success, error }
)

async function test() {
    console.debug("\r\n------默认正确返回")
    await app.get("http://baidu.com", {})
    
    console.debug("\r\n------默认错误返回")
    await app.get("http://baidu.co", {})
    const config = { success: cuSuccess, error: cuError }

    console.debug("\r\n------自定义正确返回")
    let data = await app.get("http://baidu.com", config)
    console.info("data",data)

    console.debug("\r\n------自定义错误返回(不阻塞)")
    await app.get("http://baidu.co", {before:cuBefore})

    console.debug("\r\n------自定义错误返回(不阻塞顺序执行正确)")
    data = await app.get("http://baidu.com", {success:[cuSuccess1,cuSuccess2]})
    console.info("data",data)

    console.debug("\r\n------自定义错误返回(不阻塞顺序执行错误)")
    await app.get("http://baidu.co", {error:[cuError1,cuError2]})

    console.debug("\r\n------自定义错误返回(阻塞)")
    await app.get("http://baidu.co", config)
}

test()