Digest

The Digest class is used to create a digest object which can group events together and send them at a specified time with a specified schedule.

Constructor

new Digest(name: string, options: { cron: string; email: string; })
  • name: The name of the digest.
  • options:
    • cron: A cron string specifying the schedule.
    • email: The email address where the digest will be sent.

Methods

push(data: GitHubEvent): void
  • Pushes a GitHub event to the digest.

Examples

import { Digest } from "stacker";

// At 9am every weekday this digest will be sent
const daily = new Digest("daily", {
  cron: "0 9 * * 1-5",
  email: "work@work.com",
});
 
// Every hour between 9am and 5pm every weekday this digest will be sent
const important = new Digest("important", {
  cron: "0 9-17 * * 1-5",
  email: "work@work.com",
});

events

Provides a whay to handle events from various sources. Events can be pushed to a Digest or, if they are not important, you can just ignore them.

Methods

on(source: string, callback: (event: GitHubEvent) => void): void
  • Registers an event listener for a specified source.
  • source: The source of the event.
    • The only supported source right now is github.
  • callback: The callback function to handle the event.

Examples

import { events } from "stacker";
import { type GitHubEvent, GitHubReasons } from "stacker/github";

events.on("github", (event: GitHubEvent) => {
  if (event.reason === GitHubReasons.Subscribed) {
    daily.push(event);
  } 
  // else ignore the event
});

settings

Methods

setTimezone(timezone: string): void
  • Sets the timezone for the module.
  • timezone: The timezone string.

Examples

import { settings } from "stacker";

settings.setTimezone("America/New_York");