mirror of
https://github.com/Nezumi-2711/onedrive-vercel-index.git
synced 2026-09-22 13:38:45 +00:00
change unknown file preview to readable format
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Convert raw bits file/folder size into a human readable string
|
||||
*
|
||||
* @param size File or folder size, in raw bits
|
||||
* @returns Human readable form of the file or folder size
|
||||
*/
|
||||
export const humanFileSize = (size: number) => {
|
||||
if (size < 1024) return size + ' B'
|
||||
const i = Math.floor(Math.log(size) / Math.log(1024))
|
||||
const num = size / Math.pow(1024, i)
|
||||
const round = Math.round(num)
|
||||
const formatted = round < 10 ? num.toFixed(2) : round < 100 ? num.toFixed(1) : round
|
||||
return `${formatted} ${'KMGTPEZY'[i - 1]}B`
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the last modified date time into locale friendly string
|
||||
*
|
||||
* @param lastModifedDateTime DateTime string in ISO format
|
||||
* @returns Human readable form of the file or folder last modified date
|
||||
*/
|
||||
export const formatModifiedDateTime = (lastModifedDateTime: string) => {
|
||||
return new Date(lastModifedDateTime).toLocaleString('en-US', {
|
||||
year: 'numeric',
|
||||
month: '2-digit',
|
||||
day: '2-digit',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
hour12: false,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user