Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

bytes-formatter

Package Overview
Dependencies
Maintainers
2
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bytes-formatter

Bytes formatter module provides a function to format byte values into human-readable strings with appropriate units (bytes, KB, MB, GB, TB, PB).

latest
Source
npmnpm
Version
21.6.15
Version published
Maintainers
2
Created
Source

Bytes Formatter Tweet

Build Status License NPM version NPM downloads

Bytes formatter module provides a function to format byte values into human-readable strings with appropriate units (bytes, KB, MB, GB, TB, PB).

Usage

npm install bytes-formatter
# Or
yarn add bytes-formatter
import { formatBytes } from "bytes-formatter";

/**
 * Formats given <code>bytes</code> to human friendly format.
 * @param {number} bytes The bytes to be formatted.
 * @return {string} The formatted bytes as string.
 */
console.log(formatBytes(1000)); // "1000 bytes"
console.log(formatBytes(1024)); // "1.00 KB"
console.log(formatBytes(1000000)); // "976.56 KB"
console.log(formatBytes(2000000)); // "1.91 MB"
console.log(formatBytes(2000000000)); // "1.86 GB"
console.log(formatBytes(2000000000000)); // "1.82 TB"
console.log(formatBytes(Number.MAX_SAFE_INTEGER)); // "8.00 PB"

Keywords

bytes-formatter

FAQs

Package last updated on 15 Feb 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts