Skip to content

arraypress/file-size

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@arraypress/file-size

Format byte counts as human-readable file sizes. One function, zero dependencies.

Installation

npm install @arraypress/file-size

Usage

import { formatSize } from '@arraypress/file-size';

formatSize(0)              // '0 B'
formatSize(1024)           // '1.0 KB'
formatSize(52428800)       // '50.0 MB'
formatSize(1073741824)     // '1.0 GB'
formatSize(1099511627776)  // '1.0 TB'

// Custom decimal places
formatSize(1536, 2)        // '1.50 KB'
formatSize(1536, 0)        // '2 KB'

API

formatSize(bytes, decimals?)

Returns a human-readable string. Uses binary units (1 KB = 1024 bytes). Bytes are shown without decimals, larger units default to 1 decimal place. Returns empty string for null/undefined/negative values.

License

MIT

About

Format byte counts as human-readable file sizes.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors