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

luck7-fetch

v0.2.3

Published

A tool to manage AJAX of project

Downloads

2

Readme

luck7-fetch

可以拥有统一配置的项目层面的对ajax的再封装,没有任何依赖,体积小巧(仅4.5kb,开启gzip压缩后仅2kb),使用简洁,可以同时存在多个

import L7Fetch from 'luck7-fetch'

// 创建ajax对象
const ajax = new L7Fetch(apiLists, ajaxConfigs, apiMethods)
// 使用ajax对象发起请求
ajax.do(apiName, params) // 没有请求参数的时候,params可以不写
  .then(res => {
    console.log(res)
  }).catch(err => {
    console.error(err)
  })

参数

  • apiLists

Array类型,api接口列表,格式为key: {method, url, options},支持简写

  • ajaxConfigs

Object类型,对ajax请求的配置(如headers、timeout等),用于对请求/返回数据进行处理,默认值如下

{
  baseURL: '/',
  lang: Object, // 错误提示文本
  isStrict: true // 是否开启严格模式
  options: { // 可参考fetch的配置,额外引入了timeout配置
    headers: {
      // ...
    },
    method: 'GET',
    timeout: 120000 // 单位毫秒
  } // 请求配置项
}

错误提示文本默认值

{
  noList: '配置错误: 缺少接口配置(list)',
  methodError: '配置错误: #apiName#请求类型异常#method#',
  urlError: '配置错误: #apiName#缺少请求地址(url)',
  typeError: '使用错误: 接口参数类型错误',
  noConfig: '使用错误: 接口#apiName#未配置',
  netError: '服务器错误: 状态码:#status#',
  paramError: '缺少URL参数#param#'
}
  • apiMethods

apiLists中的key对应,代表相应的api请求后的处理方法,格式如下

{
  key () { // key的唯一特例是'_',代表通用处理方法,将对所有未配置method的api生效
    return {
      request (req) { /* ... */ }, // 对request参数进行处理
      response (res) { return res }, // 对返回数据进行处理,返回处理后的数据
      error (err) {} // 对异常进行处理
    }
  }
}