惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Help Net Security
The GitHub Blog
The GitHub Blog
F
Fortinet All Blogs
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Simon Willison's Weblog
Simon Willison's Weblog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Cisco Talos Blog
Cisco Talos Blog
P
Privacy & Cybersecurity Law Blog
I
Intezer
Y
Y Combinator Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
N
Netflix TechBlog - Medium
The Hacker News
The Hacker News
AWS News Blog
AWS News Blog
aimingoo的专栏
aimingoo的专栏
A
About on SuperTechFans
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Stack Overflow Blog
Stack Overflow Blog
Hacker News: Ask HN
Hacker News: Ask HN
酷 壳 – CoolShell
酷 壳 – CoolShell
量子位
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
B
Blog
T
Tor Project blog
C
Cybersecurity and Infrastructure Security Agency CISA
云风的 BLOG
云风的 BLOG
博客园_首页
V2EX - 技术
V2EX - 技术
T
Threat Research - Cisco Blogs
腾讯CDC
宝玉的分享
宝玉的分享
博客园 - 叶小钗
罗磊的独立博客
S
Securelist
The Last Watchdog
The Last Watchdog
Google Online Security Blog
Google Online Security Blog
Scott Helme
Scott Helme
博客园 - 司徒正美
W
WeLiveSecurity
有赞技术团队
有赞技术团队
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
S
Secure Thoughts
NISL@THU
NISL@THU
N
News and Events Feed by Topic
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
雷峰网
雷峰网
大猫的无限游戏
大猫的无限游戏
K
Kaspersky official blog
IT之家
IT之家

清竹志-(原清竹茶馆)

读完 DeepSeek-V4 技术报告:这次最值得看的,不是“更大”,而是“更省” Codex Skills 不是 Prompt 的升级版,而是写给 AI 的岗位 SOP 【译】React 服务器组件中的关键安全漏洞 Vercel收购NuxtLabs,我和尤雨溪一样心情复杂 免费平替Claude-Code:Google Gemini CLI深度解析与实践指南 Newsletter逆天福利:三种方式获取全年免费 AI/SaaS 工具包(含团体购买兑换防坑指南) Google发布Agent2Agent(A2A)协议:开启协作式 AI 代理的新时代 颠覆传统搜索!全球AI搜索工具正在攻城略地 激战“后DeepSeek时代”:全球大模型开启“地狱级”内卷模式 改名公告:清竹茶馆的新篇章-清竹志 【2023年终总结】与逝去的年华道个别 【前端工程化】Nextjs项目工程化最佳实践总结(献给2023-1024的礼物) 【2022年终总结】此去经年,烟消雾散,晨曦微露 【1024献礼】生成可掌握钱包和揭秘NFT和token被盗案例以及如何预防被盗 【2021年终总结】刚好遇见你,留下百年的期许 【Swift】Swift学习计划与资料 【前端工程化】Vite关于Vue3/React项目工程化总结(献给2021-1024的礼物) 【图解算法】前端思维学习图解算法数据结构笔记(一)之算法复杂度 【三亚攻略】2021年三亚团建攻略 【2020年终总结】如果这一年你很健康,那便是最好的一年!
【前端工具】前端工具函数合集
vadxq · 2021-03-03 · via 清竹志-(原清竹茶馆)

收集一些前端工具函数,整理成集,以便查询使用。随时更新:2021-03-03

正则匹配相关

手机号正则验证

将手机号中间四位隐藏为****

1
2
3
4
const phone = 17600000000;
const data = phone.toString().replace(/(\d{3})\d{4}(\d{4})/, "$1****$2");
console.log(data);

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
40
41
42
43
44
45
46





export const setCookie = (name, val) => {
const date = new Date();
const value = val;


date.setTime(date.getTime() + 7 * 24 * 60 * 60 * 1000);


document.cookie =
name + "=" + value + "; expires=" + date.toUTCString() + "; path=/";
};





export const getCookie = (name) => {
const value = "; " + document.cookie;
const parts = value.split("; " + name + "=");

if (parts.length === 2) {
const ppop = parts.pop();
if (ppop) {
return ppop.split(";").shift();
}
}
};





