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 🙏

© 2025 – Pkg Stats / Ryan Hefner

ltv-calculator

v0.4.0

Published

Simply LTV / ARPU / Average Duration calcurator

Readme

LTV calculator

SaaS metrics calculator for calculating the following properties:

  • LTV (Lifetime Value)
  • MRR / ARR (Monthly/Annual Recurring Revenue)
  • Churn Rate (Customer & Revenue)
  • NRR / GRR (Net/Gross Revenue Retention)
  • Cohort Retention
  • ARPU (Average Revenue Per User)
  • Average Duration

SaaSビジネスに必要な各種指標を計算するライブラリです。Stripe等から取得したデータを元に、LTV・MRR・チャーンレート・NRR/GRR・コホート分析などを簡単に計算できます。

Motivation blog post: 計算式参考

ユーザの平均継続期間が「1/解約率」で求められることの数学的証明:https://migi.hatenablog.com/entry/churn-formula

API Docs

https://hideokamoto.github.io/ltv-calculator/

Install

https://www.npmjs.com/package/ltv-calculator

$ npm i -S ltv-calculator

Usage

MRR (Monthly Recurring Revenue) / ARR (Annual Recurring Revenue)

import LTVCalculator from 'ltv-calculator'
const client = new LTVCalculator()

// MRRを計算
// Calculate MRR from subscriptions
const subscriptions = [
  { amount: 1000, interval: 'month' },  // 月次: 1000円
  { amount: 12000, interval: 'year' },  // 年次: 12000円/年 = 1000円/月
  { amount: 100, interval: 'week' }     // 週次: 100円/週
]
const mrr = client.calculateMRR(subscriptions)

// ARRを計算 (MRR × 12)
// Calculate ARR (MRR × 12)
const arr = client.calculateARR(subscriptions)

Churn Rate (解約率)

import LTVCalculator from 'ltv-calculator'
const client = new LTVCalculator()

// 顧客ベースのチャーンレート
// Customer-based churn rate
const customerChurn = client.calculateCustomerChurnRate({
  startCustomers: 100,
  churnedCustomers: 5
}) // = 5%

// 収益ベースのチャーンレート(グロス)
// Revenue-based churn rate (Gross)
const revenueChurn = client.calculateRevenueChurnRate({
  startMRR: 10000,
  churnedMRR: 500,
  contractionMRR: 200  // ダウングレードによる減少
}) // = 7%

NRR (Net Revenue Retention) / GRR (Gross Revenue Retention)

import LTVCalculator from 'ltv-calculator'
const client = new LTVCalculator()

// NRR: 既存顧客からの収益維持率(アップグレードを含む)
// NRR: Net Revenue Retention (includes expansion)
const nrr = client.calculateNRR({
  startMRR: 10000,
  expansionMRR: 1000,    // アップグレード
  contractionMRR: 200,   // ダウングレード
  churnedMRR: 300        // 解約
}) // = 105%

// GRR: 既存顧客からの収益維持率(アップグレードを除く)
// GRR: Gross Revenue Retention (excludes expansion)
const grr = client.calculateGRR({
  startMRR: 10000,
  contractionMRR: 200,
  churnedMRR: 300
}) // = 95%

Cohort Retention (コホート分析)

import LTVCalculator from 'ltv-calculator'
const client = new LTVCalculator()

// コホート別のリテンション率を計算
// Calculate cohort retention rates
const retention = client.calculateCohortRetention([
  { month: 0, customers: 100 },
  { month: 1, customers: 90 },
  { month: 2, customers: 85 }
])
// = [100, 90, 85] (%)

Historical LTV

import LTVCalculator from 'ltv-calculator'
const client = new LTVCalculator()

// 過去の顧客収益データから平均LTVを算出
// Calculate average LTV from historical customer revenues
const customerRevenues = [1000, 1200, 1500, 800, 2000]
const ltv = client.calculateHistoricalLTV(customerRevenues)
// = 1300 (average)

ARPU

import LTVCalculator from 'ltv-calculator'
const client = new LTVCalculator()

// 売り上げが100単位・ユーザー数が10単位の時、ARPUは10単位
// Sales is 100 unit and user is 10, ARPU is 10 unit
const arpu = client.calcARPU(100, 10).getARPU()
expect(arpu).toEqual(10)

// ショートハンドル
// short handle
const arpu = client.getARPU(100, 10)
expect(arpu).toEqual(10)

Average Duration / 解約率からの平均継続期間の計算

1 / churn rate (1 / 解約率) = Average Duration (平均継続期間)

import LTVCalculator from 'ltv-calculator'
const client = new LTVCalculator()

// 解約率10%の時、平均継続期間は10単位 
// Churn rate is 10% -> Average duration is 10 unit
const averageDuration = client
  .calcAverageDurationByChurnRate(10)
  .getAverageDurationByChurnRate()
expect(averageDuration).toEqual(10)

// ショートハンドル版
const averageDuration = client
  .getAverageDurationByChurnRate(10)
expect(averageDuration).toEqual(10)

// 解約率10%の時、平均継続期間は10単位(単位を明示的に設定する)
// Churn rate is 10% -> Average duration is 10 unit
const averageDuration = client
  .calcAverageDurationByChurnRate(10, 'percentage')
  .getAverageDurationByChurnRate()
expect(averageDuration).toEqual(10)

// ショートハンドル版
const averageDuration = client
  .getAverageDurationByChurnRate(10, 'percentage')
expect(averageDuration).toEqual(10)

// 解約率0.1(10%)の時、平均継続期間は10単位(パーセントではなく数値でも指定できる)
// Churn rate is 0.1(10%) -> Average duration is 10 unit
const averageDuration = client
  .calcAverageDurationByChurnRate(0.1, 'number')
  .getAverageDurationByChurnRate()
expect(averageDuration).toEqual(10)

// ショートハンドル版
const averageDuration = client
  .getAverageDurationByChurnRate(0.1, 'number')
expect(averageDuration).toEqual(10)

LTVの計算

平均継続期間 * ARPUで計算する。

// 1: 売り上げが100単位・ユーザー数が10単位の時、ARPUは10単位
//    Sales is 100 unit and user is 10, ARPU is 10 unit
//
// 2: 解約率10%の時、平均継続期間は10単位 
//    Churn rate is 10% -> Average duration is 10 unit
//
// 3: LTV (平均継続期間 * ARPU)は 10 * 10 = 100単位
//    LTV (Average Duration * ARPU) is 10 * 10 = 100 unit
const arpu = client.calcARPU(100, 10)
    .calcAverageDurationByChurnRate(10)
    .getLTV()

expect(arpu).toEqual(100)

contribution

// clone
$ git clone [email protected]:hideokamoto/ltv-calculator.git
$ cd ltv-calculator

// setup
$ yarn

// Unit test
$ yarn test
or
$ yarn run test:watch

// Lint
$ yarn run lint
or
$ yarn run lint --fix

// Build
$ yarn run build

// Rebuild docs
$ yarn run doc