mirror of
https://github.com/Luzifer/ots.git
synced 2025-08-09 06:32:22 -04:00
Port to Vue3 and TypeScript
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
b447417d0f
commit
e572d2f545
33 changed files with 2297 additions and 5930 deletions
21
src/helpers.ts
Normal file
21
src/helpers.ts
Normal file
|
@ -0,0 +1,21 @@
|
|||
/**
|
||||
* Converts number of bytes into human format (524288 -> "512.0 KiB")
|
||||
* @param {number} bytes Byte amount to convert into human readable format
|
||||
* @returns string
|
||||
*/
|
||||
function bytesToHuman(bytes: number): string {
|
||||
for (const t of [
|
||||
{ thresh: 1024 * 1024, unit: 'MiB' },
|
||||
{ thresh: 1024, unit: 'KiB' },
|
||||
]) {
|
||||
if (bytes > t.thresh) {
|
||||
return `${(bytes / t.thresh).toFixed(1)} ${t.unit}`
|
||||
}
|
||||
}
|
||||
|
||||
return `${bytes} B`
|
||||
}
|
||||
|
||||
export {
|
||||
bytesToHuman,
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue