Skip to content

Commit 5f9a0c2

Browse files
committed
🚸 Perf: 优化 sed 转义
1 parent 74d57af commit 5f9a0c2

File tree

7 files changed

+187
-193
lines changed

7 files changed

+187
-193
lines changed

dist/busuanzi.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/busuanzi.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,14 @@
1010
storageName: string = "bsz-id"; // 本地存储名称
1111

1212
let format = (num: number, style: string = 'default'): string => {
13-
switch (style) {
14-
case "comma":
15-
return num.toLocaleString();
16-
case "short": {
17-
let units = ["", "K", "M", "B", "T"];
18-
let index = 0;
19-
while (num >= 1000 && index < units.length - 1) {
20-
num /= 1000;
21-
index++;
22-
}
23-
return Math.round(num * 100) / 100 + units[index]; // 四舍五入到两位小数
24-
}
25-
default:
26-
return num.toString();
13+
if (style === "comma") return num.toLocaleString();
14+
if (style === "short") {
15+
const units = ["", "K", "M", "B", "T"];
16+
let index = Math.floor(Math.log10(num) / 3);
17+
num /= Math.pow(1000, index);
18+
return `${Math.round(num * 100) / 100}${units[index]}`;
2719
}
20+
return num.toString();
2821
};
2922

3023
let bsz_send = () => {

dist/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"dependencies": {
55
"ts-loader": "^9.3.0",
66
"typescript": "^4.6.4",
7-
"webpack": "5.76.0",
7+
"webpack": "5.95.0",
88
"webpack-cli": "^4.10.0"
99
},
1010
"license": "Apache-2.0",

0 commit comments

Comments
 (0)