Socket
Socket
Sign inDemoInstall

@kodex-data/big-prototypes

Package Overview
Dependencies
Maintainers
3
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@kodex-data/big-prototypes

`@kodex-data/big-prototypes` is a library for extending the global `String` and `Number` prototypes with additional functionality related to big numbers and fractions.


Version published
Weekly downloads
0
Maintainers
3
Weekly downloads
 
Created
Source

@kodex-data/big-prototypes

@kodex-data/big-prototypes is a library for extending the global String and Number prototypes with additional functionality related to big numbers and fractions.

Installation

You can install @kodex-data/big-prototypes using yarn or npm:

yarn add @kodex-data/big-prototypes 

or

npm install @kodex-data/big-prototypes 

Usage

After importing the package, the global String and Number prototypes will be extended with the following methods:

String

  • toBN(base?: number): BigNumber: Converts a string to a BigNumber instance.
  • shiftedBy(n: number): string: Shifts the decimal point of a string by n places to the right.
  • shiftedBy(n: number, asBN: undefined | false | null): string: Shifts the decimal point of a string by n places to the right, returning a string value.
  • shiftedBy(n: number, asBN: true): BigNumber: Shifts the decimal point of a string by n places to the right, returning a BigNumber instance.
  • toFraction(): Fraction<string>: Converts a string to a fraction.
  • toFraction(asBigInt: true): Fraction<BigNumberJS>: Converts a string to a fraction, returning a Fraction instance with BigNumberJS values.
  • toFraction(asBigInt?: false): Fraction<string>: Converts a string to a fraction, returning a Fraction instance with string values.
  • toFraction(asBigInt?: boolean | false): Fraction<string | BigNumberJS>: Converts a string to a fraction, returning a Fraction instance with either string or BigNumberJS values, depending on the asBigInt argument.
  • prettyNum(): string: Formats a string number with commas for thousands separators.

Number

  • toBN(): BigNumber: Converts a number to a BigNumber instance.
  • toUint(add0x?: boolean): string: Converts a number to an unsigned integer string.
  • shiftedBy(n: number): string: Shifts the decimal point of a number by n places to the right, returning a string value.
  • shiftedBy(n: number, asBN: boolean): BigNumber: Shifts the decimal point of a number by n places to the right, returning a BigNumber instance.
  • noExponents(): string: Removes scientific notation from a number.
  • prettyNum(): string: Formats a number with commas for thousands separators.

Example

import '@kodex-data/big-prototypes'
const { mul, div } = '0.3'.toFraction()
console.log({ mul, div }) 

Output:

{ mul: '3/10', div: '10/3' }

Definitions

declare global {
    interface String {
        toBN(base?: number): BigNumber;
        shiftedBy(n: number): string;
        shiftedBy(n: number, asBN: undefined | false | null): string;
        shiftedBy(n: number, asBN: true): BigNumber;
        toFraction(): Fraction<string>;
        toFraction(asBigInt: true): Fraction<BigNumberJS>;
        toFraction(asBigInt?: false): Fraction<string>;
        toFraction(asBigInt?: boolean | false): Fraction<string | BigNumberJS>;
        prettyNum(): string;
    }
    interface Number {
        toBN(): BigNumber;
        toUint(add0x?: boolean): string;
        shiftedBy(n: number): string;
        shiftedBy(n: number, asBN: boolean): BigNumber;
        noExponents(): string;
        prettyNum(): string;
    }
}

Keywords

FAQs

Package last updated on 08 Mar 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc