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

bignumber-arr-utils

v0.1.0

Published

A lightweight utility library designed for efficient manipulation and calculation of large numbers within arrays

Downloads

142

Readme

bignumber-arr-utils

A lightweight utility library designed for efficient manipulation and calculation of large numbers within arrays. Perfect for financial, scientific, and blockchain-related projects, this package provides a set of functions that handle operations on arrays of big numbers with precision and ease.

Install

npm i bignumber-arr-utils

Usage

To get started, import the BigNumberArrUtils class from the package:

import BigNumber from 'bignumber.js';
import { BigNumberArrUtils } from 'bignumber-arr-utils';

Example Usage

Creating an Instance

Creates an instance of BigNumberArrUtils and initializes the array with valid BigNumber instances.

  • Parameters:
    • ...n - A list of values to be converted to BigNumber and added to the array.
const arr = new BigNumberArrUtils(1, '2', new BigNumber(3));

Getting the items on the array

Returns the list of BigNumber instances in the array.

const arr = new BigNumberArrUtils(1, '2', new BigNumber(3));
console.log(arr.items); // [BigNumber(1), BigNumber(2), BigNumber(3)]

Adding Items

Adds a new BigNumber instance to the array. Returns false if the given input is not a valid BigNumber.Value. Returns true if the new BigNumber instance has been added to the array.

  • Parameters:
    • n - The value to be added as a BigNumber.
const arr = new BigNumberArrUtils();
console.log(arr.add(-0.8)); // true
console.log(arr.add('abc')); // false
console.log(arr.add(3e18)); // true
console.log(arr.items); // [BigNumber(-0.8), BigNumber(3e+18)]

Removing Items

Removes an instance of BigNumber from the array. Returns false if the given input is not found in the array. Returns true if the BigNumber has been removed from the array.

  • Parameters:
    • n - The value to be removed from the array.
const arr = new BigNumberArrUtils(-0.8, 3e18, 1.0000000000000001);
console.log(arr.remove(-1)); // false
console.log(arr.remove(3e18)); // true
console.log(arr.items); // [BigNumber(-0.8), BigNumber(1.0000000000000001)]

Calculating the Sum

Returns the sum of all BigNumber instances in the array.

const arr = new BigNumberArrUtils(-0.8, 3e18, 1.0000000000000001);
console.log(arr.sum().toString()); // "3000000000000000001.2"

Determining the Min

Returns the minimum of all BigNumber instances in the array.

const arr = new BigNumberArrUtils(-0.8, 3e18, 1.0000000000000001);
console.log(arr.min().toString()); // "-0.8"

Determining the Max

Returns the maximum of all BigNumber instances in the array.

const arr = new BigNumberArrUtils(-0.8, 3e18, 1.0000000000000001);
console.log(arr.max().toString()); // "3e18"

Checking for an Item in the Array

The includes method checks if a specific BigNumber value is present in the array. It returns true if the value is found, and false otherwise.

  • Parameters:

    • n - The value to check for in the array.
  • Returns:

    • boolean - true if the array contains the specified value; otherwise, false.
const arr = new BigNumberArrUtils(-0.8, 3e18, 1.0000000000000001, 5);
console.log(arr.includes(5)); // true
console.log(arr.includes(new BigNumber(6))); // false
console.log(arr.includes('3e18')); // true
console.log(arr.includes(1.1)); // false

Contributing

If you want to contribute to this project, please follow these steps:

Licence

The MIT Licence.

See LICENCE.