mirror of
https://github.com/xuthus83/pigallery2.git
synced 2024-11-03 21:04:03 +08:00
19 lines
395 B
TypeScript
19 lines
395 B
TypeScript
|
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];
|
||
|
}
|
||
|
}
|
||
|
|