1
0
Files
yel-dspace-angular/src/app/shared/utils/file-size-pipe.ts
2020-06-10 10:32:58 +02:00

20 lines
521 B
TypeScript

import { Pipe, PipeTransform } from '@angular/core';
import * as fileSize from 'filesize';
/*
* Convert bytes into largest possible unit.
* Takes an precision argument that defaults to 2.
* Usage:
* bytes | fileSize:precision
* Example:
* {{ 1024 | fileSize}}
* formats to: 1 KB
*/
@Pipe({ name: 'dsFileSize' })
export class FileSizePipe implements PipeTransform {
transform(bytes: number = 0, precision: number = 2): string {
return fileSize(bytes, { standard: 'jedec', round: precision });
}
}