Limit file upload size on the client (#84)

This commit is contained in:
Sebastien Castiel
2024-02-06 10:19:57 -05:00
parent be0964d9e1
commit 0e6a2bdc6c
3 changed files with 41 additions and 1 deletions

View File

@@ -29,3 +29,16 @@ export function formatCurrency(currency: string, amount: number) {
const formattedAmount = format.format(amount / 100)
return `${currency} ${formattedAmount}`
}
export function formatFileSize(size: number) {
const formatNumber = (num: number) =>
num.toLocaleString('en-US', {
minimumFractionDigits: 0,
maximumFractionDigits: 1,
})
if (size > 1024 ** 3) return `${formatNumber(size / 1024 ** 3)} GB`
if (size > 1024 ** 2) return `${formatNumber(size / 1024 ** 2)} MB`
if (size > 1024) return `${formatNumber(size / 1024)} kB`
return `${formatNumber(size)} B`
}