xf-tools

1.0.15 • Public • Published

工具函数集合

总结了自己工作中一些常用的工具函数,方便使用

安装

 npm install xf-tools  or yarn add xf-tools

使用

import Tools from 'xf-tools'

 默认从Tools下引入默认方法

 or

 import {xxx} from 'xf-tools'  // xxx: 方法名

example

console.log(Tools.formatDate(new Date(1632643437144)), "yyyy-MM-dd");

// 打印格式化后的时间

API

类型说明 方法名 example
通用类 `urlParse`:获取url后面的参数 urlParse(url:string)
selectRandomValue: 随机取min-max之间的值 selectRandomValue(min:number, max:number)
addNums: 数组求和(注意数组每一项为number) addNums(arr:number[]) // arr: [1,2,3]
compareArrayKey: 根据数组元素的某一项来排序 compareArrayKey(arr: []) // arr: [{name: 'zs', age: 3}]
日期类 `formatDate`:格式化时间戳 formatDate(date: new Date, fmt: any) //date: Date日期类型,fmt: 'yyyy-MM-dd'
下载类 `downFileBlob`:返回的文件流下载 downFileBlob(res: any, name?: any, type?: string) // res: 文件流;name: 文件名;文件格式:pdf或者word格式
downFileUrl: 根据url下载 downFileUrl(url: string, fileName: string) // url:url;fileName: 文件名字
打印类 `htmlPrint`:根据html打印文件 htmlPrint(id: any) // id:dom元素id
urlPrint: 根据url打印文件 urlPrint(url: any, isbase64?: boolean) // url: url; isbase64: 是否转换成base64打印,默认false;

Readme

Keywords

Package Sidebar

Install

npm i xf-tools

Weekly Downloads

3

Version

1.0.15

License

MIT

Unpacked Size

99.4 kB

Total Files

8

Last publish

Collaborators

  • wxfwill