<cs-format-bytes>
StableHelpersSince 0.1

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.

npm Self-Hosted React
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.

PropertyAttributeDescriptionTypeDefaultReflects
displaydisplayDetermines how to display the result, e.g. "100 bytes", "100 b", or "100b".'long' | 'short' | 'narrow''short'
unitunitThe type of unit to display.'byte' | 'bit''byte'
valuevalueThe number to format in bytes.number0