Skip to content

itsmnthn/big-utils

Repository files navigation

BigInt Utils for DApps

Utils for BigInt manipulation and formatting for DeFi/Blockchain applications(DAPPS).

ESM: 50.77 kB  │  gzip: 13.81 kB
CJS: 52.37 kB  │  gzip: 14.07 kB

Installation

pnpm add @itsmnthn/big-utils@latest
yarn add @itsmnthn/big-utils@latest
npm install @itsmnthn/big-utils@latest
bun add @itsmnthn/big-utils@latest

Quick Start

import {
  // Core math functions
  bigAbs,
  bigGcd,
  bigLog2Scaled,

  // Advanced arithmetic
  bigMulDivTrunc,
  bigPow10,
  // Scaling & formatting
  bigScale,

  bigSqrtScaled,
  bigUnscale,
  // DeFi utilities
  calcTotalPrice,

  calcUnitPrice,
  formatAmount,
  formatWithComma,
} from '@itsmnthn/big-utils'

// Calculate token price with 18 decimals
const price = calcTotalPrice(1000000000000000000n, 1500000000n, 18, 9)
// Result: 1500000000000000000n (1.5 USD with 9 decimals)

// Format for display
const displayPrice = formatAmount(price, 9, 2)
// { base: 1500000000000000000n, display: '1.50', formatted: '1.5' }

Key Features

  • Zero Dependencies - Pure BigInt operations
  • Tree-Shakeable - Import only what you need
  • TypeScript First - Full type safety
  • High Performance - Optimized BigInt operations
  • DeFi Ready - Token price calculations, formatting
  • Modular Design - Clean, maintainable architecture

Migration from v1.x

coming soon

There are breaking changes in v2.0.0. some function renamed & some parameters changed.

Documentation

📚 v1 API Documentation


Made with ❤️ for the DeFi ecosystem

About

Zero dependency bigint unit converters and formatters

Resources

License

Stars

Watchers

Forks

Packages

No packages published