Skip to content

Commit

Permalink
🚸 Perf: 优化 sed 转义
Browse files Browse the repository at this point in the history
  • Loading branch information
soxft committed Nov 7, 2024
1 parent 74d57af commit 5f9a0c2
Show file tree
Hide file tree
Showing 7 changed files with 187 additions and 193 deletions.
2 changes: 1 addition & 1 deletion dist/busuanzi.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 7 additions & 14 deletions dist/busuanzi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,14 @@
storageName: string = "bsz-id"; // 本地存储名称

let format = (num: number, style: string = 'default'): string => {
switch (style) {
case "comma":
return num.toLocaleString();
case "short": {
let units = ["", "K", "M", "B", "T"];
let index = 0;
while (num >= 1000 && index < units.length - 1) {
num /= 1000;
index++;
}
return Math.round(num * 100) / 100 + units[index]; // 四舍五入到两位小数
}
default:
return num.toString();
if (style === "comma") return num.toLocaleString();
if (style === "short") {
const units = ["", "K", "M", "B", "T"];
let index = Math.floor(Math.log10(num) / 3);
num /= Math.pow(1000, index);
return `${Math.round(num * 100) / 100}${units[index]}`;
}
return num.toString();
};

let bsz_send = () => {
Expand Down
2 changes: 1 addition & 1 deletion dist/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"dependencies": {
"ts-loader": "^9.3.0",
"typescript": "^4.6.4",
"webpack": "5.76.0",
"webpack": "5.95.0",
"webpack-cli": "^4.10.0"
},
"license": "Apache-2.0",
Expand Down
Loading

0 comments on commit 5f9a0c2

Please sign in to comment.