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

ab-test-sample-size

v1.0.1

Published

Zero-dependency A/B test sample-size, test-duration, and minimum-detectable-effect calculator using the two-proportion z-test.

Readme

ab-test-sample-size

Zero-dependency A/B test sample-size, test-duration, and minimum-detectable-effect calculations using the two-proportion z-test. Written in TypeScript, runs anywhere (Node, Deno, Bun, browsers).

This is the same calculation engine that powers the free A/B test traffic & sample-size estimator at optipilot.com — extracted so you can run the numbers in your own code, CI checks, or experiment-planning dashboards.

License: MIT

Why

Most "is my A/B test big enough?" bugs come from eyeballing significance instead of computing the sample size up front. This library gives you the one number that matters — how many visitors per variation you need — plus how long that will take at your traffic level, with no dependencies and a formula you can audit in ~30 lines.

Install

npm install ab-test-sample-size

Usage

import { calculateSampleSize, calculateFullEstimate } from 'ab-test-sample-size'

// How many visitors per variation do I need?
calculateSampleSize({
  baselineRate: 0.05, // current conversion rate (5%)
  mdeRelative: 0.1,   // smallest relative lift worth detecting (10%)
  significance: 95,   // confidence level (90 | 95 | 99)
  power: 80,          // statistical power (70 | 80 | 90)
  variations: 2,      // control + variant(s)
})
// => 31240

// Full plan, including how long the test will run at 1,000 visitors/day:
calculateFullEstimate(
  { baselineRate: 0.05, mdeRelative: 0.1, significance: 95, power: 80, variations: 2 },
  1000,
)
// => { sampleSizePerVariation: 31240, totalSampleSize: 62480, estimatedDays: 63 }

API

calculateSampleSize(input): number

Required visitors per variation, rounded up. Returns 0 for degenerate inputs (rates outside (0, 1) or a zero effect size).

calculateFullEstimate(input, dailyTraffic?): SampleSizeResult

Adds the total across all variations and — when dailyTraffic is supplied — an estimatedDays duration.

input: SampleSizeInput

| Field | Type | Meaning | | --- | --- | --- | | baselineRate | number | Current conversion rate as a decimal (0.05 = 5%). | | mdeRelative | number | Minimum detectable effect as a relative lift (0.1 = 10% relative). | | significance | number | Confidence level: 90, 95, or 99. | | power | number | Statistical power: 70, 80, or 90. | | variations | number | Number of variations including control. |

Unrecognised significance / power values fall back to 95 / 80. The z-score lookup tables are exported as Z_ALPHA and Z_BETA if you need them.

The formula

It's a standard two-proportion z-test:

n = ((z_α + z_β)² · (p₁(1 − p₁) + p₂(1 − p₂))) / (p₂ − p₁)²

where p₁ is the baseline rate, p₂ = p₁ · (1 + mdeRelative) is the expected rate under the alternative hypothesis, z_α is the two-tailed z-score for the significance level, and z_β is the z-score for the power level.

Testing

npm test

Zero runtime dependencies; the test suite uses Node's built-in test runner.

Related

License

MIT © optipilot.com