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

yhl-request

v0.2.13

Published

yaohanlin

Downloads

313

Readme

yhlRequest

// 支持自定义属性,必须以$开头
type Params = {
  baseURL?: string // 根路径
  timeout?: number // 超时时间   默认3s
  headers?: false | AxiosRequestConfig['headers'] // 请求头

  // 【1】设置当前请求参数的参数 用于做判断动态设置不同参数
  ___setCurrentParams?: (method: Method, url: string, data: AnyObj, params: Params, axiosConfig: AxiosRequestConfig) => Params

  // 【2】基础数据 //! 仅参数为Object生效
  _baseData?: false | AnyObj
  // 【3】基础数据回调 //! 仅返回为Object生效
  __getBaseDataFn?: false | ((method: Method, url: string, data: AnyObj, params: Params, axiosConfig: AxiosRequestConfig) => Promise<AnyObj>)

  // 【4】请求前回调
  __requestBeforeFn?:
    | false
    | ((
        method: Method,
        url: string,
        data: AnyObj,
        params: Params,
        axiosConfig: AxiosRequestConfig
      ) => AndPromise<void | {
        method?: Method // 可能被修改的请求方法
        url?: string // 可能被修改的请求URL
        data?: AnyObj // 可能被修改的请求数据
        params?: Params // 可能被修改的请求参数
        axiosConfig?: AxiosRequestConfig // 可能被修改的Axios配置
      }>)

  // 【5】设置token方法支持async
  __getTokenFn?:
    | false
    | ((
        method: Method,
        url: string,
        data: AnyObj,
        params: Params,
        axiosConfig: AxiosRequestConfig
      ) => AndPromise<void | {
        data?: AnyObj // 登录参数
        headers?: AxiosRequestConfig['headers'] // 登录header
      }>)

  // 【6】删除参数中值为undefined的参数
  _removeUndefined?: boolean

  // 【7】缓存用户标识
  __getCacheUserTag?: () => string
  // 【8】缓存时间 单位ms
  _isCache?: false | number
  // 【9】缓存存储位置 默认['indexedDB','sessionStorage']//! 必须设置 _isCache 默认缓存
  _cacheDateStore?: ('indexedDB' | 'sessionStorage' | 'localStorage' | 'window')[]
  // 【21】判断是否需要缓存 //! 必须设置 _isCache 默认缓存
  _isCacheFn?: false | ((res: any) => Promise<void | boolean>)

  // 【10】是否开启防抖
  _debounce?: boolean
  // 【11】防抖时间  默认 500ms
  _debounceTime?: number

  // 【12】中断请求的 source
  _source?: CancelTokenSource

  // 【13】请求前最后一次回调 // 加密,验签
  __requestBeforeMiddleFn?:
    | false
    | ((
        method: Method,
        url: string,
        data: AnyObj,
        params: Params,
        axiosConfig: AxiosRequestConfig
      ) => AndPromise<void | {
        method?: Method // 可能被修改的请求方法
        url?: string // 可能被修改的请求URL
        data?: AnyObj // 可能被修改的请求数据
        params?: Params // 可能被修改的请求参数
        axiosConfig?: AxiosRequestConfig // 可能被修改的Axios配置
      }>)

  // 【14】请求随机数时间戳
  _rid?: boolean

  // 【15】post请求表单提交
  _isUpLoad?: boolean

  //! 开始发送请求

  // 【16】是否将相应的Number转成String  默认false
  _Number2String?: boolean

  // 【17】http请求失败提示
  __failHttpToastFn?: false | ((error: AxiosError, method: Method, url: string, data: AnyObj, params: Params, axiosConfig: AxiosRequestConfig) => void)

  // 【18】不需要返回结果
  _noReturn?: boolean

  // 【19】请求后第一次回调-返回数据将作为新的数据向后传递 // 解密,验签
  __requestAfterMiddleFn?:
    | false
    | ((res: ResType, method: Method, url: string, data: AnyObj, params: Params, axiosConfig: AxiosRequestConfig) => AndPromise<void | ResType>)

  // 【20】请求后参数校验,可做相关提示   需要返回检查结果
  __requestReturnCodeCheckFn?:
    | false
    | ((res: any, method: Method, url: string, data: AnyObj, params: Params, axiosConfig: AxiosRequestConfig) => AndPromise<boolean>)

  // 【22】请求后回调
  __requestAfterFn?:
    | false
    | ((
        type: 'success' | 'fail',
        res: any,
        method: Method,
        url: string,
        data: AnyObj,
        params: Params,
        axiosConfig: AxiosRequestConfig
      ) => AndPromise<void | any>)

  // 【23】处理返回数据
  __handleResponseFn?: false | ((res: any) => any)
  // 【24】是否返回全部数据
  _responseAll?: boolean

  [key: `$${string}`]: any
}