~/recurring-dates
docs

getRecurringDates

A convenience wrapper around generateRecurringDates that guarantees a non-undefined return value.

Signature

function getRecurringDates(config: RecurringDatesConfig): RecurringDatesResult

Behavior

Calls generateRecurringDates(config) internally. If the result is undefined (which can happen on validation failures), it returns a safe fallback:

{ text: "", dates: [], error: "Invalid configuration" }

When to Use

  • When you want a guaranteed object return (no undefined check needed).
  • In templates or UI bindings where you destructure immediately.
  • As a drop-in replacement for generateRecurringDates.

Example

import { getRecurringDates } from "recurring-dates";

// Always safe to destructure
const { text, dates, error } = getRecurringDates({
  STARTS_ON: "01-01-2025",
  ENDS_ON: "31-01-2025",
  FREQUENCY: "W",
  WEEK_DAYS: ["MON"],
});

if (error) {
  console.error(error);
} else {
  console.log(text);  // "Every week on Monday"
  console.log(dates); // [...]
}