1. 常用正则表达式
手机号:/^1[3456789]\d{9}$/,
邮箱:/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/,
链接:/^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/,
edu教育邮箱:/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.edu\.cn$/,
密码包含大小写字母和数字:/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*).+$/,
仅支持中文空格和英文大小写字母:/^[a-zA-Z \u4e00-\u9fa5]+$/,
2. Array Set Map转换
const array = [1, 2, 3, 4];
const set = new Set(array);
const arr = Array.from(set);
const map = new Map().set('GFG', 1).set('Geeks', 2);
const keys = map.keys();
const arr = [...keys];
3. Enum获取数据类型
enum ENUM_TYPE { ALL = 'all', SOME = 'some', LITTLE = 'little' }
type IValue = `${ENUM_TYPE}`
type IKey = keyof typeof ENUM_TYPE
4. 字符串数组排序
const list = ['abc123', 'abc11', 'abc2'];
const newList = list?.sort(
(a, b) =>
a.location.name?.localeCompare(b.location.name || '', 'zh-CN', {
numeric: true,
}) as number,
)