@gyw123/utils
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

axiosRequest

axios请求封装

  • GET
import {get} from "@ninggure/utils/axiosRequest";
// 请求链接
const url = "http://xxxx.com";
// 参数
const params = {
    a: 1
}
// 请求头, 可以不设置
const headers = {}
// 响应内容格式, 可以不设置,默认为json
const responseType = "json";
get(url, params, headers, responseType)
  • POST
import {post} from "@ninggure/utils/axiosRequest";
// 请求链接
const url = "http://xxxx.com";
// 参数
const data = {
    a: 1
}
// 请求头, 可以不设置
const headers = {}
// 响应内容格式, 可以不设置,默认为json
const responseType = "json";
post(url, params, headers, responseType)
  • 上传文件(POST)
import {uploadFile} from "@ninggure/utils/axiosRequest";
// 请求链接
const url = "http://xxxx.com";
// 参数
const data = {
    file
}
// 请求头, 可以不设置
const headers = {}
// 响应内容格式, 可以不设置,默认为json
const responseType = "json";
uploadFile(url, params, headers, responseType)

deepClone

深拷贝对象或数组

  • depthDeepClone(深度遍历深拷贝)
import {depthDeepClone} from "@ninggure/utils/deepClone";

const a = {test: 1, test2: 2, test3: {
    test: 1
}}
// 深拷贝一个a对象
const newA = depthDeepClone(a);
console.log(a === newA) // false
  • breadthDeepClone(广度遍历深拷贝)
import {breadthDeepClone} from "@ninggure/utils/deepClone";
const a = {test: 1, test2: 2, test3: {
    test: 1
}}
// 深拷贝一个a对象
const newA = breadthDeepClone(a);
console.log(a === newA) // false

fileList

遍历目录里面的所有内容

  • getDepthFileList(深度遍历)
const {getDepthFileList} = require("@ninggure/utils/fileList");
const dirPath = "xxxx";
getDepthFileList(dirPath)
  • getBreadthFileList(广度遍历)
const {getBreadthFileList} = require("@ninggure/utils/fileList");
const dirPath = "xxxx";
getBreadthFileList(dirPath)

Readme

Keywords

none

Package Sidebar

Install

npm i @gyw123/utils

Weekly Downloads

1

Version

1.0.4

License

ISC

Unpacked Size

34.9 kB

Total Files

25

Last publish

Collaborators

  • gyw123