Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.
export function formatCompactNumber(count: number) {
const formatter = Intl.NumberFormat('en', {
notation: 'compact',
maximumFractionDigits: 1,
})
return formatter.format(count)
}
export function formatFileSize(bytes: number): string {
if (!bytes) return '0 B'
const sizes = ['B', 'KB', 'MB', 'GB', 'TB']
const i = Math.floor(Math.log(bytes) / Math.log(1024))
if (i === 0) return `${bytes} ${sizes[i]}`
return `${(bytes / Math.pow(1024, i)).toFixed(1)} ${sizes[i]}`
}
export const totalDownload = (release: []) => {
if (release instanceof Array) {
const count = release
.map((version: { assets: any[]; name: string }) => {
return version.assets
.map((os) => os.download_count)
})
.map((x: any[]) => x.reduce((a: any, b: any) => a + b, 0))
.reduce((a: any, b: any) => a + b, 0)
return formatCompactNumber(count)
} else {
// return dummy to avoid rate limit API when in dev mode (kept close to the
// real prod total so the dev preview isn't misleading)
return formatCompactNumber(6600000)
}
}