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

xmiot-net

v1.4.16

Published

喜马声联网net封装

Readme

xmiot-net

安装

 npm i --save xmiot-net

用法

  1. 引入
import axios from 'axios'
import Net from 'xmiot-net'
const axiosInstance = axios.create()

/*
* 第一个参数为axios实例
* 第二个参数为布尔值,表示是否可以重复相同请求
*/
const net = new Net(axiosInstance, true)
  1. Hook

xmiot-net的事件流机制参考tapable的Hook事件机制,事件支持异步和同步

waterfallHook:

const hook = new WaterfallHook('name')

hook.listen((name, stop) => { console.log(name) })

hook.listen(async (name, stop) => {
    console.log(name + 'test')
    stop()
    return name + 'test'
})

hook.listen((name) => {console.log('can not be printed')})

hook.run('luka')

print: luka lukatest
  1. 拦截
拦截队列:
1. pre队列:请求发起前的拦截队列
2. postSuccess:响应成功的拦截队列
3. postError:响应失败的拦截队列

/*
 * 请求拦截层
 * config: axios配置信息
 * stop: 跳出链式调用,使用会取消后面的pre回调,以及和与该事件绑定的post回调
 * 返回的config会传递给下一个事件,如果返回undefined,则返回之前的传递值
 */ 
net.pre((config, stop) => {
  // your code here
  return config
})

/*
 * 成功响应拦截层
 * response: axios响应信息
 * stop: 跳出链式调用,使用会取消后面postSuccess的回调
 * 返回的response会传递给下一个事件,如果返回undefined,则返回之前的传递值
 */ 
net.postSuccess((response, stop) => {
  // your code here
  return response
})

/*
 * 失败响应拦截层
 * err: axios错误信息
 * stop: 跳出链式调用,使用会取消后面postError的回调
 * 返回的err会传递给下一个事件,如果返回undefined,则返回之前的传递值
 */ 
net.postError((err, stop) => {
  // your code here
  return err
})

/*
 * 注意
 * 拦截支持链式调用
 */
net.pre().postSuccess().postError()
  1. 缓存
/*
 * 缓存
 * url: string 要缓存的地址
 * method: fuction 方法
 * timeout: number 过期时间,
 * ignoreParams: string[] 无视的参数,
 * ignoreData: string[] 无视的payload
 */
net.onCache({url, method, timeout, ignoreParams, ignoreData})
  1. 请求重发配置

如果需要对某个接口的失败做重发,可以使用重发配置

/*
 * url: 要重发的地址
 * method: 方法
 * times: 如果失败需要尝试几次
 */
 net.onResend({url, method, times})
  1. mock

对接口进行mock

/*
 * 初始化baseURLs
 * baseURLs: 请求地址的base地址,一般填写axios中base即可
 */
 net.mockBase(...baseURLs)

/*
 * mock请求get
 * url: 要请求的url,是baseURL的相对地址
 * body: 包含的参数,一般是data或者params
 * code: 状态码
 * response: 响应
 * options.delay: 延迟
 * options.errorMessage: 错误信息
 */
net.get(url, body).reply(code, response, options)

/*
 * 单次mock请求get
 */
net.get(url, body).replyOnce(code, response, options)

/*
 * 其他mock请求
 */
net.post
net.put
net.delete

/*
 * mock的链式调用
 */
net.get('/a').replyOnce(200, {}, {delay: 3000})
  .get('/a').reply(400, {}, {errorMessage: 'error'})

###注意事项 不要再拦截器中返回非config/response/err的其他值,会产生不可控影响