Skip to content

Repository files navigation

bytesize

bytesize mark

Parse, format, inspect, and convert SI and IEC byte sizes with a tiny runtime-neutral API.

JSR version 1.2.0 license MIT

Package: @theworker02/bytesize · Docs: GitHub Pages · Source: theworker02/bytesize

Highlights

  • Parses values such as 1.5KiB, 2MB, and 64B.
  • Formats byte counts using IEC or SI units.
  • Converts values between unit systems.
  • Exposes unit metadata through describeUnit().
  • Provides IEC_UNITS, SI_UNITS, and isSize() for introspection and validation.
  • Fully documented TypeScript symbols on JSR.
  • Runtime-neutral implementation with no filesystem or platform APIs.

Add from JSR

deno add jsr:@theworker02/bytesize
import {
  convert,
  describeUnit,
  formatIec,
  isSize,
  PACKAGE,
  parseSize,
} from "@theworker02/bytesize";

console.log(parseSize("1.5KiB"));        // 1536
console.log(formatIec(1536));            // 1.50KiB
console.log(convert("2MB", "MiB"));
console.log(describeUnit("GiB"));
console.log(isSize("42KB"), PACKAGE.version);

Public API

Parsing and formatting

  • parseSize(input) — parse SI or IEC text into bytes.
  • formatIec(bytes) — format bytes using binary units.
  • formatSi(bytes) — format bytes using decimal units.
  • convert(input, unit) — convert a value to a target unit.

Introspection

  • isSize(value) — validate a human-readable size string.
  • describeUnit(unit) — return the unit system, base, and exponent.
  • IEC_UNITS and SI_UNITS — ordered supported unit sets.
  • PACKAGE — package identity and release metadata.

Types

IecUnit, SiUnit, SizeUnit, ConversionResult, UnitDescription, and PackageMetadata are documented in JSR.

CLI from source

git clone https://github.com/theworker02/bytesize.git
cd bytesize
node src/cli.js --help

Examples:

node src/cli.js 1.5KiB
node src/cli.js convert 2MB --to MiB

Development

node --test

Publishing

The canonical package is published to JSR through GitHub Actions using OIDC trusted publishing.

Documentation

License

Source-available proprietary — evaluation under LICENSE; commercial / production use via COMMERCIAL.md. See LICENSE_TRANSITION_NOTICE.md and NOTICE.

About

Parse, format, and convert human byte sizes (SI and IEC). npm: https://www.npmjs.com/package/%40magnexis/bytesize

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages