1.0.2 • Published 8 months ago
w-common-methods v1.0.2
说明
安装
npm i w-common-methods
引入
ES6引入,如下:
import w from 'w-common-methods'
内置方法如下
方法名:w.togglePCCCodeToName
接收参数:String:code 对应省 市 县行政编码 如:110000
Boolean:isReturnSuperior 是否返回上级行政区 true返回 false不返回(默认)
方法名:w.getAreaTime
/**
* 获取当月一号至当日区间时间段
* 如果当前为1号则返回上月一号至最后一号
* 如果当前为1号并且为1月份则返回上一年的12月1日至最后一日
* @returns {Array} [yyyy-MM-dd,yyyy-MM-dd]
*/
方法名:w.getMonthBefore
/**
* @description {
* 基于当前时间获取前n月的时间,
* 参数n不可传入过大,传入小于等于12的数字
* }
*
* @param {Number} n:获取前n月的时间,默认为1(前一月)
*
* @returns {String}yyyy-MM
*/
方法名:w.handleDate
/**
* @description {
* 将时间戳转换成年月日时分秒
* }
*
* @param {*}time:时间戳
* @param {Boolean}isHMS:是否返回时分秒,true返回,false只返回年月日
*
* @returns {String} yyyy-MM-dd || yyyy-MM-dd hh:mm:ss
*/
方法名:w.downloadFileBlob
/**
* 下载文件
* @param {String} path - 文件地址
* @param {String} name - 文件名,eg: test.png
*/
方法名:w.downloadFileBase64
/**
* 下载文件
* @param {String} path - 文件地址
* @param {String} name - 文件名,eg: test.png
*/
方法名:w.downloadXls
/**
* 下载excel
* @param {blob} fileArrayBuffer 文件流
* @param {String} filename 文件名称,eg:text.xls/text.xlsx
*/
方法名:w.downloadFile
/**
* 文件流转blob对象下载
* @param {blob} res 文件流
* @param {String} filename 如果有自定义的文件名则采用自定义的文件名,没有则采用后台返回的文件名
从content-disposition中读取后台返回的文件名
*/
//校验方法
方法名:w.validateURL
/**
*
* @description {校验合法url}
*
* @param {*} testUrl:校验的url
*
* @returns {Boolean}
*/
方法名:w.validateEmail
/**
*
* @description {校验合法邮箱}
*
* @param {*} email:校验的邮箱
*
* @returns {Boolean}
*/
方法名:w.isvalidatemobile
/**
*
* @description {校验手机号}
*
* @param {*} phone:校验的手机号
*
* @returns {Boolean}
*/
方法名:w.isMobile
/**
*
* @description {校验电话号}
*
* @param {*} s:校验的电话号
*
* @returns {Boolean}
*/
方法名:w.validateLowerCase
/**
*
* @description {校验小写字母}
*
* @param {*} str:校验的小写字母
*
* @returns {Boolean}
*/
方法名:w.validateUpperCase
/**
*
* @description {校验大写字母}
*
* @param {*} str:校验的大写字母
*
* @returns {Boolean}
*/
方法名:w.validatAlphabets
/**
*
* @description {校验大小写字母}
*
* @param {*} str:校验的大小写字母
*
* @returns {Boolean}
*/
方法名:w.vaildatePc
/**
*
* @description {校验是否是PC端}
*
*
* @returns {Boolean}
*/
方法名:w.cardid
/**
*
* @description {校验身份证号}
* @param {*} code:校验的身份证号
*
* @returns {Boolean}
*/
方法名:w.validatenum
/**
*
* @description {校验是否为整数或小数}
* @param {*} num:校验的数
* @param {*} type:1 校验的小数,2 校验整数
*
* @returns {Boolean}
*/
方法名:w.validatenull
/**
*
* @description {判断是否为空,基本数据类型和引用数据类型}
* @param {*} val
*
* @returns {Boolean}
*/
方法名:w.typeOf
/**
*
* @description {校验数据类型}
* @param {*} params
*
* @returns string || number || boolean || array || object || undefined || null || function || date
*/
// 常用方法
方法名:w.hideMobile
/**
*
* @description {手机号脱敏}
* @param {*} mobile
*
* @returns 例:135****0303
*/
方法名:w.turnCase
/**
*
* @description {转大小写字母}
* @param {String} str
* @param {Number} type 1:全大写 2:全小写 3:首字母大写
*
* @returns
*/
方法名:w.uuid
/**
*
* @description {生成uuid}
*
* @returns {String}
*/
方法名:w.debounce
/**
*
* @desc 函数防抖
* @param func 回调函数
* @param delay 延迟执行毫秒数
*/
方法名:w.throttle
/**
* @desc 函数节流
* @param func 回调函数
* @param limit 时间限制
*/