ngx-filesize-pipe
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

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-pipe

Usage

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 size

Example:

<p>{{ 'abc' | filesize }}</p>
<!-- Output: Invalid size -->

License

This project is licensed under the MIT License. (©) Vipin.

Happy coding! 🚀

Package Sidebar

Install

npm i ngx-filesize-pipe

Weekly Downloads

3

Version

1.0.2

License

MIT

Unpacked Size

14.1 kB

Total Files

12

Last publish

Collaborators

  • vipinkc4