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

@Pipe({
    name: 'toUtil'
})
export class ToUtilPipe implements PipeTransform {

    transform(value: any): any {
        if(value){
            let res;
            let Mbps = 1000 * 1000;
            let kbps = 1000;
            let size = Math.abs(value);
            if (size / Mbps > 1) {
                const m = size / Mbps;
                res = m.toFixed(2) + 'Mbps';
            } else if (size / kbps > 1) {
                const k = size / kbps;
                res = k.toFixed(2) + 'kbps';
            } else {
                res = (size) + 'bps';
            }
            return res;
        }else{
            return true;
        }

    }

}
