import {Pipe, PipeTransform} from '@angular/core';

@Pipe({
    name: 'unitConversion'
})
export class UnitConversionPipe implements PipeTransform {

    transform(value: any, args?: any): any {
        console.log(value);
        let res = '';
        let Gbps = 1000 * 1000 * 1000;
        let Mbps = 1000 * 1000;
        let kbps = 1000;
        let size = Math.abs(value);
        if (size / Gbps > 1) {
            res += (size / Gbps).toFixed(2) + 'Gbps';
        } else if (size / Mbps > 1) {
            res += (size / Mbps).toFixed(2) + 'Mbps';
        } else if (size / kbps > 1) {
            res += (size / kbps).toFixed(2) + 'kbps';
        } else {
            res += (size) + 'bps';
        }
        return res;
    }

}
