UNPKG

ngx-filesize-pipe

Version:

An Angular pipe to convert bytes to formated file sizes

48 lines (42 loc) 2.14 kB
import * as i0 from '@angular/core'; import { Pipe, NgModule } from '@angular/core'; class FilesizePipe { transform(value, decimals = 2) { if (typeof value !== 'number' || isNaN(value)) { return 'Invalid size'; } if (value === 0) return '0 Bytes'; const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; const i = Math.floor(Math.log(value) / Math.log(1024)); return `${parseFloat((value / Math.pow(1024, i)).toFixed(decimals))} ${sizes[i]}`; } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: FilesizePipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); } static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "17.3.12", ngImport: i0, type: FilesizePipe, name: "filesize" }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: FilesizePipe, decorators: [{ type: Pipe, args: [{ name: 'filesize' }] }] }); class NgxFilesizePipe { static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: NgxFilesizePipe, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); } static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.3.12", ngImport: i0, type: NgxFilesizePipe, declarations: [FilesizePipe], exports: [FilesizePipe] }); } static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: NgxFilesizePipe }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: NgxFilesizePipe, decorators: [{ type: NgModule, args: [{ declarations: [FilesizePipe], exports: [FilesizePipe] }] }] }); /* * Public API Surface of filesize */ /** * Generated bundle index. Do not edit. */ export { FilesizePipe, NgxFilesizePipe }; //# sourceMappingURL=ngx-filesize-pipe.mjs.map