Socket
Socket
Sign inDemoInstall

filesize.js

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    filesize.js

filesize.js is a simple browserjs / nodejs library to make filesize human-readable.


Version published
Weekly downloads
3K
decreased by-18.12%
Maintainers
1
Install size
7.23 kB
Created
Weekly downloads
 

Readme

Source

filesize.js

filesize.js is a nano(350 b) library to make file size bytes human-readable. e.g. 20.4 Kb.

Build Status npm npm npm

Install

npm install filesize.js

Usage

The unique API is: fileSize(bytes[, fixed=1, spec='jedec']);.

  • bytes: Number of file size bytes.
  • fixed: Number of decimal, default is 1.
  • spec: String of file size spec, default is jedec.
// bytes.
filesize(123456); 				// '120.6 Kb'

// fixed, `1` is default.
filesize(123456, 0); 			// '121 Kb'
filesize(123456, 4); 			// '1120.5625 Kb'

// specs, `jedec` / `iec / si`.
// `jedec` is default.
filesize(123456, 2, 'iec'); 	// '120.56 Kib'
filesize(123456, 0, 'si'); 		// '123 kb'

Test

npm install

npm test

Spec

  • jedec: Unit is ['b', 'Kb', 'Mb', 'Gb', 'Tb', 'Pb', 'Eb', 'Zb', 'Yb'], and the power is 1024.
  • iec: Unit is ['b', 'Kib', 'Mib', 'Gib', 'Tib', 'Pib', 'Eib', 'Zib', 'Yib'], and the power is 1024.
  • si: Unit is ['b', 'kb', 'Mb', 'Gb', 'Tb', 'Pb', 'Eb', 'Zb', 'Yb'], and the power is 1000.

More specs waiting for your issues / pull requests.

LICENSE

MIT@hustcc.

Keywords

FAQs

Last updated on 10 Oct 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc