@vhen2023/fs-helper
安装
npm install @vhen2023/fs-helper --save-dev 或者 pnpm add -D @vhen2023/fs-helper
import { convertToRMB, hideMobile, toCase, trim, dayjs } from '@vhen2023/fs-helper'
工具类
| 函数 | 举例 | 描述 |
|---|
| convertToRMB | convertToRMB(120) | 数字金额转化为大写金额 |
| hideMobile | hideMobile('15612345678') | 隐藏手机号 |
| toCase | toCase('test',3) | 大小写转化(1-大写,2-小写,3-首字母大写) |
| trim | trim(' t e s t ', 4) | 去除空格 (1-所有空格 2-前后空格 3-前空格 4-后空格) |
| LoadScript | LoadScript('test.ts', () => {}) | 异步加载 JS |
| padZero | padZero(1, 2) | 数字补位 001 |
| setObjToUrlParams | setObjToUrlParams('www.baidu.com', { a: 1, b: 2 }) | 将对象作为参数添加到 URL |
| setUrlParamsToObj | setUrlParamsToObj('www.baidu.com?a=1&b=2') | 将 URL 中的参数转为对象 |
| onlyDecimalOrInteger | onlyDecimalOrInteger('432.356',true) | 小数或整数(不可以负数) ,第二个参数控制是否四舍五入 |
| onlyInteger | onlyInteger('222') | 正整数 |
| randomRangeInteger | randomRangeInteger(10,30) | 在某个区间随机一个整数 |
| greetings | greetings() | 问候语:早中晚等 |
| thousandSeparator | thousandSeparator(1215455.1234, ',') | 千分位分隔符 |
时间类
import { toTimeFormat, getPastTime, getDateDiff, dayjs } from "@vhen2023/fs-helper";
| 函数 | 举例 | 描述 |
|---|
| toTimeFormat | toTimeFormat(new Date(),'YYYY-MM-DD HH:mm:ss') | 时间格式化默认:YYYY-MM-DD HH:mm:ss |
| getPastTime | getPastTime('2012-01-02 12:12:30', 2) | 过去日期(刚刚,几分钟之前等), 第二个参数为 0 不格式时间,否则 2 表示大于 2 年显示格式化时间 YYYY-MM-DD HH:mm:ss |
| getDateDiff | getDateDiff('2024-05-01', new Date(), 'day') | 判断相差天、月、年 ,类型:('day'、'months'、'years') |
| getZodiac | getZodiac(2024) | 生肖 |
验证类
| 函数 | 举例 | 描述 |
|---|
| isPhone | isPhone('19606066920') | 是否为手机号码 |
| isExternal | isExternal('www.baidu.com') | 是否是外部链接 |
| isUrl | isUrl('www.baidu.com') | 验证是否是 url |
| isImageUrl | isImageUrl('xxx.xxx.png') | 验证图片路径 |
| isIdCard | isIdCard('350423199906154973') | 验证是否是身份证号 |
@vhen2023/fs-helper持续更新,有需要拓展需求可以写在评论区