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

@shitou/tea-plus

v1.4.6

Published

ajax promise

Downloads

4

Readme

teaPlus 使用文档

安装

npm i @shitou/tea-plus --save-dev

使用

引用

import teaPlus from '@shitou/tea-plus'

使用api

  • GET方式
teaPlus
    .get(URL,config)
    .then(res => {
     		 console.log(res)
    })
    .catch(e => {
				console.log(e)
    })

teaPlus
	.delete(URL,config)

teaPlus
	.head(URL,config)

teaPlus
	.options(URL,config)
  • PLOS方式
teaPlus
    .post(URL,config)
    .then(res => {
     		 console.log(res)
    })
    .catch(e => {
				console.log(e)
    })

teaPlus
	.put(URL,config)

teaPlus
	.patch(URL,config)

Config配置参数

| 参数名字 | 类型 | 默认值 | 参数描述 | | --------------- | ------- | ------ | ----------------------------------------------- | | params | Object | null | 只给get方式请求传递参数试用可以不传 | | data | Object | null | 只给post方式请求传递参数试用可以不传 | | timeout | Number | 0 | 接口超时时间配置,以毫秒(ms)为单位 | | withCredentials | Boolean | False | 是否开启ajax跨域请求 | | headers | Object | {} | 配置请求头文件 | | cache | Boolean | true | 为false时自动在请求链接后面加入时间戳凡防止缓存 | | mark | Boolean | false | 为true时会自动配合 mark 打点 计算接口响应时间 |

返回参数详解

| 参数 | 类型 | 默认值 | 参数描述 | | -------------- | ------ | -------- | ---------------------------------- | | res | Object | null | 请求成功返回参数 | | res.data | Object | null | 接口返回的内容 | | res.status | Number | null | 接口返回的状态码 | | res.statusText | String | 空字符串 | 接口返回的与状态码相对应的状态消息 | | res.headers | Object | null | 接口返回的的头信息 | | res.config | Object | Object | 用户的config配置信息 | | res.request | Object | Object | XMLHttpRequest 对象 |

错误参数详解

| 参数 | 类型 | 默认 | 参数描述 | | ---------------- | ------- | -------- | ------------------------------------------------------------ | | e | String | 空字符串 | 错误信息内容 | | e.message | String | 空字符串 | 错误信息内容 | | e.config | Object | Object | 用户的config配置信息 | | e.code | Number | null | 接口返回的状态码 | | e.request | Object | null | XMLHttpRequest 对象 | | e.response | Object | null | XMLHttpRequest 对象 | | e.isTeaPlusError | Boolean | false | 是否是 timeout 网络异常 返回码不正常的 teaPlus内部错误的情况判断 |

其他使用方法

  • teaPlus.all:等同于promise.all

  • teaPlus.create:创建静态类

  • teaPlus.spread:等同于promise.spread分别获取 promise.all的结果

拦截器

// 添加一个请求拦截器
teaPlus
    .interceptors
    .request
    .use(function (config) {
      
        // 在发送请求之前可以做一些事情
        return config;
    }, function (error) {
        console.log(error)
        // 处理请求错误
        return Promise.reject(error);
    });

// 添加一个响应拦截器
teaPlus
    .interceptors
    .response
    .use(function (response) {
        console.log(222)
        // 处理响应数据
        return response;
    }, function (error) {
        // 处理响应错误
        return Promise.reject(error);
    });

兼容处理

因为低版本的浏览器不支持promise,本库的链式调用是基于原生promise,本库推荐使用es6-promise所兼容

安装地址:https://www.npmjs.com/package/es6-promise

可以用
require('es6-promise').polyfill();
或者
require('es6-promise/auto');
 

或者引用

<!-- Automatically provides/replaces `Promise` if missing or broken. -->
<script src="https://cdn.jsdelivr.net/npm/es6-promise@4/dist/es6-promise.js"></script>
<script src="https://cdn.jsdelivr.net/npm/es6-promise@4/dist/es6-promise.auto.js"></script> 
 
<!-- Minified version of `es6-promise-auto` below. -->
<script src="https://cdn.jsdelivr.net/npm/es6-promise@4/dist/es6-promise.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/es6-promise@4/dist/es6-promise.auto.min.js"></script>