mirror of
https://github.com/alexta69/metube.git
synced 2026-03-18 14:33:50 +00:00
19 lines
570 B
TypeScript
19 lines
570 B
TypeScript
import { Pipe, PipeTransform } from "@angular/core";
|
|
|
|
@Pipe({
|
|
name: 'speed',
|
|
pure: true
|
|
})
|
|
export class SpeedPipe implements PipeTransform {
|
|
transform(value: number): string {
|
|
if (value === null || value === undefined || isNaN(value) || value <= 0) {
|
|
return '';
|
|
}
|
|
|
|
const k = 1024;
|
|
const decimals = 2;
|
|
const sizes = ['B/s', 'KB/s', 'MB/s', 'GB/s', 'TB/s', 'PB/s', 'EB/s', 'ZB/s', 'YB/s'];
|
|
const i = Math.floor(Math.log(value) / Math.log(k));
|
|
return `${parseFloat((value / Math.pow(k, i)).toFixed(decimals))} ${sizes[i]}`;
|
|
}
|
|
} |