feat(frontend): modernize Angular app
This commit is contained in:
16
ui/src/app/pipes/file-size.pipe.ts
Normal file
16
ui/src/app/pipes/file-size.pipe.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { Pipe, PipeTransform } from "@angular/core";
|
||||
|
||||
@Pipe({
|
||||
name: 'fileSize',
|
||||
})
|
||||
export class FileSizePipe implements PipeTransform {
|
||||
transform(value: number): string {
|
||||
if (isNaN(value) || value === 0) return '0 Bytes';
|
||||
|
||||
const units = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
||||
const unitIndex = Math.floor(Math.log(value) / Math.log(1000)); // Use 1000 for common units
|
||||
|
||||
const unitValue = value / Math.pow(1000, unitIndex);
|
||||
return `${unitValue.toFixed(2)} ${units[unitIndex]}`;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user