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

@hucy_hucy/axios-wrapper

v0.0.4

Published

create a axios wrapper function for request cache and intercept repeat request

Downloads

2

Readme

用例

import { AxiosWrapper } from '@hucy_hucy/axios-wrapper';
import { ElLoading } from 'element-plus';
const service = new AxiosWrapper({
  baseURL: 'http://192.168.1.xyz',
  timeout: 15000,
  apiMap: []
});

// req.on('repeat')

const whiteList = ['login']

// 是否请求成功的检测函数,有默认值
// 检测请求成功后将会在适当的时候执行缓存操作
service.isRequestSuccess(function (response: AxiosResponse) {
  // 默认
  // return has(response.data, 'code') && response.data.code === 0
  return response.data && response.data.code === 200
})

service.injectHeader(function (apiConfig) {
  if (whiteList.includes(apiConfig.name)) return {}
  return {
    // 在请求前注入 Token
    Authorization: 'Bearer ' + getToken(),
    'Content-Type': get(config, 'headers.Content-Type', 'application/json')
  }
})

// 当 loading 为 true 时会执行
service.startLoading(function (apiConfig) {
  return ElLoading.service({
    lock: true,
    text: 'Loading',
    background: 'rgba(0, 0, 0, 0.7)',
  })
});

service.stopLoading(function (loadingInstance) {
  loadingInstance.close()
});

service.request('ApiName', {
  params: {},
  data: {},
  // 默认是 false, 不允许重复请求
  allowRepeat: true,
  // 默认是false, 不会进行缓存,可选的值有:
  // boolean | 'memory' | session | local
  // 其中:设置 true 等同于设置
  cache: 'memory',
  // 是否强制请求,为 true 时会无视缓存
  force: false,
  // 是否为请求前后添加全局 loading 动画
  loading: true // boolean
}).then((response) => {

});

重复请求如何处理 - PLAN

  1. 使用首次请求的接口,后续的请求全部忽略,后续接口会得到首次请求的返回数据
  2. 使用最后一次请求的接口,前面的所有请求都取消掉,只有最后一次请求会返回数据