xbits
v0.2.0
Published
Convert bits and bytes to a human readable string
Downloads
410
Readme
xbits
Convert bytes to a human readable string:
1337
→1.34 KiB
Useful for displaying file sizes / traffic / bandwidth / network speed for humans.
Install
# npm
npm install xbits
# yarn
yarn add xbits
# pnpm
pnpm add xbits
Usage
createPrettyBits
import { createPrettyBits, prettyBitsPresets } from 'xbits';
const prettyTraffic = createPrettyBits(prettyBitsPresets.traffic);
// You can also import `prettyTraffic` directly from `xbits`:
// import { prettyTraffic } from 'xbits';
const prettyBandwidth = createPrettyBits(prettyBitsPresets.bandwidth);
// You can also import `prettyBandwidth` directly from `xbits`:
// import { prettyBandwidth } from 'xbits';
// You can also create your own formatter function using custom presets:
const pretty = createPrettyBits({
bits: false,
binary: false,
speed: false,
largeK: true
});
pretty(42);
pretty(0xd000721, {
space: true,
signed: false,
minimumFractionDigits: undefined,
maximumFractionDigits: undefined,
});
prettyBits
import { prettyBits } from 'xbits';
prettyBits(42);
prettyBits(0721, {
bits: false,
binary: false,
speed: false,
largeK: true,
space: true,
signed: false,
minimumFractionDigits: undefined,
maximumFractionDigits: undefined,
locale: undefined
});
Differences with pretty-bytes
xbits
prefers uppercaseK
instead ofk
in units (still configurable vialargeK
option).xbits
supportsspeed
option (KB/s
,GiB/s
,Mbps
, etc.).xbits
has first-party supports for network traffic and bandwidth.
xbits © Sukka, Released under the MIT License. Authored and maintained by Sukka with help from contributors (list).
Personal Website · Blog · GitHub @SukkaW · Telegram Channel @SukkaChannel · Mastodon @[email protected] · Twitter @isukkaw · Keybase @sukka