JSPM

filesize.js

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 4096
  • Score
    100M100P100Q144805F
  • License MIT

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

Package Exports

  • filesize.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (filesize.js) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

filesize.js

filesize.js is a simple browserjs / nodejs library to make filesize human-readable. e.g. 20.4 Kb.

Build Status npm npm npm

1. Install

npm install filesize.js

Then import it.

var filesize = require('filesize.js');

//or

import filesize from 'filesize.js';

Or import it with <script> tag.

<script type="text/javascript" src="filesize.min.js"></script>

2. Detail Usage

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

  • bytes: Number of filesize.
  • fixed: Number of decimal, default is 1.
  • spec: String of filesize 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'

3. Test

npm install npm test

4. 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 you issue / pull request.

5. LICENSE

MIT