export const deleteCookie = (name) => {
const date = new Date();


date.setTime(date.getTime() + -1 * 24 * 60 * 60 * 1000);


document.cookie = name + "=; expires=" + date.toUTCString() + "; path=/";
};

格式化时间

将时间戳变为个位数带 0 前缀

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19





export const formatDate = (date) => {
const da = new Date(date);
const year = da.getFullYear();
const month = da.getMonth() + 1;
const day = da.getDate();
const hours = da.getHours();
const mins = da.getMinutes();
const secs = da.getSeconds();
return `${year}-${month > 9 ? month : "0" + month}-${
day > 9 ? day : "0" + day
} ${hours > 9 ? hours : "0" + hours}:${mins > 9 ? mins : "0" + mins}:${
secs > 9 ? secs : "0" + secs
}`;
};

生成 UUID

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






export const UUID = (len, radix) => {
const chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(
""
);
const uuid = [];
let i;
radix = radix || chars.length;

if (len) {

for (i = 0; i < len; i++) uuid[i] = chars[0 | (Math.random() * radix)];
} else {

let r;


uuid[8] = uuid[13] = uuid[18] = uuid[23] = "-";
uuid[14] = "4";



for (i = 0; i < 36; i++) {
if (!uuid[i]) {
r = 0 | (Math.random() * 16);
uuid[i] = chars[i === 19 ? (r & 0x3) | 0x8 : r];
}
}
}

return uuid.join("");
};

type 类型判断

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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
export const isString = (e) => { 
return Object.prototype.toString.call(e).slice(8, -1) === 'String'
}

export const isNumber = (e) => {
return Object.prototype.toString.call(e).slice(8, -1) === 'Number'
}

export const isBoolean = (e) => {
return Object.prototype.toString.call(e).slice(8, -1) === 'Boolean'
}

export const isFunction = (e) => {
return Object.prototype.toString.call(e).slice(8, -1) === 'Function'
}

export const isNull = (e) => {
return Object.prototype.toString.call(e).slice(8, -1) === 'Null'
}

export const isUndefined = (e) => {
return Object.prototype.toString.call(e).slice(8, -1) === 'Undefined'
}

export const isObj = (e) => {
return Object.prototype.toString.call(e).slice(8, -1) === 'Object'
}

export const isArray = (e) => {
return Object.prototype.toString.call(e).slice(8, -1) === 'Array'
}

export const isDate = (e) => {
return Object.prototype.toString.call(e).slice(8, -1) === 'Date'
}

export const isRegExp = (e) => {
return Object.prototype.toString.call(e).slice(8, -1) === 'RegExp'
}

export const isError = (e) => {
return Object.prototype.toString.call(e).slice(8, -1) === 'Error'
}

export const isSymbol = (e) => {
return Object.prototype.toString.call(e).slice(8, -1) === 'Symbol'
}

export const isPromise = (e) => {
return Object.prototype.toString.call(e).slice(8, -1) === 'Promise'
}

export const isSet = (e) => {
return Object.prototype.toString.call(e).slice(8, -1) === 'Set'
}

random随机数

返回一定范围的整数随机数

1
2

export const randoms = (min, max) => Math.floor(min + Math.random() * ((max + 1) - min))

去除空格

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20






export const trim = (str, type = 1) => {
switch (type) {
case 1:
return str.replace(/\s+/g, '')
case 2:
return str.replace(/(^\s*)|(\s*$)/g, '')
case 3:
return str.replace(/(^\s*)/g, '')
case 4:
return str.replace(/(\s*$)/g, '')
default:
return str
}
}

大小写处理

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





export const changeCase = (str, type = 4) => {
switch (type) {
case 1:
return str.replace(/\b\w+\b/g, (word) => return word.substring(0, 1).toUpperCase() + word.substring(1).toLowerCase())
case 2:
return str.replace(/\b\w+\b/g, (word) => word.substring(0, 1).toLowerCase() + word.substring(1).toUpperCase())
case 3:
return str.split('').map((word) => {
if (/[a-z]/.test(word)) {
return word.toUpperCase()
} else {
return word.toLowerCase()
}
}).join('')
case 4:
return str.toUpperCase()
case 5:
return str.toLowerCase()
default:
return str
}
}