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

@lp-labs/loan-amortization

v0.1.0

Published

Exact bigint-cent fixed-rate loan schedules with balloon, equal-principal, and zero-rate support.

Readme

@lp-labs/loan-amortization

Exact fixed-rate loan schedules in integer cents. Payments and interest are computed with bigint rational arithmetic and rounded once per figure with a rounding mode you choose, so there is no floating-point drift. Supports level payments, equal-principal repayment, balloon amounts, and zero rates.

Install

npm install @lp-labs/loan-amortization

ES2022 ESM and CommonJS builds ship with TypeScript declarations. There are no runtime dependencies.

Quickstart

import { buildLoanSchedule, regularPaymentCents } from '@lp-labs/loan-amortization';

const loan = { principalCents: 10_000_000n, annualRate: 0.06, periods: 360 };
if (regularPaymentCents(loan) !== 59955n) throw new Error('unexpected payment');

const schedule = buildLoanSchedule({ ...loan, balloonCents: 2_000_000n, currency: 'USD' });
console.log(schedule.regularPaymentCents, schedule.finalAdjustmentCents, schedule.rows.length);

API

type RoundingMode = 'floor' | 'ceil' | 'half-even' | 'half-up' | 'trunc';
type LoanKind = 'level-payment' | 'equal-principal';
interface LoanInput {
  principalCents: bigint | number;
  annualRate: number | string;
  periods: number;
  periodsPerYear?: number;
  balloonCents?: bigint | number;
  kind?: LoanKind;
  rounding?: RoundingMode;
  currency?: string;
}
interface LoanRow {
  period: number;
  paymentCents: bigint;
  interestCents: bigint;
  principalCents: bigint;
  balanceCents: bigint;
}
interface LoanSchedule {
  currency: string | undefined;
  kind: LoanKind;
  regularPaymentCents: bigint;
  finalAdjustmentCents: bigint;
  totalPaymentCents: bigint;
  totalInterestCents: bigint;
  rows: readonly LoanRow[];
}
interface Rational {
  numerator: bigint;
  denominator: bigint;
}
type LoanErrorCode = 'invalid-input' | 'invalid-rate';
class LoanError extends Error {
  readonly code: LoanErrorCode;
}

const MAX_PERIODS: 1200;
const MAX_RATE_FRACTION_DIGITS: 24;
function parseRate(rate: number | string): Rational;
function regularPaymentCents(input: LoanInput): bigint;
function buildLoanSchedule(input: LoanInput): LoanSchedule;

How figures are computed

  • The periodic rate is annualRate / periodsPerYear, taken as an exact fraction of the decimal text of the rate (0.06 means exactly 6/100, not its binary approximation).
  • Level payment: (P(1+r)^n - B) * r / ((1+r)^n - 1) evaluated exactly, then rounded once. A zero rate uses (P - B) / n.
  • Each period's interest is balance * r rounded with your mode. Principal is payment minus interest.
  • Equal-principal: (P - B) is split evenly; leftover cents go one each to the earliest periods.
  • The final period always clears the remaining balance, so the last payment absorbs accumulated rounding residue and any balloon. finalAdjustmentCents reports its difference from the first payment.
  • balloonCents is the amount left after the last regular payment and is paid with the final payment.

Customization

Choose kind, rounding, periodsPerYear (1 to 366), and balloonCents. currency is only echoed back; cents are whatever minor unit you decide.

Errors and boundaries

Everything invalid throws LoanError (invalid-input, invalid-rate): non-positive principal, balloon outside [0, principal], periods outside 1 to 1200, non-finite, negative, or over-10 (1000%) rates, rates with more than 24 fractional digits, and unknown modes.

Performance

Payment evaluation raises integers to the power of periods; the 1200-period maximum with typical rates completes in milliseconds. Rates with many fractional digits make the integers larger.

Honest scope

This is arithmetic, not financial advice. It does not model day-count conventions, APR, fees, irregular dates, variable rates, prepayments, or any lender's or jurisdiction's rounding rules. Compare the output with your lender's official disclosure before relying on it.

Support

If this library is useful to you, consider supporting its maintenance with a donation via PayPal.

Author

Created by Libin Prasanth. Connect on LinkedIn for updates and discussion.