# utils **Repository Path**: quitelinxd/utils ## Basic Information - **Project Name**: utils - **Description**: js工具类 - **Primary Language**: JavaScript - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2022-11-11 - **Last Updated**: 2025-03-12 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 本工具类纯个人及团队整理,用于团队项目开发 ## 默认导出 utils `import utils from 'linxd-utils'` ### 以下为工具类api 按模块分类 ### 1. index 方法名 | 说明 | 参数 ---- | ----- | ------ `utils.uuid()` | 返回 36 位uuid函数 string 类型 | - `utils.debounce()` | 函数节流方法 | func ``, wait ``, immediate `` ### 2. date 方法名 | 说明 | 参数 ---- | ----- | ------ `utils.date.formatDate()` | 返回格式化的时间 string 类型| 1.date 类型 2.返回的时间格式,默认`yyyy-MM-DD HH:MM:SS` ``类型 `utils.date.formatTime()` | 返回距离当前时间(刚刚,几分钟前,几小时前等) string 类型| (cellValue,type) 1.time `` 2.返回的时间格式 `yyyy-MM-DD HH:MM:SS 或 yyyy-MM-DD` `` `utils.date.getRelativeTime()` | 获取相对时间描述 | date `` `utils.date.dateAdd()` | 日期加减 | date ``, num ``, unit `` `utils.date.getDateRange()` | 获取日期范围 | type `` 'today'/'week'/'month'/'year' `utils.date.dateDiff()` | 计算日期差值 | date1 ``, date2 ``, unit `` `utils.date.isLeapYear()` | 判断是否闰年 | year `` `utils.date.getDaysInMonth()` | 获取月份天数 | year ``, month `` ### 3. number 方法名 | 说明 | 参数 ---- | ----- | ------ `utils.number.numberToString()` | 返回大写中文数字 string 类型 | num ` ` `utils.number.thousandSplit()` | 千位逗号分隔 返回类型 `` | str ` ` `utils.number.add()` | 精确加法 | num1 ``, num2 `` `utils.number.subtract()` | 精确减法 | num1 ``, num2 `` `utils.number.multiply()` | 精确乘法 | num1 ``, num2 `` `utils.number.divide()` | 精确除法 | num1 ``, num2 ``, precision `` `utils.number.round()` | 数字四舍五入 | num ``, precision `` `utils.number.clamp()` | 数字范围限制 | num ``, min ``, max `` ### 4. bower 方法名 | 说明 | 参数 ---- | ----- | ------ `utils.bower.httpToHttps()` | 返回 string | url ` ` `utils.bower.getParams()` | 返回 `` | key `` 要获取的参数 例: ('id') `utils.bower.getBowerType()` | 返回 浏览器类型 `` | -- ### 5. data 方法名 | 说明 | 参数 ---- | ----- | ------ `utils.data.treeDataformatter()` | 根据id和pid循环出树形结构的数据 | data ``, id `` 默认值为 `id` , pid `` 默认值为 `pid`, children `` 默认值为 `children` `utils.data.orderBy()` | 返回排序数组 | 基本类型数组 ` ` 正序 `asc` 或倒序 `desc` `utils.data.deleteSame()` | 返回去重后的数组(基本类型数组) | 基本类型数组 ` ` `utils.data.union()` | 返回两个数组的并集 | 基本类型数组 ` ` `utils.data.deleteSameByObj()` | 返回去重后的数组(list 套 map) | -- ### 6. file 方法名 | 说明 | 参数 ---- | ----- | ------ `utils.file.getFileNameExt()` | 返回文件名的后缀 | fileName `string` `utils.file.getFileName()` | 返回文件名 | fileName `string` `utils.file.isImageType()` | 判断是否为图片类型 返回值`` | fileName `string` `utils.file.isVideoType()` | 判断是否为视频类型 返回值`` | fileName `string` ### 7. reg 方法名 | 说明 | 参数 ---- | ----- | ------ `utils.reg.email()` | 正则验证 返回类型 `` | `` `utils.reg.mobile()` | 正则验证 返回类型 `` | `` `utils.reg.tel()` | 正则验证 返回类型 `` | `` `utils.reg.idCard()` | 正则验证 返回类型 `` | `` `utils.reg.ip()` | 正则验证 返回类型 `` | `` # 前端通用工具库 ## 安装