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

web3-bignumber

v0.1.2

Published

Web3 BigNumber is an extensive library for managing large number for Javascript and Node.js. Useful for web3 development.

Downloads

104

Readme

Web3 BigNumber

npm package Downloads Issues ES Version Node Version

Web3 BigNumber is an extensive library for managing large number for Javascript and Node.js. Useful for web3 development.

Installation

You can install the package using NPM

Using NPM

npm install web3-bignumber

Using Yarn

yarn add web3-bignumber

Getting Started

Prerequisites

Usage

Import

const { Web3BigNumber } = require("web3-bignumber");

OR

import { Web3BigNumber } from "web3-bignumber";
Web3BigNumber(number: bigint | string | number)

Basic Usage


Simple Formatting

Web3BigNumber(1e+27).value();
// Output: 1000000000000000000000000000

From small to big

Web3BigNumber(1000).toBig(18);
// Output: 1000000000000000000000

From big to small

Web3BigNumber("12300000000000000").toSmall(18);
// Output: 0.0123

Arithmatic Operations


Addition

Web3BigNumber("100").add(50);
// Output: 150

Subtract

Web3BigNumber("100").subtract(50);
// Output: 50

Multiply

Web3BigNumber("100").multiply(5);
// Output: 500

Division

Web3BigNumber("50").divide(5);
// Output: 10

Manipulate


To Big Integer

Web3BigNumber("1234500000000000").toBigInt();
// Output: 1234500000000000n

To Integer

Web3BigNumber("123").toInteger();
// Output: 123

Comma Seperated

Web3BigNumber("1234500000000").toCommaSeparated();
// Output: 1,234,500,000,000

Compact Number

Web3BigNumber("1000000").toCompactNumber();
// Output: 1M

Percentage

Web3BigNumber("0.123").toPercent();
// Output: 12.3%

Fixed Decimal Places

Web3BigNumber("12.34567").trimDecimalPlaces(2);
// Output: 12.35

Conditional Check


Check Zero

Web3BigNumber(0).isZero();
// Output: true

Web3BigNumber(1).isZero();
// Output: false

Check Negative

Web3BigNumber(-123).isNegative();
// Output: true

Web3BigNumber(123).isNegative();
// Output: false

Equal

Web3BigNumber(123).equals("123");
// Output: true

Web3BigNumber(123).equals(456);
// Output: false

Greater Than

Web3BigNumber(123).gt("5");
// Output: true

Web3BigNumber(123).gt(456);
// Output: false

Greater Than or Equal

Web3BigNumber(123).gte("123");
// Output: true

Web3BigNumber(123).gte(456);
// Output: false

Less Than

Web3BigNumber(123).lt("1234");
// Output: true

Web3BigNumber(123).lt(5);
// Output: false

Less Than or Equal

Web3BigNumber(123).lte("123");
// Output: true

Web3BigNumber(123).lte(5);
// Output: false

Check Maximum

Web3BigNumber(123).max("1234");
// Output: 1234

Check Minimum

Web3BigNumber(123).min("1234");
// Output: 123

Prototype Functions

// Example
Web3BigNumber(1000).subtract("1000").isZero();
// Output: true

All Prototype Functions


String | Number | BigInt
  • toBigInt()
  • toCommaSeparated()
  • toCompactNumber()
  • toPercent()
  • toInteger()
  • isZero()
  • isNegative()
  • equals(num2: number | string | bigint)
  • gt(num2: number | string | bigint)
  • gte(num2: number | string | bigint)
  • lt(num2: number | string | bigint)
  • lte(num2: number | string | bigint)
  • add(num2: number | string | bigint)
  • subtract(num2: number | string | bigint)
  • multiply(num2: number | string | bigint)
  • divide(num2: number | string | bigint)
  • max(num2: number | string | bigint)
  • min(num2: number | string | bigint)