ngx-filesize-pipe is an Angular pipe that converts a file size (in bytes) into a human-readable format. Perfect for file uploaders, media managers, or storage apps.
- Converts bytes to KB, MB, GB, etc.
- Easy integration with Angular 17+
- Simple API, zero dependencies
npm install ngx-filesize-pipe
Add NgxFilesizePipe
to your module's declarations:
import { NgxFilesizePipe } from 'ngx-file-size';
@NgModule({
declarations: [AppComponent, NgxFilesizePipe],
bootstrap: [AppComponent]
})
export class AppModule { }
Convert bytes to a readable format:
<p>{{ 1048576 | filesize }}</p>
<!-- Output: 1 MB -->
Specify decimal places (default: 2):
<p>{{ 1048576 | filesize:3 }}</p>
<!-- Output: 1.000 MB -->
If the input is invalid (e.g., non-numeric), the pipe returns:
Invalid size
Example:
<p>{{ 'abc' | filesize }}</p>
<!-- Output: Invalid size -->
This project is licensed under the MIT License. (©) Vipin.
Happy coding! 🚀