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 🙏

© 2025 – Pkg Stats / Ryan Hefner

strap-trousers

v1.1.5

Published

#### 🐣 <a href="https://www.npmjs.com/package/strap-trousers">strap-trousers</a> <a><img src="https://badgen.net/npm/v/strap-trousers" alt="npm package"></a>

Readme


基本模块

🐣 strap-trousers

说明

在strap-trousers中 connectStraw模块用于解决、减轻在项目中api请求封装遇到的问题和时间,同时让请求封装不再繁琐 同时,在strap-trousers/common/mixComputing中也有分类好常用的js计算方法


基本使用

安装

npm | pnpm

$ npm i strap-trousers

yarn

$ yarn add strap-trousers

使用 StrawPlus

import axios from "axios";
import { connectStraw, ConnectStrawPlus, Debounce, Post, Get, Res } from "strap-trousers"

/**
 * @ConnectStrawPlus 装饰器
 * 用于创建请求模块
*/
@ConnectStrawPlus({
    lib: axios,
    name: "test",
    rootUrl: 'http://localhost:8202/',
    headers: {
        'Token': 'test_token',
    },
})
class Test {
    /**防抖*/
    @Debounce()
    /**Post请求*/
    @Post('/user/login')
    static Login(e: {
        [key: string]: any
    }) {
        /** 用于收集返回Promise类型*/
        return Res<{
            data: any
        }>()
    }

    /**Get请求*/
    @Get('/user/list')
    static List() {
        return Res<{
            data: any
        }>()
    }

}

使用 StrawApi

import { connectStraw } from "strap-trousers";
import axios from "axios"
const test = connectStraw({
    config: {
        //使用请求库
        lib: axios,
        name: "test",
        rootUrl: 'http://127.0.0.1:8202/',
    },
    action: {
        //函数写法
        list1: () => ({
            url: 'user/list',
            method: "GET",
        }),
          //对象写法
        list2: {
            url: 'user/list',
            debounce: true,
            method: "GET",
            //Typescript工程下 api.object会继承fn()的出入参类型
            fn() {
                return {} as {
                    data: string
                    value: string
                }
            }
        }
    }
})

(async function(){
    const res1 = test.list1()
    const res2 = test.list2()
})()

更新情况

  • 2024-11-04

      ✨增加 
          | 【StrawPlus】模块
              使用装饰器实现接口
              
  • 2024-07-08

      ✨增加 
          | 【test】模块
          | 统一使用package.json的version
  • 2024-06-08

      🦄重构 
          |【straw】中请求体使用iife方式,减少请求判断,优化请求实际执行速度
            
  • 2024-04-29

      🐞修复 
          | 修复小程序使用【straw】时地址拼接不完整问题
          | 修复小程序使用【straw】时没有合并请求参数问题
  • 2024-04-25

      🦄重构 优化项目结构
          | 关闭冗余导出
          | 增加部分描述
          | 原functions移动至common
  • 2024-03-28

      ✨增加 【strawApi】 返回值:实例、参数、缓存池
      🐞修复 【strawApi】 当请求失败时,没有删除当前请求缓存
  • 2024-02-18

      🐞修复 【strawApi】 公共data不生效问题
         | 增加部分描述
  • 2024-02-02

      ✨ 测试 Fetch
      ✨ 修改StrawApi拦截器
      ✨ 修改EaseApi拦截器
  • 2024-01-15

      🦄 refactor(抽离Axios)
      🦄 refactor(抽离小程序适配器)
      ✨ feat(【StrawApi】) : 相比easeApi,更好地对输入类型支持。写法略有不同
  • 2023-08-31

       1:修复使用 axios 请求时,没有拼接传入的params
       2:增加 axios 动态 header 、 params。
       使用时在createConnect中的 header|params 中需要动态数据的参数中
       传一个return动态参数 的方法即可