Move Top Played part. Move pipes and dashboard Rename object folder to model Doc pipes
27 lines
585 B
TypeScript
27 lines
585 B
TypeScript
import { Pipe, PipeTransform } from '@angular/core';
|
|
|
|
@Pipe({
|
|
name: 'convertSizeToString'
|
|
})
|
|
export class ConvertSizeToStringPipe implements PipeTransform {
|
|
|
|
/**
|
|
* Convert size to human readable size
|
|
* @param size size in byte
|
|
*/
|
|
transform(size: number): any {
|
|
const units = ['Bytes', 'KiB', 'MiB', 'GiB', 'TiB'];
|
|
|
|
if (size === 0) {
|
|
return '0 Byte';
|
|
}
|
|
|
|
const i = Math.floor(Math.log(size) / Math.log(1024));
|
|
let calcSize = size / Math.pow(1024, i);
|
|
calcSize = Math.round(calcSize * 100) / 100;
|
|
|
|
return calcSize + ' ' + units[i];
|
|
}
|
|
|
|
}
|