@types/bytes

  • Version 3.1.6
  • Published
  • 7.76 kB
  • No dependencies
  • MIT license

Install

npm i @types/bytes
yarn add @types/bytes
pnpm add @types/bytes

Overview

TypeScript definitions for bytes

Index

Functions

function bytes

bytes: typeof bytes;
  • Convert the given value in bytes into a string.

    Parameter value

    Number of bytes to convert.

    Parameter options

    Formatting options.

    Returns

    Formatted string, or null if value is invalid.

    Example 1

    bytes(1024); // '1KB' bytes(1000, { thousandsSeparator: ' ' }); // '1 000B'

  • Parse string to an integer in bytes.

    Parameter value

    String representation of bytes to parse.

    Returns

    Number of bytes, or null if value is invalid.

    Example 1

    bytes('1KB'); // 1024 bytes('10.5MB'); // 11010048

function format

format: (value: number, options?: BytesOptions) => string | null;
  • Format the given value in bytes into a string.

    If the value is negative, it is kept as such. If it is a float, it is rounded.

    Parameter value

    Number of bytes to format.

    Parameter options

    Formatting options.

    Returns

    Formatted string, or null if value is invalid.

function parse

parse: (value: string | number) => number | null;
  • Parse the string value into an integer in bytes.

    If no unit is given, it is assumed the value is in bytes.

    Parameter value

    String representation or number to parse.

    Returns

    Number of bytes, or null if value is invalid.

Interfaces

interface BytesOptions

interface BytesOptions {}

    property decimalPlaces

    decimalPlaces?: number | undefined;
    • Number of decimal places to include. Default is 2.

    property fixedDecimals

    fixedDecimals?: boolean | undefined;
    • Whether to format with fixed decimal precision. Default is false.

    property thousandsSeparator

    thousandsSeparator?: string | undefined;
    • Thousands separator character (e.g. ',' or ' '). Default is ''.

    property unit

    unit?: Unit | undefined;
    • Specific unit to force formatting into (e.g. 'MB', 'GB'). Default is ''.

    property unitSeparator

    unitSeparator?: string | undefined;
    • Separator between the number and metric unit. Default is ''.

    Type Aliases

    type Unit

    type Unit =
    | 'b'
    | 'gb'
    | 'kb'
    | 'mb'
    | 'pb'
    | 'tb'
    | 'B'
    | 'GB'
    | 'KB'
    | 'MB'
    | 'PB'
    | 'TB';

      Package Files (1)

      Dependencies (0)

      No dependencies.

      Dev Dependencies (0)

      No dev dependencies.

      Peer Dependencies (0)

      No peer dependencies.

      Badge

      To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

      You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@types/bytes.

      • Markdown
        [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@types/bytes)
      • HTML
        <a href="https://www.jsdocs.io/package/@types/bytes"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>