Giter VIP home page Giter VIP logo

superbytes's Introduction

Superbytes

Superbytes is a Node.js library for converting bytes to human readable string format


npm npm NPM GitHub Workflow Status (with event) GitHub contributors

Description

Superbytes will help you convert bytes into other units understandable for humans. The library automatically converts bytes and returns a string with the most optimal unit representation. The library also allows you to set the precision of numbers following the decimal point and choose the output metric in the form of either the IEC standard (1024 bytes = 1 kibibyte) or SI (1000 bytes = 1 kilobyte).

By default superbytes converts to IEC units.

The current version supports loading library using both CommonJS and ESModules.

Installation

Latest version:

npm i superbytes@latest

Usage

Loading using CommonJS

const { superbytes } = require('superbytes');

superbytes(423551030);
// returns '403.93 MiB'
superbytes(423551030, 3);
// returns '403.930 MiB'
superbytes(72355103011, { metric: 'si'});
// returns '72.36 GB'
superbytes(3123123, { precision: 5});
// returns '2.97844 MiB'
superbytes(912839123, { metric: 'si', precision: 5});
// returns '912.83912 MB'

Loading using ES modules

import { superbytes } from 'superbytes';

superbytes(423551030);
// returns '403.93 MiB'
superbytes(423551030, 3);
// returns '403.930 MiB'
superbytes(72355103011, { metric: 'si'});
// returns '72.36 GB'
superbytes(3123123, { precision: 5});
// returns '2.97844 MiB'
superbytes(912839123, { metric: 'si', precision: 5});
// returns '912.83912 MB'

License

MIT © Damian Polak

superbytes's People

Contributors

damianpolak avatar twisteer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

avenir-zhang

superbytes's Issues

typescript problem

hi i want use this package but i have error in my react typescript project.i solved problem for my self by converting your code to typescript if you want i will send a merge request to reveiw code

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.