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

dividend-math

v1.0.0

Published

A tiny, zero-dependency TypeScript library for dividend math: yield, growth, DRIP reinvestment, monthly income and payout ratio. Pure functions, fully tested.

Readme

dividend-math

CI npm License: MIT

A tiny, zero-dependency TypeScript library for dividend math: yield, growth, DRIP reinvestment, monthly income and payout ratio. Pure functions, fully tested.

No frameworks. No runtime dependencies. Just one file of pure functions you can drop into any project — browser, Node, or edge.

✨ Features

  • 8 pure functions — no side effects, no I/O, easy to test and tree-shake
  • Zero runtime deps — only TypeScript as a dev dependency
  • DRIP compounding simulator — year-by-year dividend reinvestment model
  • Fully tested — vitest unit tests covering edge cases (zero price, zero growth, invalid input)
  • Typed — full TypeScript types and interfaces exported

📦 Install

npm install dividend-math

…or just copy src/dividend.ts into your project. It’s a single file with no imports.

🚀 Quick example

import {
  dripCalculator,
  dividendYield,
  monthlyDividendIncome,
  payoutRatio,
} from 'dividend-math';

// 1. Dividend yield: $2.80 annual dividend on an $80 share
dividendYield({ annualDividendPerShare: 2.8, price: 80 }); // → 3.5 (%)

// 2. Project a 15-year DRIP for a quality dividend ETF (SCHD-style)
const result = dripCalculator({
  initialInvestment: 10000,
  price: 80,
  dividendYieldPct: 3.5,
  dividendGrowthPct: 10,
  priceGrowthPct: 7,
  monthlyContribution: 100,
  years: 15,
});
// → { shares, finalPrice, finalValue, totalInvested, totalDividends, finalAnnualDividendIncome }

// 3. Monthly income from a high-yield position
monthlyDividendIncome({ investment: 50000, dividendYieldPct: 13 }); // → ~541.67/month

// 4. Payout-ratio sustainability check
payoutRatio({ dividendPerShare: 2, earningsPerShare: 5 }); // → 40 (%)

🖥️ Live demo

Want to see these formulas in action without wiring up code? I built a free dividend calculator using these exact functions — DRIP, yield, growth, monthly income, plus dedicated SCHD and QQQI calculators.

📖 API

All percentage inputs are numeric: pass 5 for 5% (the function converts internally). Money is in dollars.

annualizeDividend(dividend, isMonthly)number

Convert a monthly dividend to annual (×12). isMonthly=false returns the input unchanged.

dividendYield({ annualDividendPerShare, price })number

Dividend yield as a percentage. Returns NaN if price ≤ 0.

dividendPerShareFromYield(price, yieldPct)number

Reverse: given a target yield, compute the annual dividend per share.

futureDividend({ currentDividend, growthRatePct, years })number

Per-share dividend n years out: D0 × (1 + g)^n.

cumulativeDividends({ currentDividend, growthRatePct, years })number

Sum of dividends over n years (geometric series). Handles g = 0.

monthlyDividendIncome({ investment, dividendYieldPct })number

Monthly cash flow: investment × yield ÷ 12.

payoutRatio({ dividendPerShare, earningsPerShare })number

Payout ratio as a percentage. >100% signals an unsustainable dividend. Returns NaN if EPS ≤ 0.

dripCalculator(input)DripResult

Year-by-year DRIP (dividend reinvestment) simulation. Each year: dividends are computed at the current yield, reinvested into more shares at the current price, then price grows by priceGrowthPct and yield grows by dividendGrowthPct. Monthly contributions buy shares at the current price.

interface DripInput {
  initialInvestment: number;
  price: number;
  dividendYieldPct: number;
  dividendGrowthPct: number;
  priceGrowthPct: number;
  monthlyContribution: number;
  years: number;
}

interface DripResult {
  shares: number;                       // shares owned at end
  finalPrice: number;                   // share price at end
  finalValue: number;                   // portfolio market value at end
  totalInvested: number;                // sum of all contributions
  totalDividends: number;               // cumulative dividends received
  finalAnnualDividendIncome: number;    // projected annual income at end
}

🧪 Testing

npm install
npm test    # 16 vitest unit tests

📄 License

MIT — use it anywhere. Issues and PRs welcome.