Hearthforge
Sign in
Register
zbin
Code
Branches
Tags
Commits
Issues
Patches
Releases
Pipelines
zbin
/
src
/
shared.ts
shared.ts
⎇
82a92c3c (detached)
master
Go
Raw
1
export
function
humanFileSize
(
size
:
number
) {
2
if
(size
<
1024
)
return
`${
size
} B`
;
3
const
i
=
Math.
min
(
4
, Math.
floor
(Math.
log
(size)
/
Math.
log
(
1024
)));
4
return
`${
(
size
/
1024
**
i
).
toFixed
(
2
)
} ${
[
"B"
,
"KiB"
,
"MiB"
,
"GiB"
,
"TiB"
][
i
]
}`
;
5
}
6