@febin52/fast-bytes
v1.0.2
Published
Ultra-fast human-readable byte parser and formatting utility with zero dependencies.
Maintainers
Readme
⚡ @febin52/fast-bytes
High-performance, zero-dependency human-readable byte parser and formatting utility for Node.js, browsers, and Edge runtimes.
Convert raw numbers into formatted byte strings (1.5 MB, 1 KiB) and parse human-readable byte values back into raw integer bytes seamlessly with maximum speed and zero dependencies.
🚀 Features
- ⚡ Ultra Fast: Optimized math algorithms for parsing and formatting.
- 📦 Zero Dependencies: Lightweight sub-kilobyte bundle footprint.
- 🔠 Binary & Decimal Support: Handles both standard SI units (
KB,MB,GB) and IEEE binary units (KiB,MiB,GiB). - 🛡️ Type-Safe: Full TypeScript declarations out of the box.
📦 Installation
npm install @febin52/fast-bytes
# or
yarn add @febin52/fast-bytes
# or
pnpm add @febin52/fast-bytes💡 Usage
Formatting Bytes (formatBytes)
import { formatBytes } from '@febin52/fast-bytes';
// Decimal (Standard SI)
formatBytes(1000); // '1 KB'
formatBytes(1572864); // '1.57 MB'
formatBytes(1000000000); // '1 GB'
// Binary (IEC Standards)
formatBytes(1024, { binary: true }); // '1 KiB'
formatBytes(1048576, { binary: true }); // '1 MiB'
// Custom Decimal Precision
formatBytes(1572864, { decimals: 1 }); // '1.6 MB'
formatBytes(1572864, { decimals: 0 }); // '2 MB'Parsing Byte Strings (parseBytes)
import { parseBytes } from '@febin52/fast-bytes';
parseBytes('1.5 MB'); // 1500000
parseBytes('1 KiB'); // 1024
parseBytes('2.5 GB'); // 2500000000
parseBytes('500 B'); // 500🔗 Links
- NPM Package: https://www.npmjs.com/package/@febin52/fast-bytes
- GitHub Repository: https://github.com/febin52/fast-bytes
- Issue Tracker: https://github.com/febin52/fast-bytes/issues
📄 License
MIT © Febin Francis
