byteConverter

The byteConverter pipe converts numeric byte values into human-readable file size strings (e.g., "1.5 MB", "2.3 GB") with locale-aware formatting. It automatically handles unit conversion (BYTE, KB, MB, GB, TB) and supports internationalization with translations for multiple languages including English, French, Chinese, Japanese, Korean, German, Spanish, Italian, Portuguese, and Russian.

Examples

Example 1: Basic Usage

Convert byte values to human-readable format:

import {ByteConverterPipe} from 'ngx-lift';

@Component({
  imports: [ByteConverterPipe],
  template: `
    <p>{{ 104.89 | byteConverter }}</p>
    <!-- Output: "104.89 B" -->

    <p>{{ 1044.89 | byteConverter }}</p>
    <!-- Output: "1.02 KB" -->
  `
})
export class ByteConverterExampleComponent {}

Example 2: File Size Display

Display file sizes in a user-friendly format:

import {ByteConverterPipe} from 'ngx-lift';

@Component({
  imports: [ByteConverterPipe],
  template: `
    <p>File size: {{ fileSizeInBytes | byteConverter }}</p>
    <!-- Example: "File size: 1.02 KB" -->
  `
})
export class FileSizeExampleComponent {
  fileSizeInBytes = 1044.89;
}

Example 3: Different Unit Conversions

The pipe automatically converts to the appropriate unit:

import {ByteConverterPipe} from 'ngx-lift';

@Component({
  imports: [ByteConverterPipe],
  template: `
    <p>{{ 104.89 | byteConverter }}</p>
    <!-- Output: "104.89 B" -->

    <p>{{ 1044.89 | byteConverter }}</p>
    <!-- Output: "1.02 KB" -->

    <p>{{ 2 * 1024 * 1024 | byteConverter }}</p>
    <!-- Output: "2 MB" -->

    <p>{{ 3 * 1024 * 1024 * 1024 | byteConverter }}</p>
    <!-- Output: "3 GB" -->

    <p>{{ 2.89 * 1024 * 1024 * 1024 * 1024 | byteConverter }}</p>
    <!-- Output: "2.89 TB" -->
  `
})
export class UnitConversionsExampleComponent {}

API Reference

byteConverter

Angular pipe that converts a number of bytes into a human-readable string format with locale-aware formatting.

Signature

transform(value?: number | null): string | null

Parameters

  • value?: number | null

    (Optional) The number of bytes to convert. Returns null if the value is null, undefined, or NaN.

Returns

A formatted string with the appropriate unit (B, KB, MB, GB, TB) based on the locale, or null if the input is invalid.

Language Support

The pipe uses the application's LOCALE_ID to determine the appropriate unit translations. Supported languages include English, French, Chinese (Simplified and Traditional), Japanese, Korean, German, Spanish, Italian, Portuguese (Brazil), and Russian. If the browser language is not supported, English serves as the default.