Format Bytes
<cs-format-bytes>
Formats a number of bytes as a human-readable string with the appropriate unit, such as kB, MB, or GB. Supports both byte and bit units with configurable locale.
The file is in size.
Examples
Bytes
Set the value attribute to a number to get the value in bytes.
Bits
To get the value in bits, set the unit attribute to bit.
Localization
Use the lang attribute to set the number formatting locale.
API
Importing
If you're using the autoloader or a hosted project, components load on demand — no manual import needed. To cherry-pick this component, use one of the following snippets.
import '@cruglobal/cornerstone-components/components/format-bytes/format-bytes.js';
import './cornerstone/components/format-bytes/format-bytes.js';
import CsFormatBytes from '@cruglobal/cornerstone-components/react/format-bytes/index.js';
Attributes & Properties
Learn more about attributes and properties.
| Property | Attribute | Description | Type | Default | Reflects |
|---|---|---|---|---|---|
display | display | Determines how to display the result, e.g. "100 bytes", "100 b", or "100b". | 'long' | 'short' | 'narrow' | 'short' | — |
unit | unit | The type of unit to display. | 'byte' | 'bit' | 'byte' | — |
value | value | The number to format in bytes. | number | 0 | — |

