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

@Pipe({
  name: 'size'
})
export class SizePipe implements PipeTransform {

  transform(value: number, exp: string): string {
    const divide = ['', 'k', 'M', 'G', 'T'].indexOf(exp);
    for (let i = 0; i < divide; i ++) {
      value = value / 1024;
    }
    return `${value.toFixed(2)} ${exp}B`;
  }

}
