refactor: extract formatCompactNumber util and add last_used_at to refresh key
- Add formatCompactNumber() for consistent large-number formatting (K/M/B) - Include last_used_at in OpenAI usage refresh key for better change detection - Add .gitattributes eol=lf rules for frontend source files
This commit is contained in:
@@ -247,6 +247,26 @@ export function formatTokensK(tokens: number): string {
|
||||
return tokens.toString()
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化大数字(K/M/B,保留 1 位小数)
|
||||
* @param num 数字
|
||||
* @param options allowBillions=false 时最高只显示到 M
|
||||
*/
|
||||
export function formatCompactNumber(
|
||||
num: number | null | undefined,
|
||||
options?: { allowBillions?: boolean }
|
||||
): string {
|
||||
if (num === null || num === undefined) return '0'
|
||||
|
||||
const abs = Math.abs(num)
|
||||
const allowBillions = options?.allowBillions !== false
|
||||
|
||||
if (allowBillions && abs >= 1_000_000_000) return `${(num / 1_000_000_000).toFixed(1)}B`
|
||||
if (abs >= 1_000_000) return `${(num / 1_000_000).toFixed(1)}M`
|
||||
if (abs >= 1_000) return `${(num / 1_000).toFixed(1)}K`
|
||||
return num.toString()
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化倒计时(从现在到目标时间的剩余时间)
|
||||
* @param targetDate 目标日期字符串或 Date 对象
|
||||
|
||||
Reference in New Issue
Block a user