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

digital-unit-converter-bignumber

v1.0.1

Published

Utility to simplify conversion of arbitrary-precision digital units of measurement

Downloads

10

Readme

digital-unit-converter-bignumber

Utility to simplify conversion of arbitrary-precision digital units of measurement

Installation

Using npm

$ npm install digital-unit-converter-bignumber --save

Using yarn

$ yarn add digital-unit-converter-bignumber

Import module

CommonJS

const { DataUnit } = require('digital-unit-converter-bignumber');

ES6

import { DataUnit } from 'digital-unit-converter-bignumber';

Examples

JavaScript: convert 10 megabytes (MB) to bytes (B)

let converted = DataUnit.MEGABYTE.toBytes(BigNumber(10));
console.log(converted.toString()); // 10000000

// or use convert() instead
converted = DataUnit.BYTE.convert(BigNumber(10), DataUnit.MEGABYTE);
console.log(converted.toString()); // 10000000

TypeScript: convert 1 gibibyte (GiB) to mebibytes (MiB)

let converted: BigNumber = DataUnit.GIBIBYTE.toMebibytes(BigNumber(1));
console.log(converted.toString()); // 1024

// or use convert() instead
converted = DataUnit.MEBIBYTE.convert(BigNumber(1), DataUnit.GIBIBYTE);
console.log(converted.toString()); // 1024

Supported Data Units

The following data units are currently supported.

| DataUnit | Term | Abbreviation | Unit Type | Number of Bytes | | :--- | :--- | :--- | :--- | :--- | | BIT | bit | b | - | 0.125 | | BYTE | byte | B | - | 1 | | KILOBYTE | kilobyte | kB | Decimal | 103 | | KIBIBYTE | kibibyte | KiB | Binary | 210 | | MEGABYTE | megabyte | MB | Decimal | 106 | | MEBIBYTE | mebibyte | MiB | Binary | 220 | | GIGABYTE | gigabyte | GB | Decimal | 109 | | GIBIBYTE | gibibyte | GiB | Binary | 230 |

Static Members

BIT

Static Readonly BIT: DataUnit

Bit (b). Data unit representing a binary digit

Defined in: index.ts:12


BYTE

Static Readonly BYTE: DataUnit

Byte (B). Data unit representing 8 bits

Defined in: index.ts:27


GIBIBYTE

Static Readonly GIBIBYTE: DataUnit

Gibibyte (GiB). Binary data unit representing 1,0243 bytes

Defined in: index.ts:117


GIGABYTE

Static Readonly GIGABYTE: DataUnit

Gigabyte (GB). Decimal data unit representing 1,0003 bytes

Defined in: index.ts:102


KIBIBYTE

Static Readonly KIBIBYTE: DataUnit

Kibibyte (KiB). Binary data unit representing 1,024 bytes

Defined in: index.ts:57


KILOBYTE

Static Readonly KILOBYTE: DataUnit

Kilobyte (kB). Decimal data unit representing 1,000 bytes

Defined in: index.ts:42


MEBIBYTE

Static Readonly MEBIBYTE: DataUnit

Mebibyte (MiB). Binary data unit representing 1,0242 bytes

Defined in: index.ts:87


MEGABYTE

Static Readonly MEGABYTE: DataUnit

Megabyte (MB). Decimal data unit representing 1,0002 bytes

Defined in: index.ts:72

Methods

convert

convert(val: BigNumber, unit: DataUnit): BigNumber

Converts the value (val) in the specified data unit (unit) to this unit

Parameters:

Name | Type | Description | :------ | :------ | :------ | val | BigNumber | value to convert | unit | DataUnit | data unit of val |

Returns: BigNumber

converted value in this unit

Defined in: index.ts:261


toBits

toBits(val: BigNumber): BigNumber

Convert a value in this unit to bits (b)

Parameters:

Name | Type | Description | :------ | :------ | :------ | val | BigNumber | value to convert to bits |

Returns: BigNumber

converted bit value

Defined in: index.ts:180


toBytes

toBytes(val: BigNumber): BigNumber

Convert a value in this unit to bytes (B)

Parameters:

Name | Type | Description | :------ | :------ | :------ | val | BigNumber | value to convert to bytes |

Returns: BigNumber

converted byte value

Defined in: index.ts:190


toGibibytes

toGibibytes(val: BigNumber): BigNumber

Convert a value in this unit to gibibytes (GiB)

Parameters:

Name | Type | Description | :------ | :------ | :------ | val | BigNumber | value to convert to gibibytes |

Returns: BigNumber

converted gibibyte value

Defined in: index.ts:250


toGigabytes

toGigabytes(val: BigNumber): BigNumber

Convert a value in this unit to gigabytes (GB)

Parameters:

Name | Type | Description | :------ | :------ | :------ | val | BigNumber | value to convert to gigabytes |

Returns: BigNumber

converted gigabyte value

Defined in: index.ts:240


toKibibytes

toKibibytes(val: BigNumber): BigNumber

Convert a value in this unit to kibibytes (KiB)

Parameters:

Name | Type | Description | :------ | :------ | :------ | val | BigNumber | value to convert to kibibytes |

Returns: BigNumber

converted kibibyte value

Defined in: index.ts:210


toKilobytes

toKilobytes(val: BigNumber): BigNumber

Convert a value in this unit to kilobytes (kB)

Parameters:

Name | Type | Description | :------ | :------ | :------ | val | BigNumber | value to convert to kilobytes |

Returns: BigNumber

converted kilobyte value

Defined in: index.ts:200


toMebibytes

toMebibytes(val: BigNumber): BigNumber

Convert a value in this unit mebibytes (MiB)

Parameters:

Name | Type | Description | :------ | :------ | :------ | val | BigNumber | value to convert to mebibytes |

Returns: BigNumber

converted mebibyte value

Defined in: index.ts:230


toMegabytes

toMegabytes(val: BigNumber): BigNumber

Convert a value in this unit to megabytes (MB)

Parameters:

Name | Type | Description | :------ | :------ | :------ | val | BigNumber | value to convert to megabytes |

Returns: BigNumber

converted megabyte value

Defined in: index.ts:220