ngx-filesize-pipe
v1.0.2
Published
An Angular pipe to convert bytes to formated file sizes
Maintainers
Readme
ngx-filesize-pipe
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.
Features
- Converts bytes to KB, MB, GB, etc.
- Easy integration with Angular 17+
- Simple API, zero dependencies
Installation
npm install ngx-filesize-pipeUsage
1. Import the Pipe
Add NgxFilesizePipe to your module's declarations:
import { NgxFilesizePipe } from 'ngx-file-size';
@NgModule({
declarations: [AppComponent, NgxFilesizePipe],
bootstrap: [AppComponent]
})
export class AppModule { }2. Use in Templates
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 -->3. Handling Invalid Inputs
If the input is invalid (e.g., non-numeric), the pipe returns:
Invalid sizeExample:
<p>{{ 'abc' | filesize }}</p>
<!-- Output: Invalid size -->License
This project is licensed under the MIT License. (©) Vipin.
Happy coding! 🚀
