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

vani-cycle

v0.1.4

Published

A TypeScript library for menstrual cycle predictions.

Readme

vani-cycle

A TypeScript library for menstrual cycle predictions.

vani-cycle provides a flexible prediction engine to forecast menstrual cycles, ovulation, and fertile windows based on historical data. It's designed to be simple to use and integrate into your applications.

Features

  • Predict the next menstrual period.
  • Estimate the ovulation day.
  • Calculate the fertile window.
  • Multiple prediction strategies (Weighted Moving Average, simple Calendar average).
  • Analyze cycle history with all available strategies.
  • TypeScript ready.

Installation

Install the package using npm:

npm install vani-cycle

Usage

Here's a simple example of how to use the PredictionEngine:

import { PredictionEngine } from "vani-cycle";

// Initialize the engine with a strategy (e.g., 'wma' or 'calendar')
const engine = new PredictionEngine({ strategy: "wma" });

// Provide a history of period start dates
const history = {
  periodStarts: [
    { date: "2025-01-02" },
    { date: "2025-01-30" },
    { date: "2025-02-27" }
  ]
};

// Get predictions
const nextPeriod = engine.predictNextPeriod(history);
console.log("Next period prediction:", nextPeriod);

const ovulation = engine.predictOvulation(history);
console.log("Ovulation prediction:", ovulation);

const fertileWindow = engine.predictFertileWindow(history);
console.log("Fertile window:", fertileWindow);

// You can also analyze the history with all available strategies
const analysis = engine.analyze(history);
console.log("Analysis with all strategies:", analysis);

Example Output

{
  "nextPeriod": {
    "likely": "2025-03-27",
    "confidence": 0.65,
    "notes": [
      "wma 27.50d",
      "pred interval 28d",
      "std 0.71d"
    ]
  },
  "ovulation": {
    "likely": "2025-03-13",
    "confidence": 0.65,
    "notes": [
      "wma 27.50d",
      "pred interval 28d",
      "std 0.71d",
      "estimated ovulation = 2025-03-13"
    ]
  },
  "fertileWindow": {
    "start": "2025-03-08",
    "peak": "2025-03-13",
    "end": "2025-03-14",
    "confidence": 0.65,
    "notes": [
      "wma 27.50d",
      "pred interval 28d",
      "std 0.71d",
      "estimated ovulation = 2025-03-13"
    ]
  }
}

API

PredictionEngine(config?: PredictorConfig)

Creates a new prediction engine instance.

Config:

  • strategy: The prediction strategy to use. Can be "wma" (default) or "calendar".
  • lutealPhaseDays: The number of days in the luteal phase (default: 14).

Methods

  • predictNextPeriod(history: HistoryInput): PredictionResult
  • predictOvulation(history: HistoryInput): PredictionResult
  • predictFertileWindow(history: HistoryInput): FertileWindow
  • predictPregnancy(lastPeriodIso: string): PregnancyPrediction
  • analyze(history: HistoryInput): Record<string, PredictionResult>

Strategies

vani-cycle comes with two built-in prediction strategies:

  • wma (Weighted Moving Average): This is the default strategy. It calculates the average cycle length but gives more weight to recent cycles, making it more responsive to changes in cycle patterns.
  • calendar: A simpler strategy that calculates the unweighted average of all past cycle lengths.

You can also register your own custom prediction strategies.

License

This project is licensed under the MIT License.