mirror of
https://github.com/xuthus83/pigallery2.git
synced 2024-11-03 21:04:03 +08:00
20 lines
446 B
TypeScript
20 lines
446 B
TypeScript
import {Pipe, PipeTransform} from '@angular/core';
|
|
import {I18n} from '@ngx-translate/i18n-polyfill';
|
|
|
|
|
|
@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];
|
|
}
|
|
}
|
|
|