npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

file-size

v1.0.0

Published

Lightweight filesize to human-readable / proportions w/o dependencies.

Downloads

336,040

Readme

File-size.js

filesize

File-size module for node.js for converting, manipulating, and handling file-sizes.

Features

  • Zero Dependencies.
  • Supports IEC (power 1024, default), SI (power 1000), and JEDEC (Alternative SI Unit Notation).
  • Conversion from bytes to K, M, G, and so forth...
  • Customizable human-readable output.

Installation

$ npm install file-size

Now require it in your files like so:

var filesize = require('file-size');

Usage

filesize(Number bytes, Object options)

Using filesize is very easy, a lot easier if you know the Specification Table. However, it's not required to know it, and in most cases you won't need it.

Initialization

Filesize works in a jQuery chainable manner so you can use multiple instances without trouble.

var size = filesize(186457865);

Options

var size = filesize(186457865, {
  fixed: 2,
  spacer: ' '
});
  • fixed - Number of positions after the decimal to show, default is 2
  • spacer - Space between the number and the unit, default is a space

size.human(String spec) -> String

Generates human readable filesize.

  • spec can be one of the following:
    • si
    • iec
    • jedec
IEC Specification

Default

Power of 1024

// outputs: 177.82 MiB
filesize(186457865).human();
SI Specification

Power of 1000

// outputs: 186.46 MB
filesize(186457865).human('si');
JEDEC Specification

Changes IEC default unit notation iB to B for the following: KB, MB, GB

The rest are in iB notation, as per JEDEC Specification.

// outputs: 186.46 MB
filesize(186457865).human('jedec');

size.to(String unit, String spec) -> String

Converts bytes to another filesize unit

  • unit of size can be one of the following:
    • B, KB, MB, GB, TB, PB, EB, ZB, YB
  • spec can be one of the following:
    • si
    • iec
    • jedec
IEC Specification

Default

// outputs: 177.82
filesize(186457865).to('MB');
SI Specification
// outputs: 186.46
filesize(186457865).to('MB', true);

size.calculate(String spec) -> Object

Calculates suffix, magnitude, fixed, non-fixed, bits (fixed, non-fixed) from specified bytes against the specified spec.

  • spec can be one of the following:
    • si
    • iec
    • jedec
/*
 * outputs:
 *
 *    {
 *      suffix: 'Bytes',
 *      magnitude: 0,
 *      result: 8,
 *      fixed: '8.00',
 *      bits: { result: 1, fixed: '1.00' }
 *    }
*/

var result = filesize(8).calculate()