Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

strap-trousers

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

strap-trousers

#### 🐣 strap-trousers

latest
npmnpm
Version
1.1.5
Version published
Maintainers
1
Created
Source

🐣

Strap-Trousers🍼


npm package & npm package

npm package npm package

基本模块

🐣 strap-trousers npm package

说明

在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动态参数 的方法即可
    

Keywords

ID

FAQs

Package last updated on 15 Mar 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts