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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@courierkit/availability

v0.1.0

Published

A stateless, composable slot generation library for Node.js

Readme

@courierkit/availability

A stateless, composable slot generation library for Node.js. Given schedules, bookings, external calendar events, and event type configuration, it answers the question: "When can this happen?"

Installation

npm install @courierkit/availability

Quick Start

import { getAvailableSlots } from '@courierkit/availability';

const slots = getAvailableSlots({
  eventType: {
    id: 'consultation',
    length: 60 * 60 * 1000, // 1 hour
    bufferAfter: 15 * 60 * 1000, // 15 min for notes
    minimumNotice: 24 * 60 * 60 * 1000, // 24 hours advance booking
    maxPerDay: 4,
  },
  hosts: [{
    hostId: 'dr-smith',
    schedules: {
      default: {
        id: 'default',
        rules: [{
          days: ['monday', 'tuesday', 'wednesday', 'thursday', 'friday'],
          startTime: '09:00',
          endTime: '17:00',
          timezone: 'America/New_York',
        }],
        overrides: [
          { date: '2024-12-25', available: false }, // Holiday
        ],
      },
    },
  }],
  bookings: [
    {
      hostId: 'dr-smith',
      start: new Date('2024-01-15T14:00:00Z'),
      end: new Date('2024-01-15T15:00:00Z'),
      eventTypeId: 'consultation',
    },
  ],
  range: {
    start: new Date('2024-01-15T00:00:00Z'),
    end: new Date('2024-01-22T00:00:00Z'),
  },
});

// Returns: Slot[] sorted by start time
// [{ hostId: 'dr-smith', start: Date, end: Date, bufferAfter?: Interval }, ...]

Adapter Engine (Optional)

If you don't want to assemble inputs on every request, use createAvailability with an adapter:

import { createAvailability } from '@courierkit/availability';

const availability = createAvailability({
  adapter: {
    async getEventType(eventTypeId) {
      return db.eventTypes.findById(eventTypeId);
    },
    async getHosts({ hostIds }) {
      return db.hosts.withSchedules(hostIds);
    },
    async getBookings({ hostIds, range }) {
      return db.bookings.overlap(hostIds, range);
    },
    async getBlocks({ hostIds, range }) {
      return db.blocks.overlap(hostIds, range);
    },
    async getEventTypeBuffers({ eventTypeIds }) {
      return db.eventTypes.bufferMap(eventTypeIds);
    },
  },
});

const slots = await availability.getAvailableSlots({
  eventTypeId: 'consultation',
  hostIds: ['dr-smith'],
  range: { start: new Date('2024-01-15'), end: new Date('2024-01-22') },
  at: new Date(), // optional override for "now"
});

Database Setup

At minimum, you'll need tables/collections for:

  • Hosts and schedules (rules + overrides)
  • Event types (length, buffers, limits)
  • Bookings (with UTC start/end)
  • Optional external blocks

For a concrete schema and query patterns, see the data model guide in the docs.

How It Works

Everything is an interval on a timeline. The engine layers intervals to produce available slots:

Availability (schedule)          ████████████████████████████
− Bookings                          ████       ████
− External calendar blocks               ███
− Buffer zones (derived)            ▒█████▒    ▒████▒
− Minimum notice window          ███
= Available slots                         ░░░░        ░░░░░░░

Key Features

  • Stateless: No side effects, no caching, no persistence. You own your data.
  • Timezone-Aware: Schedules are defined in local time, everything else is UTC.
  • Composable: Low-level interval arithmetic exposed for custom logic.
  • Type-Safe: Full TypeScript support.

Core Concepts

Schedules

Define recurring availability with rules and overrides:

const schedule: Schedule = {
  id: 'default',
  rules: [
    {
      days: ['monday', 'tuesday', 'wednesday', 'thursday', 'friday'],
      startTime: '09:00',
      endTime: '17:00',
      timezone: 'America/New_York',
    },
  ],
  overrides: [
    { date: '2024-12-25', available: false }, // Christmas off
    { date: '2024-01-20', available: true, startTime: '10:00', endTime: '14:00' }, // Special Saturday
  ],
};

Event Types

Configure what's being booked with constraints:

const consultation: EventType = {
  id: 'consultation',
  length: 60 * 60 * 1000, // 1 hour
  bufferBefore: 15 * 60 * 1000, // 15 min prep
  bufferAfter: 15 * 60 * 1000, // 15 min notes
  slotInterval: 30 * 60 * 1000, // 30 min grid
  minimumNotice: 24 * 60 * 60 * 1000, // 24 hours
  maxPerDay: 4,
  maxPerWeek: 15,

  // Per-host customization
  hostOverrides: {
    'dr-jones': { maxPerDay: 3 },
  },
};

Multiple Schedules per Host

const drSmith: HostSchedules = {
  hostId: 'dr-smith',
  schedules: {
    default: officeSchedule,
    telehealth: extendedHoursSchedule,
  },
};

// Use scheduleKey to select which schedule
const telehealthVisit: EventType = {
  id: 'telehealth',
  length: 20 * 60 * 1000,
  scheduleKey: 'telehealth', // Uses telehealth schedule
};

Helpers

Google Calendar Integration

import { buildBlocksFromFreebusy } from '@courierkit/availability';

// Convert Google Calendar FreeBusy response to blocks
const blocks = buildBlocksFromFreebusy(freebusyResponse, 'dr-smith');

Recurrence Expansion

import { expandRecurrence } from '@courierkit/availability';

const weeklyMeeting = {
  frequency: 'weekly' as const,
  days: ['monday', 'wednesday'] as const,
  startTime: '09:00',
  endTime: '10:00',
  timezone: 'America/New_York',
};

const intervals = expandRecurrence(weeklyMeeting, dateRange);

Interval Arithmetic

import { mergeIntervals, subtractIntervals, intersectIntervals } from '@courierkit/availability';

// Merge overlapping intervals
const merged = mergeIntervals(intervals);

// Remove busy time from available time
const free = subtractIntervals(available, busy);

// Find common availability (all must be free)
const overlap = intersectIntervals(aliceAvailability, bobAvailability);

API Reference

getAvailableSlots(input, now?)

The main entry point. Returns available slots for the given configuration.

expandSchedule(schedule, range)

Converts a schedule to UTC intervals for a date range.

expandRecurrence(rule, range)

Expands a recurrence rule into concrete intervals.

buildBlocksFromFreebusy(freebusy, hostId)

Converts Google Calendar FreeBusy response to blocks.

mergeIntervals(intervals)

Combines overlapping or adjacent intervals.

subtractIntervals(from, subtract)

Removes intervals from another set.

intersectIntervals(a, b)

Finds time present in both sets.

Documentation

Full documentation with examples: courierkit.mintlify.app

License

MIT