0.9.16-alpha • Published 4 years ago

jt-utils v0.9.16-alpha

Weekly downloads
-
License
MIT
Repository
-
Last release
4 years ago

jtutil 工具类

快速入门

npm安装:

npm i jt-utils --save

使用说明

// 方式一
const  utils = require('jt-utils');

// 方式二

const  { http ,date} = require('jt-utils');

cookie 模块

本模块即支持浏览器也支持node环境

  • cookie.set(name, value, time)

    name: cookie 的名字. value : cookie 的值. time: cookie存储时间(按天计算)

  • cookie.get(name)

    name: cookie 的名字.

  • cookie.remove(name)

    name: cookie 的名字.

localStorage 模块

本模块只支持浏览器模式,因为node环境下不支持

  • localStorage.set(name,content)

  • localStorage.get(name)

  • localStorage.delete(name)

date 模块

本模块即支持浏览器也支持node环境

  • date.formatPassTime(startTime)

    可计算此时离目标时间的差距

  • date.formatTime(time, fmt = 'yyyy-MM-dd hh:mm:ss')

    格式化时间

tools 模块

  • deepCopyBy(data) 深拷贝
  • deepCopy(data) JSON 深拷贝
  • checkType(str, type) 正则检测 以下type可选: - ip - port - phone - number - email - IDCard - url

  • formatPhone(phone) 将手机号中间部分替换为星号

  • debounce(func, wait) 防抖
  • throttle(func, wait) 节流
  • getType(obj) 类型检测

http 模块

基于axios ,对axios的二次封装

  • init 方法
//  初始化方法
 jtutil.http.init({
            url: 'http://localhost:8888/',
            timeout: 20000,
            withCredentials: false,
});
  • isInterceptor 方法
jtutil.http.isInterceptor(false)

此方法是开启拦截器的功能,默认为true,开启封装的拦截器,对请求进行简单的拦截 如果你想增加一些复杂的逻辑,可以关闭为false。 当为false的时候,我们会给你返回一个拦截对象,你可以接收他,并进行自我的拦截封装。

    const Interceptor =  jtutil.http.isInterceptor(false);
  • Get 方法

  • Post 方法

  • Put 方法

  • Delete 方法

random 模块

  • get 方法

    jtutil.random.get(0,1)

    随机得到一定范围的整数

  • getArrayItem 方法

jtutil.random.getArrayItem([1,2,3])

随机得到目标数组的数据

0.9.16-alpha

4 years ago

0.9.14-bate

4 years ago

0.9.13-bate

4 years ago

0.9.12-bate

4 years ago

0.9.11-bate

4 years ago

0.9.8-bate

4 years ago