-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
39 lines (31 loc) · 988 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import dayjs from 'dayjs';
// 检查是否为有效邮箱地址
export function isValidEmail(email) {
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(email);
}
// 检查是否为有效手机号码
export function isValidPhoneNumber(phoneNumber) {
const phoneRegex = /^\d{10}$/;
return phoneRegex.test(phoneNumber);
}
// 获取数组中的最大值
export function getMaxValue(arr) {
return Math.max(...arr);
}
// 获取数组中的最小值
export function getMinValue(arr) {
return Math.min(...arr);
}
// 将字符串转换为驼峰命名
export function toCamelCase(str) {
return str.replace(/[-_](\w)/g, (_, c) => c.toUpperCase());
}
// 日期检测 检测当前日期是否在 date 之后
export function isAfter(currentTime, compareTime) {
// 使用 Day.js 解析时间
const current = dayjs(currentTime);
const compare = dayjs(compareTime);
// 判断当前时间是否在比较时间之后
return current.isAfter(compare);
}