forked from QuantumNous/new-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformat.ts
More file actions
53 lines (46 loc) · 2.05 KB
/
Copy pathformat.ts
File metadata and controls
53 lines (46 loc) · 2.05 KB
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
/*
Copyright (C) 2023-2026 QuantumNous
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
For commercial licensing, please contact support@quantumnous.com
*/
// ----------------------------------------------------------------------------
// Rankings formatting helpers
// ----------------------------------------------------------------------------
/** Format a token count as `1.2B`, `42M`, `980K`, or `512`. */
export function formatTokens(value: number): string {
if (!Number.isFinite(value) || value <= 0) return '0'
if (value >= 1_000_000_000_000)
return `${(value / 1_000_000_000_000).toFixed(2)}T`
if (value >= 1_000_000_000)
return `${(value / 1_000_000_000).toFixed(value >= 10_000_000_000 ? 1 : 2)}B`
if (value >= 1_000_000)
return `${(value / 1_000_000).toFixed(value >= 10_000_000 ? 1 : 2)}M`
if (value >= 1_000)
return `${(value / 1_000).toFixed(value >= 10_000 ? 0 : 1)}K`
return value.toLocaleString()
}
/** Format a 0..1 share as a percentage with two decimals. */
export function formatShare(share: number): string {
if (!Number.isFinite(share) || share <= 0) return '0%'
if (share < 0.001) return '<0.1%'
return `${(share * 100).toFixed(share < 0.01 ? 2 : 1)}%`
}
/** Format a release date like `Oct 12, 2025`. */
export function formatReleaseDate(iso: string): string {
const ts = Date.parse(iso)
if (!Number.isFinite(ts)) return iso
return new Date(ts).toLocaleDateString(undefined, {
year: 'numeric',
month: 'short',
day: 'numeric',
})
}