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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@f-o-t/bigint

v1.0.4

Published

Low-level bigint primitives for precise decimal arithmetic

Readme

@f-o-t/bigint

Low-level bigint primitives for precise decimal arithmetic. Provides standardized bigint operations across all FOT libraries.

Installation

bun add @f-o-t/bigint

Features

  • ✅ Parse decimal strings/numbers to bigint with configurable scale
  • ✅ Format bigint to decimal strings with trailing zero control
  • ✅ Arithmetic operations (add, subtract, multiply, divide)
  • ✅ Comparison operations (equals, greater than, less than, etc.)
  • ✅ Multiple rounding modes (truncate, banker's rounding, ceil, floor)
  • ✅ Scale conversion utilities
  • ✅ Zod-based validation throughout
  • ✅ Optional condition-evaluator integration

Core Usage

Parsing

import { parseToBigInt } from "@f-o-t/bigint";

// Parse decimal string to bigint
const value1 = parseToBigInt({ value: "10.50", scale: 2 });  // 1050n (scale 2)
const value2 = parseToBigInt({ value: "123.456", scale: 3 }); // 123456n (scale 3)

// Different rounding modes
parseToBigInt({ value: "10.999", scale: 2, roundingMode: "truncate" });  // 1099n (default)
parseToBigInt({ value: "10.999", scale: 2, roundingMode: "round" });     // 1100n (banker's rounding)
parseToBigInt({ value: "10.999", scale: 2, roundingMode: "ceil" });      // 1100n (round up)
parseToBigInt({ value: "10.999", scale: 2, roundingMode: "floor" });     // 1099n (round down)

Formatting

import { formatFromBigInt } from "@f-o-t/bigint";

// Format bigint to decimal string
formatFromBigInt({ value: 1050n, scale: 2 });        // "10.5" (trims trailing zeros)
formatFromBigInt({ value: 1050n, scale: 2, trimTrailingZeros: false }); // "10.50" (keeps trailing zeros)
formatFromBigInt({ value: 100n, scale: 0 });         // "100" (no decimals)

Arithmetic

All arithmetic operations require the same scale for both operands.

import { add, subtract, multiply, divide } from "@f-o-t/bigint";

// Addition and subtraction
add({ a: 1050n, b: 525n, scale: 2 });       // 1575n (10.50 + 5.25 = 15.75)
subtract({ a: 1050n, b: 525n, scale: 2 });  // 525n (10.50 - 5.25 = 5.25)

// Multiplication (result maintains scale)
multiply({ a: 1000n, b: 500n, scale: 2 });  // 5000n (10.00 * 5.00 = 50.00)

// Division with rounding
divide({ a: 10000n, b: 300n, scale: 2 });            // 3333n (truncate, default)
divide({ a: 10000n, b: 300n, scale: 2, roundingMode: "round" });   // 3333n (banker's rounding)
divide({ a: 10000n, b: 300n, scale: 2, roundingMode: "ceil" });    // 3334n

Comparison

import { compare, equals, greaterThan, lessThan } from "@f-o-t/bigint";

compare({ a: 100n, b: 50n, scale: 2 });     // 1 (greater)
compare({ a: 50n, b: 100n, scale: 2 });     // -1 (less)
compare({ a: 100n, b: 100n, scale: 2 });    // 0 (equal)

equals({ a: 100n, b: 100n, scale: 2 });     // true
greaterThan({ a: 100n, b: 50n, scale: 2 }); // true
lessThan({ a: 50n, b: 100n, scale: 2 });    // true

Rounding & Scale Conversion

import { bankersRound, convertScale } from "@f-o-t/bigint";

// Banker's rounding (round half to even)
bankersRound(25n, 10n);  // 2n (2.5 → 2, even)
bankersRound(35n, 10n);  // 4n (3.5 → 4, even)

// Convert between scales
convertScale({ value: 100n, fromScale: 2, toScale: 4 });              // 10000n (1.00 @ 2 → 1.0000 @ 4)
convertScale({ value: 10050n, fromScale: 4, toScale: 2, roundingMode: "round" });   // 100n (1.0050 @ 4 → 1.00 @ 2, banker's rounding to even)
convertScale({ value: 10050n, fromScale: 4, toScale: 2, roundingMode: "truncate" }); // 100n (1.0050 @ 4 → 1.00 @ 2)

Condition-Evaluator Integration

Optional integration with @f-o-t/condition-evaluator for rule-based evaluations.

import { createEvaluator } from "@f-o-t/condition-evaluator";
import {
  bigintEqualsOperator,
  bigintGreaterThanOperator,
  bigintBetweenOperator
} from "@f-o-t/bigint/operators";

const evaluator = createEvaluator({
  operators: {
    bigint_eq: bigintEqualsOperator,
    bigint_gt: bigintGreaterThanOperator,
    bigint_between: bigintBetweenOperator,
  }
});

// Evaluate conditions
evaluator.evaluate({
  type: "custom",
  field: "measurement",
  operator: "bigint_gt",
  value: { value: 10000n, scale: 2 }  // 100.00
}, {
  data: {
    measurement: { value: 15000n, scale: 2 }  // 150.00
  }
}); // true

// Range checks
evaluator.evaluate({
  type: "custom",
  field: "amount",
  operator: "bigint_between",
  value: {
    min: { value: 0n, scale: 2 },
    max: { value: 10000n, scale: 2 }
  }
}, {
  data: {
    amount: { value: 5000n, scale: 2 }  // 50.00
  }
}); // true

Available Operators

Comparison:

  • bigint_eq - Equals
  • bigint_neq - Not equals
  • bigint_gt - Greater than
  • bigint_gte - Greater than or equal
  • bigint_lt - Less than
  • bigint_lte - Less than or equal

Range/State:

  • bigint_between - Value within range (inclusive)
  • bigint_zero - Value is zero
  • bigint_positive - Value is positive
  • bigint_negative - Value is negative

Validation

All functions use Zod schemas for input validation:

import { ParseInputSchema, ScaledBigIntSchema } from "@f-o-t/bigint";

// Validate parse inputs
ParseInputSchema.parse({ value: "10.5", scale: 2 });  // ✓
ParseInputSchema.parse({ value: "abc", scale: 2 });   // ✗ throws ZodError

// Validate scaled bigint
ScaledBigIntSchema.parse({ value: 100n, scale: 2 });  // ✓
ScaledBigIntSchema.parse({ value: "100", scale: 2 }); // ✗ throws ZodError

Type Exports

import type {
  RoundingMode,
  ScaledBigInt,
  ParseInput,
  ArithmeticInput
} from "@f-o-t/bigint";

const mode: RoundingMode = "round";
const value: ScaledBigInt = { value: 100n, scale: 2 };

Design Philosophy

This library provides low-level primitives only:

  • No domain-specific concepts (use @f-o-t/money or @f-o-t/uom for that)
  • All operations require explicit scale parameters
  • Arithmetic operations enforce same-scale requirement
  • Zod handles all validation (no custom error classes)

License

MIT