1.0.25 • Published 4 years ago
cafe-utils v1.0.25
Cafe-Utils
使用
NPM
npm i cafe-utils在项目中引用:
// 单独引用
import { uuid } from 'cafe-utils';
uuid();
// 整体引用
import * as cafeUtils from 'cafe-utils';
cafeUtils.uuid();CDN
<script src="https://unpkg.com/cafe-utils/lib/utils.umd.min.js"></script>
<!-- 或者 -->
<script src="https://cdn.jsdelivr.net/npm/cafe-utils/lib/utils.umd.min.js"></script>在项目中使用:
cafeUtils.uuid()Jest功能覆盖
| File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
|---|---|---|---|---|---|
| All files | 94.88 | 83.33 | 88.17 | 94.12 | |
| depend | 100 | 100 | 100 | 100 | |
| numToString.ts | 100 | 100 | 100 | 100 | |
| modules | 94.86 | 83.2 | 88.11 | 94.08 | |
| array.ts | 100 | 100 | 100 | 100 | |
| cookies.ts | 100 | 80 | 100 | 100 | 46-57 |
| date.ts | 100 | 100 | 100 | 100 | |
| dom.ts | 40 | 0 | 0 | 28.57 | 15-17,27,37-39,50-53 |
| event.ts | 30.77 | 7.69 | 22.22 | 28 | 16-27,42-49,64-71 |
| floatCalculate.ts | 100 | 100 | 100 | 100 | |
| index.ts | 100 | 100 | 86.25 | 100 | |
| money.ts | 98.51 | 94.59 | 100 | 98.36 | 115 |
| number.ts | 100 | 100 | 100 | 100 | |
| storage.ts | 100 | 100 | 100 | 100 | |
| string.ts | 100 | 94.29 | 100 | 100 | 71-90 |
| tools.ts | 100 | 97.5 | 100 | 100 | 90 |
| type.ts | 100 | 100 | 100 | 100 | |
| validator.ts | 100 | 100 | 100 | 100 |
现有方法
类型判断
isObject:判断对象类型isArray:判断数组类型isDate:判断日期类型isNumber:判断数字类型isString:判断字符串类型isBoolean:判断布尔类型isFunction:判断函数类型isNull:判断空类型
表单验证
isPhone:判断手机号isTel:判断固定电话isZIPCode:判断邮政编码isEmail:判断邮箱isIDCard:判断身份证isURL:判断URLisImg:判断图片格式isCar:判断车牌号码isIPV4/isIPV6:判断IP地址
字符串类
formatStr:格式化字符串toCamelCase:字符串转换为驼峰fromCamelCase:驼峰转字符串trim:去除空格escapeHTML:转义HTML字符串unescapeHTML:反转义HTMLstripHTMLTags:过滤HTML代码subGbString:截取字符,区分中英文getGbLen:判断字符长度,区分中英文changeCase:字符串写法转换
数组类
arrayMax:返回数组中的最大值arrayMin:返回数组中的最小值arrayChunk:切割数组flatten:指定扁平化数组deepFlatten:深度扁平化数组union:数组并集intersection:数组交集difference:数组差集initArrayFillValues:初始化并填充具有指定值的数组sample:返回数组中的随机元素
数字类
toFixed:浮点数保留格式randomIntegerInRange:返回指定范围内的随机整数randomNumberInRange:返回指定范围内的随机数
金额类
formatMoney:金额格式化convertMoney:金额转大写
日期类
formatDate:日期格式化isWeekend:判断是否为周末isWeekday:判断是否为工作日dayName:日期转名称getTimestamp:日期转时间戳fromTimestamp:时间戳转日期roundDate:日期转换为零点
浮点计算类
addExact:两个数相加subExact:两个数相减mulExact:两个数相乘divExact:两个数相除
工具类
clone:浅拷贝deepClone:深拷贝debounce:防抖throttle:节流randomId:生成随机iduuid:生成uuidhexToRGB:16进制转RGBrgbToHex:RGB转16进制
存储类
cookie
getCookie:获取cookiesetCookie:设置cookiedelCookie:删除cookieclearCookie:清空cookie
localStorage
setLStorage:存储localStoragegetLStorage:取出localStoragedelLStorage:删除localStorageclearLStorage:清空localStorage
sessionStorage
setSStorage:存储sessionStoragegetSStorage:取出sessionStoragedelSStorage:删除sessionStorageclearSStorage:清空sessionStorage
DOM类操作
hasClass:判断元素是否包含类名addClass:添加class类名removeClass:移除class类名toggleClass:切换class类名
事件处理相关函数
listener:事件监听器on:绑定事件off:解绑事件
使用文档
1.0.25
4 years ago
1.0.24
5 years ago
1.0.23
5 years ago
1.0.22
5 years ago
1.0.21
5 years ago
1.0.20
5 years ago
1.0.19
5 years ago
1.0.18
5 years ago
1.0.17
5 years ago
1.0.16
5 years ago
1.0.15
5 years ago
1.0.14
5 years ago
1.0.13
5 years ago
1.0.12
5 years ago
1.0.9
5 years ago
1.0.8
5 years ago
1.0.11
5 years ago
1.0.10
5 years ago
1.0.7
5 years ago
1.0.6
5 years ago
1.0.5
5 years ago
1.0.4
5 years ago
1.0.3
5 years ago
1.0.2
5 years ago
1.0.1
5 years ago
1.0.0
5 years ago