1.2.1 • Published 3 years ago
lgr-tools v1.2.1
lgr-tools
介绍
一款自建的 JavaScript
工具函数库
安装
yarn add lgr-tools -S
# 或者
npm i lgr-tools -S
使用
import { checkCommonMobile } from 'lgr-tools'
checkCommonMobile(13966992456)
或者
const lgrTools = require('lgr-tools')
lgrTools.checkCommonMobile(13966992456)
第三方库的使用
dayjs
用法同dayjs一样
import { dayjs } from 'lgr-tools'
const year = dayjs().isoWeekYear()
const info = `
当前是${year}年,
${dayjs().isLeapYear() ? '闰年' : '平年'},
当前的时间是${dayjs().format('YYYY-MM-DD HH:mm:ss')},
根据ISO week标准,${year}年有${dayjs().isoWeeksInYear()}个周,${dayjs().format('YYYY-MM-DD')}是第${dayjs().isoWeek()}周中的第${dayjs().isoWeekday()}天
`
console.log(info)
注意,暂时只支持
dayOfYear
、isoWeeksInYear
、isLeapYear
、isoWeek
几个插件
方法
树形操作
- 平铺树形结构treeToList()
- 为树形结构设置层级arrayTreeSetLevel()
数组
- 深克隆 deepClone()
- 数组去重 unique()
- 数组对象递归平铺 getNodeChild()
校验
- 校验1开头的11位手机号码 checkCommonMobile()
- 手机号码正则 checkMobile()
- 15位和18位身份证号码验证 checkID()
- 去字符串的首尾空格 trim()
- 判断移动端还是PC端 browserAndMobile()
- 是否微信端 isWeixin()
- 是否微博 isWeiBo
- 是否
QQ
isQQ() - 是否
iPhone
isIphone() - 是否
Android
isAndroid() - 判断一个对象是否是空对象 isEmptyObject()
cookie操作
- 根据
name
读取Cookie
getCookie() - 设置
Cookie
setCookie() - 根据
name
删除Cookie
removeCookie()
日期
- 获取某年某个月的最后一天 getMonthLastDay()
节流防抖
- 防抖 debounce()
- 节流 throttle()
DOM操作
- 是否有某个
class
hasClass() - 添加
class
addClass() - 移除
class
removeClass()
业务工具函数库
- 根据图片的
url
下载图片 downLoadImgByUrl() - 二进制流文件
excel
下载 downLoadFile() - 生成
uuid
uuid() - 手机号码脱敏
phoneEncrypt
phoneEncrypt()