Giter Site home page Giter Site logo

file-size's Introduction

file-size

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', 'si');

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()

file-size's People

Contributors

nijikokun avatar tracker1 avatar trodrigues avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

file-size's Issues

Plural bytes

If the number of bytes is not 1 then add an "s".

screen shot 2015-04-02 at 2 52 44 pm

Please include full text of the license in your repository

Hi,
"MIT" can be ambiguous, as any other shorthand license name. The only way to properly license your software is to include the full text into it.
It is usually put in a LICENSE file, but some authors put it into the README.md as
well.

Regards,
Jรฉrรฉmy.

Typescript type definitions

I'd like to contribute typescript definitions for your library, if you are interested, and I would be happy to help maintain them in that case. Feel free to say no, not all projects care to host their own type information for various reasons, but it's certainly the best experience when a project does bundle its own type definitions in with its npm package.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.