-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed SERVICE_WEB variable not working correctly. Implemented missing…
… HA voucher_custom config setting. Fixed VOUCHER_CUSTOM variable not working correctly. Fixed an issue where HA voucher_types config was not used during validation causing an incorrect error. Added bytes conversion
- Loading branch information
1 parent
a80f533
commit 78c891c
Showing
3 changed files
with
33 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* Converts bytes to a human readable format | ||
* | ||
* @param bytes | ||
* @param type | ||
* @param perSecond | ||
* @param decimals | ||
* @return {string} | ||
*/ | ||
module.exports = (bytes, type = 0, perSecond = false, decimals = 2) => { | ||
if (bytes === 0) return '0 Bytes'; | ||
|
||
const k = 1000; | ||
const dm = decimals < 0 ? 0 : decimals; | ||
const sizes = ['Bytes', 'Kb', 'Mb', 'Gb', 'Tb', 'Pb', 'Eb', 'Zb', 'Yb'].toSpliced(0, type); | ||
|
||
const i = Math.floor(Math.log(bytes) / Math.log(k)); | ||
|
||
const suffix = perSecond ? sizes[i] + 'ps' : sizes[i].toUpperCase(); | ||
|
||
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + suffix; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters