PipeOptional

wrBytes

Show a byte count as kB, MB or GB.

Installation

Import the class. This entry point has no stylesheet.

import { Component } from '@angular/core';
import { WrBytes } from 'ngwr/pipes';

@Component({ imports: [WrBytes] })
export class MyComponent {}

Basic usage

{{ 1234 | wrBytes }}  <!-- "1.2 kB" -->
532 B · 120.6 kB · 1.1 GB

Decimals

The second argument sets the decimals.

{{ 1234567 | wrBytes: 0 }}  <!-- "1 MB" -->
{{ 1234567 | wrBytes: 2 }}  <!-- "1.18 MB" -->
1 MB · 1.18 MB · 1.177 MB

Playground

1.2 MB

{{ 1234567 | wrBytes: 1 }}

Customize

Bytes
1234567
Decimals
1

API

NameDescriptionTypeDefault
wrBytesFormats bytes in 1024-based units. null, undefined and empty render as an empty string.(value: number | string | null | undefined, decimals = 1) => string—

See also