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

@wtfcode/byte-converter

v2.0.8

Published

Convert any value from a bit/byte unit measure to an another bit/byte measure, this package is compliant to IEC standard. EX: you can convert from KiB to kB or to Kib, Use the autoScale function for scale a given value and dataFormat to te best dataFormat

Downloads

978

Readme

Full Documentation

Getting Started

This package is compliant to IEC standard units. see Units Table for supported units
Convert any value from a supported unit to an another supported unit.
Compare any value or unit to another one. Sum, Subtract, Multiply and Divide two value with any supported unit.
Use the autoScale function for scale a given value and unit to te best unit for representing the value.

Install

  • yarn add @wtfcode/byte-converter

or

  • npm i @wtfcode/byte-converter

Exports

Default

  • class ByteConverter

Named

  • class Unit
  • class UnitValue
  • class ByteConverter
  • const b: Unit
  • const B: Unit

Changelog

| from | to | description | | ------ | ------ | ----------------------------------------------------------------------------------------------------------- | | 2.0.1 | 2.0.5 | Added Arithmetic method to UnitValue | | | 2.0.1 | Rewrited the byteConverter implementation in typescript and heavily simplified the algorithm | | 1.7.10 | 1.7.11 | autoScale now choose between 1000 and 1024 if is decimal type or binary type, the autoscaling is now better |

Example

ES6 syntax:

import {
  ByteConverter,
  Unit,
  UnitValue,
  B as Byte,
} from "@wtfcode/byte-converter";

console.log(ByteConverter.convert(Byte.value(1), "b")); //will output 8

console.log(ByteConverter.convert(ByteConverter.value(1024, "MiB"), "GiB")); //will output 1

console.log(new UnitValue(1024, "B").autoScale());

//will output: UnitValue {value: 1, unit: Unit { unit: "KiB", type: "binary", unitOrder: 1, name: "kibibyte" ... } } // the function return a UnitValue scaled

ES5 syntax:

const ByteConverter = require("@wtfcode/byte-converter").default;

console.log(ByteConverter.convert(ByteConverter.value(1024, "MiB"), "GiB")); //will output 1

console.log(ByteConverter.autoScale(ByteConverter.value(0.7, "GB"))); //the function accept a third paramater: an option object

//will output: UnitValue {value: 700, unit: Unit { unit: "MB", type: "decimal", unitOrder: 2, name: "megabyte" ... } }

Units Table

| unit | bit | byte | binary | decimal | | ------- | --- | ---- | ------ | ------- | | b | ✅ | | ✅ | | | B | | ✅ | ✅ | | | kb | ✅ | | | ✅ | | kB | | ✅ | | ✅ | | Kib | ✅ | | ✅ | | | KiB | | ✅ | ✅ | | | Mb | ✅ | | | ✅ | | MB | | ✅ | | ✅ | | Mib | ✅ | | ✅ | | | MiB | | ✅ | ✅ | | | Gb | ✅ | | | ✅ | | GB | | ✅ | | ✅ | | Gib | ✅ | | ✅ | | | GiB | | ✅ | ✅ | | | Tb | ✅ | | | ✅ | | TB | | ✅ | | ✅ | | Tib | ✅ | | ✅ | | | TiB | | ✅ | ✅ | | | Pb | ✅ | | | ✅ | | PB | | ✅ | | ✅ | | Pib | ✅ | | ✅ | | | PiB | | ✅ | ✅ | | | Eb | ✅ | | | ✅ | | EB | | ✅ | | ✅ | | Eib | ✅ | | ✅ | | | EiB | | ✅ | ✅ | | | Zb | ✅ | | | ✅ | | ZB | | ✅ | | ✅ | | Zib | ✅ | | ✅ | | | ZiB | | ✅ | ✅ | | | Yb | ✅ | | | ✅ | | YB | | ✅ | | ✅ | | Yib | ✅ | | ✅ | | | YiB | | ✅ | ✅ | |