mirror of
https://github.com/Luzifer/ots.git
synced 2025-08-10 07:00:00 -04:00
parent
a098395daf
commit
c5124731f5
13 changed files with 330 additions and 31 deletions
21
src/helpers.js
Normal file
21
src/helpers.js
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) {
|
||||
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