@types/bytes
TypeScript definitions for bytes
Last updated 3 years ago by types .
MIT · Repository · Original npm · Tarball · package.json
$ npm install @types/bytes 
SYNC missed versions from official npm registry.

Installation

npm install --save @types/bytes

Summary

This package contains type definitions for bytes (https://github.com/visionmedia/bytes.js).

Details

Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/bytes.

index.d.ts

/**
 * Convert the given value in bytes into a string.
 *
 * @param value Number of bytes to convert.
 * @param options Formatting options.
 * @returns Formatted string, or null if value is invalid.
 *
 * @example
 * bytes(1024); // '1KB'
 * bytes(1000, { thousandsSeparator: ' ' }); // '1 000B'
 */
declare function bytes(value: number, options?: bytes.BytesOptions): string | null;

/**
 * Parse string to an integer in bytes.
 *
 * @param value String representation of bytes to parse.
 * @returns Number of bytes, or null if value is invalid.
 *
 * @example
 * bytes('1KB'); // 1024
 * bytes('10.5MB'); // 11010048
 */
declare function bytes(value: string): number | null;

declare namespace bytes {
    type Unit = "b" | "gb" | "kb" | "mb" | "pb" | "tb" | "B" | "GB" | "KB" | "MB" | "PB" | "TB";

    interface BytesOptions {
        /**
         * Number of decimal places to include. Default is `2`.
         */
        decimalPlaces?: number | undefined;
        /**
         * Whether to format with fixed decimal precision. Default is `false`.
         */
        fixedDecimals?: boolean | undefined;
        /**
         * Thousands separator character (e.g. `','` or `' '`). Default is `''`.
         */
        thousandsSeparator?: string | undefined;
        /**
         * Specific unit to force formatting into (e.g. `'MB'`, `'GB'`). Default is `''`.
         */
        unit?: Unit | undefined;
        /**
         * Separator between the number and metric unit. Default is `''`.
         */
        unitSeparator?: string | undefined;
    }

    /**
     * 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.
     *
     * @param value Number of bytes to format.
     * @param options Formatting options.
     * @returns Formatted string, or null if value is invalid.
     */
    function format(value: number, options?: BytesOptions): string | null;

    /**
     * Parse the string value into an integer in bytes.
     *
     * If no unit is given, it is assumed the value is in bytes.
     *
     * @param value String representation or number to parse.
     * @returns Number of bytes, or null if value is invalid.
     */
    function parse(value: string | number): number | null;
}

export = bytes;

Additional Details

  • Last updated: Fri, 21 Aug 2026 09:13:39 GMT
  • Dependencies: none

Credits

These definitions were written by Zhiyuan Wang, Rickard Laurin, Florian Keller, and Semih Gemi.

Current Tags

  • 3.1.6                                ...           latest (3 months ago)
  • 3.0.0                                ...           ts2.0 (9 years ago)
  • 3.0.0                                ...           ts2.1 (9 years ago)
  • 3.0.0                                ...           ts2.2 (9 years ago)
  • 3.0.0                                ...           ts2.3 (9 years ago)
  • 3.0.0                                ...           ts2.4 (9 years ago)
  • 3.0.0                                ...           ts2.5 (9 years ago)
  • 3.0.0                                ...           ts2.6 (9 years ago)
  • 3.0.0                                ...           ts2.7 (9 years ago)
  • 3.1.0                                ...           ts2.8 (7 years ago)
  • 3.1.0                                ...           ts2.9 (7 years ago)
  • 3.1.0                                ...           ts3.0 (7 years ago)
  • 3.1.0                                ...           ts3.1 (7 years ago)
  • 3.1.0                                ...           ts3.2 (7 years ago)
  • 3.1.0                                ...           ts3.3 (7 years ago)
  • 3.1.0                                ...           ts3.4 (7 years ago)
  • 3.1.0                                ...           ts3.5 (7 years ago)
  • 3.1.1                                ...           ts3.6 (5 years ago)
  • 3.1.1                                ...           ts3.7 (5 years ago)
  • 3.1.1                                ...           ts3.8 (5 years ago)
  • 3.1.1                                ...           ts3.9 (5 years ago)
  • 3.1.1                                ...           ts4.0 (5 years ago)
  • 3.1.1                                ...           ts4.1 (5 years ago)
  • 3.1.1                                ...           ts4.2 (5 years ago)
  • 3.1.1                                ...           ts4.3 (5 years ago)
  • 3.1.1                                ...           ts4.4 (5 years ago)
  • 3.1.4                                ...           ts4.5 (3 years ago)
  • 3.1.4                                ...           ts4.6 (3 years ago)
  • 3.1.4                                ...           ts4.7 (3 years ago)
  • 3.1.4                                ...           ts4.8 (3 years ago)
  • 3.1.4                                ...           ts4.9 (3 years ago)
  • 3.1.5                                ...           ts5.0 (2 years ago)
  • 3.1.5                                ...           ts5.1 (2 years ago)
  • 3.1.5                                ...           ts5.2 (2 years ago)
  • 3.1.5                                ...           ts5.3 (2 years ago)
  • 3.1.5                                ...           ts5.4 (2 years ago)
  • 3.1.5                                ...           ts5.5 (2 years ago)
  • 3.1.6                                ...           ts5.6 (3 months ago)
  • 3.1.6                                ...           ts5.7 (3 months ago)
  • 3.1.6                                ...           ts5.8 (3 months ago)
  • 3.1.6                                ...           ts5.9 (3 months ago)
  • 3.1.6                                ...           ts6.0 (3 months ago)
  • 3.1.6                                ...           ts7.0 (3 months ago)
  • 3.1.6                                ...           ts7.1 (3 months ago)

24 Versions

  • 3.1.6                                ...           3 months ago
  • 3.1.5                                ...           2 years ago
  • 3.1.4                                ...           3 years ago
  • 3.1.3                                ...           3 years ago
  • 3.1.2                                ...           3 years ago
  • 3.1.1                                ...           5 years ago
  • 3.1.0                                ...           7 years ago
  • 3.0.0                                ...           9 years ago
  • 2.5.1                                ...           9 years ago
  • 2.5.0                                ...           9 years ago
  • 2.4.33                                ...           10 years ago
  • 2.4.32                                ...           10 years ago
  • 2.4.31                                ...           10 years ago
  • 2.4.30                                ...           10 years ago
  • 2.1.29                                ...           10 years ago
  • 2.1.28-alpha                                ...           10 years ago
  • 2.1.27-alpha                                ...           10 years ago
  • 2.1.26-alpha                                ...           10 years ago
  • 2.1.25-alpha                                ...           10 years ago
  • 2.1.24-alpha                                ...           10 years ago
  • 2.1.23-alpha                                ...           11 years ago
  • 2.1.22-alpha                                ...           11 years ago
  • 2.1.17-alpha                                ...           11 years ago
  • 2.1.16-alpha                                ...           11 years ago
Maintainers (1)
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (0)
None
Dependents (0)
None

© 2010 - cnpmjs.org x YWFE | Home | YWFE