Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
bignumber-fns
Advanced tools
Readme
Useful functions to make working with bignumber.js more enjoyable
npm i bignumber-fns bignumber.js
import { asBigNumber, formatNumber, isBigNumber } from "bignumber-fns"
isBigNumber(5) // => false
const five = asBigNumber(5)
isBigNumber(five) // => true
const six = asBigNumber("6")
isBigNumber(six) // => true
const seven = asBigNumber(new BigNumber(7))
isBigNumber(seven) // => true
const eighteen = five.plus(six).plus(seven)
isBigNumber(eighteen) // => true
formatNumber("1000.12") // => "1,000.12"
asBigNumber(value, { fallback?, base? })
Converts a BigNumber-Like param (string, number, BigNumber) and attempts to convert it to the BigNumber type. If the conversion fails (e.g. NaN is provided), it will attempt to return the fallback parameter as a BigNumber. If no fallback is provided, or if the fallback can not be converted to a BigNumber (e.g. NaN is provided), then the method will throw.
import { asBigNumber } from "bignumber-fns"
const value = "5"
const bignumber = asBigNumber(value, { fallback: 0 }) // returns a BigNumber of 5
const fallback = asBigNumber(undefined, { fallback: 0 }) // returns a BigNumber of 0
const hex = asBigNumber("AB", { base: 16 }) // returns a BigNumber of 171
const hexFallback = asBigNumber(undefined, { fallback: "A", base: 16 }) // returns a BigNumber of 10
isBigNumber(value)
Determines if a parameter is a BigNumber type, while also indicating to the Typescript parser to treat the item as a BigNumber going forward.
import { isBigNumber } from "bignumber-fns"
isBigNumber(5) // false
isBigNumber(new BigNumber(5)) // true
formatNumber(value, { numDecimals?, decimalSeparator?, thousandsSeparator? })
Format a number with thousands separators and a fixed number of decimal places.
import { formatNumber } from "bignumber-fns"
formatNumber(5) // "5"
formatNumber(5000.555555, { numDecimals: 1 }) // "5,000.6"
formatNumber(1000, { thousandsSeparator: "." }) // "1.000"
formatNumber("1.23", { decimalSeparator: "," }) // "1,23"
formatNumber(1234567890) // "1,234,567,890"
This project is maintained and funded by Catena Labs.
FAQs
Useful functions to make working with bignumber.js more enjoyable
The npm package bignumber-fns receives a total of 0 weekly downloads. As such, bignumber-fns popularity was classified as not popular.
We found that bignumber-fns demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.