Registry / devops / tiny-byte-size

tiny-byte-size

JSON →
library1.1.0jsnpmunverified

A minimal, zero-dependency byte formatter for Node.js. Version 1.1.0 is stable with no active development. It formats byte counts into human-readable strings (e.g., 100B, 1kB, 10.1MB) and includes a perSecond helper for rates. Unlike larger libraries like filesize or pretty-bytes, it has no configuration, one function, and is a single file – ideal for simple CLI tools or logging where minimalism is key.

npm install tiny-byte-size
INSTALL
IMPORT
SIG · TINY-BYTE-SIZE
T
tiny-byte-size
devopsjavascriptv1.1.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

default
import byteSize from 'tiny-byte-size'
const byteSize = require('tiny-byte-size')
This package is CommonJS only; it does not support ESM. Use require for Node.js < 14, or use dynamic import with ESM.
byteSize
const byteSize = require('tiny-byte-size')
import { byteSize } from 'tiny-byte-size'
The default export is a function. Named exports are not available. Use require for correct CommonJS consumption.
byteSize.perSecond
const byteSize = require('tiny-byte-size'); byteSize.perSecond(10101010)
import { perSecond } from 'tiny-byte-size'
perSecond is a method on the default export, not a named export. It takes two arguments: bytes and optional time in seconds.

Basic usage: import the default function, call with byte count. Also demonstrates perSecond for throughput.

const byteSize = require('tiny-byte-size'); console.log(byteSize(100)); // 100B console.log(byteSize(1000)); // 1kB console.log(byteSize(1100)); // 1.1kB console.log(byteSize(10101010)); // 10.1MB console.log(byteSize.perSecond(10101010)); // 10.1MB/s console.log(byteSize.perSecond(10101010, 500)); // 20.2MB/s
Debug
Known issues
gotchaUses binary prefixes (kB = 1000 bytes, not 1024). This differs from many byte formatters that use binary (KiB = 1024). Expect results like '1kB' for 1000 bytes.
fix
Be aware that the formatting is decimal-based. If you need binary, use another library like 'filesize' or 'pretty-bytes'.
affects: all
gotchaNo support for negative numbers or zero bytes gracefully? Zero is displayed as '0B'. Negative numbers may produce unexpected formatting.
fix
Only pass non-negative integer byte values.
affects: all
deprecatedThe package is no longer actively maintained; last release was 4 years ago. No updates for Node.js compatibility or security fixes.
fix
Consider forking or using an alternative like 'filesize' if active maintenance is required.
affects: >=1.1.0
gotchaCommonJS-only: does not export ESM. Attempting to import with 'import byteSize from...' in ES modules fails unless using a bundler or createRequire.
fix
Use require() in CommonJS or wrap with createRequire in ES modules.
affects: all
Errors
Common errors & fixes
TypeError: byteSize is not a function
Using named import syntax `import { byteSize } from...` on a CommonJS default export.
fix
Use `import byteSize from 'tiny-byte-size'` if your environment supports default imports for CommonJS, or use `const byteSize = require('tiny-byte-size')`.
Cannot find module 'tiny-byte-size'
Package not installed or typo in package name.
fix
Run `npm install tiny-byte-size` and verify the spelling in your require/import statement.
byteSize.perSecond is not a function
Attempting to call `perSecond` on a number instead of the byteSize function object.
fix
Ensure you reference `byteSize.perSecond`, not `byteSize(1000).perSecond`. Example: `byteSize.perSecond(10101010)`.
Upgrade
Version history
1.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
tiny-byte-size — npm install tiny-byte-size · libregistry