Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

file-size

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

file-size

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

  • 0.0.3
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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 converter = filesize(186457865);

Options

var converter = 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
Human Readable
filesize.human(Object spec)
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: true });
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: true });
Conversion
.to(String unit, Boolean si)
IEC Specification

Default

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

Keywords

FAQs

Package last updated on 16 Dec 2013

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc