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

safe-stack-conversion

v2.0.0

Published

Convert a stack of YC SAFEs (post-money & pre-money) and convertible notes into a pro-forma cap table at a priced round — exact solve, cap/discount/round best-price, option-pool increase, interest accrual. Zero dependencies.

Readme

safe-stack-conversion

Convert a stack of YC SAFEs (post-money and pre-money, capped, discounted or uncapped/MFN) and convertible notes into a pro-forma cap table at a priced round, including the round's option-pool increase. Exact simultaneous solve, best-price-wins conversion, interest accrual. Zero dependencies.

npm install safe-stack-conversion

Why

Every seed-stage company carries a stack of SAFEs, and "what does the cap table look like after the Series A?" is a genuinely fiddly computation: post-money SAFEs pin ownership (amount ÷ cap), discount instruments convert at a price that depends on the round PPS, and the round PPS itself depends on how many shares the stack converts into. It's a simultaneous system; this package solves it exactly and preserves the YC identities.

import { convertStack } from "safe-stack-conversion";

const pf = convertStack(
  [
    { name: "SAFE-1", kind: "safe-post-money", amount: 1_000_000, cap: 10_000_000 },
    { name: "SAFE-2", kind: "safe-pre-money", amount: 500_000, cap: 8_000_000, discount: 0.2 },
    { name: "Note-1", kind: "note", amount: 250_000, interestRate: 0.06, years: 1.5, discount: 0.2 },
  ],
  {
    preMoney: 20_000_000,
    investment: 5_000_000,
    preRoundFullyDiluted: 10_000_000, // issued + options + promised options + available pool
    targetPoolPostClose: 0.1,         // or optionPoolIncrease: <shares>
    existingUnissuedPool: 500_000,
  },
);

pf.instruments[0].ownership;      // SAFE-1's post-round stake
pf.instruments[0].basis;          // "cap" | "discount" | "price" — which price won
pf.pricePerShare;                 // preMoney / (company capitalization + pool increase)
pf.poolIncrease;                  // new pool shares created in the round
pf.ownership;                     // { existing, safesAndNotes, poolIncrease, newInvestor } — sums to 1

Semantics

These follow the YC post-money SAFE, the original YC pre-money SAFE, and the worked examples in the YC SAFE User Guide (Appendix II).

  • Best price wins, and the round price is always an option. Each instrument converts at the lowest of its candidate prices: the round price, its cap price (if capped), and (1 − discount) × round price (if discounted). A capped SAFE whose cap is above the round's valuation converts at the round price. That's the SAFE's "greater of" clause. basis reports which price won.
  • Post-money SAFE cap: Safe Price = cap / companyCapitalization, so when the cap wins, the SAFE owns exactly amount / cap of the company capitalization.
  • Company capitalization = pre-round fully diluted (issued + options + promised options + existing unissued pool) + all SAFE/note conversion shares. It excludes the new-money shares and the round's option-pool increase.
  • Pre-money SAFE / note cap: price = cap / (preRoundFullyDiluted + poolIncrease). SAFE/note shares are excluded and the pool increase is included, as in the original pre-money SAFE.
  • Round price = preMoney / (companyCapitalization + poolIncrease): the pre-money includes the converting shares and the new pool, as in the User Guide examples.
  • Pool increase: give optionPoolIncrease (shares), or targetPoolPostClose (plus existingUnissuedPool) to solve for the increase that leaves that fraction of post-close fully diluted shares unissued.
  • Notes: principal accrues simple (default) or annually-compounded interest.
  • Exact solve: total conversion shares are solved exactly, with no iteration tolerance. If the stack can't convert to a finite cap table (e.g. post-money SAFEs with Σ amount/cap ≥ 1), it throws a RangeError instead of returning nonsense. All invalid inputs throw RangeError.
  • Rounding (opt-in): rounding: { wholeShares, pricePerShareDecimals, pricePerShareRounding }. Rounding is applied once, after the exact solve. Each holder's shares are floored (pool increase rounded up). The round price is then recomputed from the rounded counts and rounded to pricePerShareDecimals, by default to the nearest value as in the User Guide, or "down" to truncate. With { optionPoolIncrease: 1_695_000, rounding: { pricePerShareDecimals: 4, wholeShares: true } }, the guide's Example 1 is reproduced share for share (see tests). Conversion prices themselves are not rounded.

Not modeled: the Promised Options carve-in to Company Capitalization when promised options exceed the existing unissued pool (include promised options in preRoundFullyDiluted, as the guide does), pro-rata side-letter purchases (they're new money at the round price; add them to investment), MFN amendments (model the amended terms), and liquidity/dissolution events.

Also exported: postMoneySafeOwnership(amount, cap), the one-liner identity (valid when the cap wins).

Verified against an independent reference written from the SAFE definitions (4,000 random stacks, 47,806 values, worst relative difference 2.5e-11; 120 committed as test fixtures) and the YC User Guide examples.

Related

Part of a cap-table math family: priced-round-math (option-pool shuffle) · exit-waterfall · vesting-schedule-math.

Author

Built by Moshe Malka — engineering leader in New York City. Studio work at Quentin.Code.

MIT © Moshe Malka