# @types/bytes

> TypeScript definitions for bytes

Latest version **3.1.6** (published 2026-08-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install @types/bytes
pnpm add @types/bytes
yarn add @types/bytes
bun add @types/bytes
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; no vulnerabilities; recently updated; high maintenance score; popular repo; extremely popular.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 3.1.6 |
| Published | 2026-08-21 |
| First published | 2016-05-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 7.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 51440 |
| Maintainers | types |

## Links

- npm: https://www.npmjs.com/package/@types/bytes
- Repository: https://github.com/DefinitelyTyped/DefinitelyTyped
- Homepage: https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/bytes
- npm.io page: https://npm.io/package/@types/bytes

## Recent versions

- 3.1.6 (latest) — 2026-08-21
- 3.1.5 (ts5.5) — 2024-12-03
- 3.1.4 (ts4.9) — 2023-11-07
- 3.1.1 (ts4.2) — 2021-07-06
- 3.1.0 (ts3.0) — 2019-11-11
- 3.0.0 (ts2.4) — 2018-03-01
- 3.1.3 — 2023-10-17
- 3.1.2 — 2023-09-15
- 2.5.1 — 2017-08-21
- 2.5.0 — 2017-06-02
- 2.4.33 — 2016-09-19
- 2.4.32 — 2016-08-25
- 2.4.31 — 2016-08-19
- 2.4.30 — 2016-08-02
- 2.1.29 — 2016-07-14
- … 9 more at https://npm.io/package/@types/bytes/versions

## README

# 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](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/bytes/index.d.ts)
````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](https://github.com/danny8002), [Rickard Laurin](https://github.com/believer), [Florian Keller](https://github.com/ffflorian), and [Semih Gemi](https://github.com/semihgemi).

---
_Source: https://npm.io/package/@types/bytes · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
