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

rrulelib

v1.0.3

Published

A library for working with recurrence rules (RRULE)

Readme

RruleLib

A TypeScript library for working with recurrence rules (RRULE) - perfect for calendar applications, scheduling systems, and any application that needs to handle recurring events with timezone support.

Features

  • 🚀 TypeScript Support - Full TypeScript definitions included
  • 📅 RRULE Parsing - Parse and validate RRULE strings
  • 🔄 Occurrence Generation - Generate recurring event occurrences
  • 🌍 Timezone Support - Full timezone-aware date generation with Luxon
  • ⚛️ React Hook - Ready-to-use React hook for timezone-aware RRULE generation
  • 🛠️ Utility Functions - Helper functions for common patterns
  • Well Tested - Comprehensive test suite included
  • 📦 Minimal Dependencies - Only Luxon for timezone support

Installation

npm install rrulelib

Quick Start

import {
  RRule,
  Frequency,
  createDailyRule,
  TimezoneRRule,
  useRruleDatesGenerator,
} from "rrulelib";

// Basic RRULE usage
const options = createDailyRule(1, 10); // Every day, 10 occurrences
const rrule = new RRule(options, new Date("2024-01-01"));
const occurrences = rrule.getOccurrences();

// Timezone-aware RRULE usage
const timezoneRRuleString =
  "DTSTART;TZID=America/New_York:20240929T044500\nRRULE:FREQ=DAILY;INTERVAL=1;COUNT=3";
const timezoneDates = TimezoneRRule.getDatesWithCustomTimezone(
  timezoneRRuleString,
  "Europe/London",
  "2024-09-29T04:45:00"
);

// React hook usage
const { getDatesWithCustomTimezone } = useRruleDatesGenerator();
const hookDates = getDatesWithCustomTimezone(
  timezoneRRuleString,
  "Asia/Tokyo",
  "2024-09-29T04:45:00"
);

API Reference

RRule Class

The main class for working with recurrence rules.

Constructor

new RRule(options: RRuleOptions, startDate?: Date)

Methods

  • getOccurrences(count?: number, until?: Date): Occurrence[] - Generate occurrences
  • getNextOccurrence(date: Date): Date - Get next occurrence after given date
  • toString(): string - Convert to RRULE string format

Static Methods

  • parse(rruleString: string): ParseResult - Parse RRULE string

Utility Functions

import {
  createDailyRule,
  createWeeklyRule,
  createMonthlyRule,
  createYearlyRule,
  validateRRule,
  formatDate,
} from "rrulelib";

// Create common recurrence patterns
const daily = createDailyRule(1, 5); // Every day, 5 times
const weekly = createWeeklyRule(2, [Weekday.MO, Weekday.FR]); // Every 2 weeks on Mon/Fri
const monthly = createMonthlyRule(1, [1, 15]); // Monthly on 1st and 15th
const yearly = createYearlyRule(1, [1, 6]); // Yearly in Jan and Jun

// Validate options
const validation = validateRRule(options);
if (!validation.valid) {
  console.log("Errors:", validation.errors);
}

// Format dates
const formatted = formatDate(new Date(), "long");

Examples

Daily Recurrence

import { RRule, createDailyRule } from "rrulelib";

const options = createDailyRule(1, 7); // Every day for a week
const rrule = new RRule(options, new Date("2024-01-01"));
const occurrences = rrule.getOccurrences();

Weekly Recurrence

import { RRule, createWeeklyRule, Weekday } from "rrulelib";

const options = createWeeklyRule(1, [Weekday.MO, Weekday.WE, Weekday.FR]);
const rrule = new RRule(options, new Date("2024-01-01"));
const occurrences = rrule.getOccurrences();

Parse Existing RRULE

import { RRule } from "rrulelib";

const result = RRule.parse("RRULE:FREQ=WEEKLY;INTERVAL=2;BYDAY=MO,WE,FR");
if (result.valid && result.rrule) {
  const rrule = new RRule(result.rrule);
  const occurrences = rrule.getOccurrences();
}

Timezone-Aware RRULE

import { TimezoneRRule, useRruleDatesGenerator } from "rrulelib";

// Parse and generate timezone-aware dates
const rruleString =
  "DTSTART;TZID=America/New_York:20240929T044500\nRRULE:FREQ=DAILY;INTERVAL=1;COUNT=3";
const dates = TimezoneRRule.getDatesWithCustomTimezone(
  rruleString,
  "Europe/London",
  "2024-09-29T04:45:00"
);

// Using React hook
const { getDatesWithCustomTimezone } = useRruleDatesGenerator();
const hookDates = getDatesWithCustomTimezone(
  rruleString,
  "Asia/Tokyo",
  "2024-09-29T04:45:00"
);

Development

Setup

git clone <repository-url>
cd rrulelib
npm install

Build

npm run build

Test

npm test

Watch Mode

npm run dev

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Thank you

If you'd like to say thanks, I'd really appreciate a coffee :)

Changelog

1.0.2

  • Initial release
  • Basic RRULE parsing and generation
  • Timezone-aware RRULE parsing and generation
  • TypeScript support
  • Comprehensive test suite