Registry / serialization / prettysize

prettysize

JSON →
library2.0.0jsnpmunverified

A lightweight utility to convert byte counts into human-readable strings (e.g., 1024 → "1 kB") for logging and CLI output. Version 2.0.0 supports sizes from bytes up to exabytes, with options to remove spaces, use single-character suffixes, control decimal places, or return only the numeric value. Minimal dependencies, pure JavaScript, works in Node.js and browsers. Alternatives like filesize.js offer more formatting features, but prettysize focuses on simplicity and small footprint.

npm install prettysize
INSTALL
IMPORT
SIG · PRETTYSIZE
P
prettysize
serializationjavascriptv2.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

prettysize
const pretty = require('prettysize')
import pretty from 'prettysize'
prettysize uses CommonJS; default export is the function. ESM import is not supported natively; use a bundler or wrapper.
prettysize
import pretty from 'prettysize'
If using a bundler (e.g., webpack) with esModuleInterop, default import works. For Node.js ESM, use createRequire or dynamic import.
prettysize
const pretty = require('prettysize')
const { pretty } = require('prettysize')
The module exports a single function, not an object. Destructuring will result in undefined.

Demonstrates basic usage with a byte value, shows options for no space, single character suffix, decimal places, and numeric-only output.

const pretty = require('prettysize'); // Basic usage console.log(pretty(1024)); // "1 kB" console.log(pretty(1048576)); // "1 MB" // Options: remove space, single character, decimal places console.log(pretty(123456789, { nospace: true })); // "117.7M" console.log(pretty(123456789, { one: true, places: 2 })); // "117.74 M" console.log(pretty(123456789, { numOnly: true })); // 117.7
Debug
Known issues
breakingVersion 2.0.0 changed the default decimal places from 0 to 1.
fix
Update code to expect one decimal place by default, or explicitly set places option.
affects: >=2.0.0
deprecatedPositional arguments (true, true, 2) are deprecated in favor of options object.
fix
Use options object: { nospace: true, one: true, places: 2 } instead of positional args.
affects: >=2.0.0
gotchaThe function returns a string with a space by default (e.g., '1 kB'), which may not match expectations for pure numeric output.
fix
Use { nospace: true } to remove space, or { numOnly: true } to get a number directly.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: pretty is not a function
CommonJS require returns a module object; destructuring incorrectly.
fix
Use `const pretty = require('prettysize');` not `const { pretty } = require('prettysize');`
Error [ERR_REQUIRE_ESM]: require() of ES Module
Trying to require the package in a strict ESM context without proper handling.
fix
Use `import pretty from 'prettysize'` (with bundler) or `createRequire` from 'module'.
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
16 hits · last 30 days
node
14
OpenAI (training)
2
Resources
prettysize — npm install prettysize · libregistry