feat: make byte size units translatable (#5969)

Make byte size units translatable
This commit is contained in:
Jerozgen
2026-05-09 12:26:59 +03:00
committed by GitHub
parent e8665f43ca
commit 3052a14d95
21 changed files with 214 additions and 222 deletions

View File

@@ -94,18 +94,6 @@ export const sortedCategories = (tags, formatCategoryName, locale) => {
})
}
export const formatBytes = (bytes, decimals = 2) => {
if (bytes === 0) return '0 Bytes'
const k = 1024
const dm = decimals < 0 ? 0 : decimals
const sizes = ['Bytes', 'KiB', 'MiB', 'GiB']
const i = Math.floor(Math.log(bytes) / Math.log(k))
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`
}
export const capitalizeString = (name) => {
return name ? name.charAt(0).toUpperCase() + name.slice(1) : name
}
@@ -240,7 +228,7 @@ export function cycleValue<T extends string>(value: T, values: T[]): T {
return values[index % values.length]
}
export const fileIsValid = (file, validationOptions) => {
export const fileIsValid = (file, validationOptions, formatBytes) => {
const { maxSize, alertOnInvalid } = validationOptions
if (maxSize !== null && maxSize !== undefined && file.size > maxSize) {
if (alertOnInvalid) {