allow formatting to display bytes
This commit is contained in:
parent
1c86bba219
commit
fb3096ed03
1 changed files with 5 additions and 1 deletions
|
@ -1,4 +1,4 @@
|
||||||
const SPACE_VALUES = ["B", "KB", "MB", "GB", "TB", "PB", "EB"];
|
const SPACE_VALUES = ["B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB"];
|
||||||
|
|
||||||
export default class FormattingUtility {
|
export default class FormattingUtility {
|
||||||
public static NumberHumanReadable(num: number) {
|
public static NumberHumanReadable(num: number) {
|
||||||
|
@ -7,6 +7,10 @@ export default class FormattingUtility {
|
||||||
|
|
||||||
// HSNOTE: Assumes bytes!
|
// HSNOTE: Assumes bytes!
|
||||||
public static NumberAsFileSize(num: number) {
|
public static NumberAsFileSize(num: number) {
|
||||||
|
if (num < 1024) {
|
||||||
|
return `${num.toFixed(2)} ${SPACE_VALUES[0]}`;
|
||||||
|
}
|
||||||
|
|
||||||
// Converts space values to lower values e.g MB, GB, TB etc depending on the size of the number
|
// Converts space values to lower values e.g MB, GB, TB etc depending on the size of the number
|
||||||
let i = 1;
|
let i = 1;
|
||||||
// Loop through until value is at it's lowest
|
// Loop through until value is at it's lowest
|
||||||
|
|
Loading…
Add table
Reference in a new issue