1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2024-11-03 21:04:03 +08:00
pigallery2/frontend/app/pipes/FileSizePipe.ts

19 lines
395 B
TypeScript
Raw Normal View History

2018-12-10 06:25:39 +08:00
import {Pipe, PipeTransform} from '@angular/core';
@Pipe({name: 'fileSize'})
export class FileSizePipe implements PipeTransform {
transform(size: number): string {
const postFixes = ['B', 'KB', 'MB', 'GB', 'TB'];
let index = 0;
while (size > 1000 && index < postFixes.length - 1) {
size /= 1000;
index++;
}
return size.toFixed(2) + postFixes[index];
}
}