[O] Better sizeFmt
This commit is contained in:
+5
-3
@@ -5,10 +5,12 @@
|
|||||||
* @returns Human readable size in string
|
* @returns Human readable size in string
|
||||||
*/
|
*/
|
||||||
export function sizeFmt(size: number): string {
|
export function sizeFmt(size: number): string {
|
||||||
var i = size == 0 ? 0 : Math.floor(Math.log(size) / Math.log(1024));
|
const i = size == 0 ? 0 : Math.floor(Math.log(size) / Math.log(1024));
|
||||||
return (size / Math.pow(1024, i)).toFixed(1) + ' ' + ['B', 'kB', 'MB', 'GB', 'TB'][i];
|
size = size / Math.pow(1024, i)
|
||||||
|
const fmt = size >= 100 ? size.toFixed(0) : size.toFixed(1)
|
||||||
|
return fmt + ' ' + ['B', 'kB', 'MB', 'GB', 'TB'][i];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function clamp(num: number, min: number, max: number) {
|
export function clamp(num: number, min: number, max: number) {
|
||||||
return Math.max(Math.min(num, max), min)
|
return Math.max(Math.min(num, max), min)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user