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 🙏

© 2024 – Pkg Stats / Ryan Hefner

google-calendar-store

v0.12.0

Published

A library that fetches and stores events from Google calendars, and provides interfaces for querying events. Useful for displaying Google calendar events in custom ways.

Downloads

7

Readme

google-calendar-store

A library that fetches and stores events from Google calendars, and provides interfaces for querying events. Useful for displaying Google calendar events in custom ways.

Install

npm install google-calendar-store

Quick start

// 1. Import relevant classes and moment.
import {Calendar, MemoryStorage} from 'google-calendar-store';
import moment from 'moment';

(async () => {
  // 2. Create storage engine.
  const storage = new MongoStorage();
  await storage.init();

  // 3. Create calendar.
  const calendar = new Calendar({
    googleId: 'GOOGLE CALENDAR ID HERE',
    apiKey: 'GOOGLE API KEY HERE',
    storage
  });

  // 4. Start fetching events every 5 minutes.
  calendar.startEventUpdates();

  // 5. Query events.
  const start = moment();
  const end = start.clone().add({months: 3});
  const weeks = await calendar.getFilledCalendar(start, end);

  // 6. Do something with events.
  for (const week of weeks) {
    for (const day of week.days) {
      for (const event of day.events) {
        console.log(event.description);
      }
    }
  }
})();

API

class Calendar

// Instantiates a new Calendar instance for a specific Google calendar.
const calendar = new Calendar({googleId: string, storage: EventStorage, apiKey: string})

// Fetches and updates events from Google, going back how every many years specified as the argument.
calendar.updateEvents(years?: number = 1)

// Fetches events every intervalMinutes minutes, the years argument is the same one as with updateEvents.
calendar.startEventUpdates(intervalMinutes: number = 5, years?: number): void

// Stops automatic updates initiated by startEventUpdates.
calendar.stopEventUpdates(): void

// Fetches events from the storage as specified by start and end times.
calendar.getEvents(start: Moment, end?: Moment): Promise<Array<CalendarEvent>>

// Returns a structure with an instance for every day within the range even if the day doesn't contain any events.
calendar.getFilledCalendar(start: number | Moment, end: number | Moment, weekdays: Array<number>): Promise<Array<Week>>

class CalendarEvent

// Not meant to be instantiated anywhere else than in an EventStorage.

// Properties:
googleId: string;
calendarGoogleId: string;
summary: string;
description: string;
start: Date;
end: Date;
cancelled: boolean;

// Methods:
isPast(): boolean;
isToday(): boolean;

class Day

// Not meant to be instantiated.

// Properties:
date: Moment;
events: Array<CalendarEvent> = [];

// Methods:
hasEvents(): boolean;

class Week

// Not meant to be instantiated.

// Properties:
days: Array<Day>;

// Methods:
hasEvents(): boolean;

class MongoStorage

const storage = new MongoStorage();

storage.init(url: string = process.env.MONGO_URL): Promise<void>;

class MemoryStorage

// Used for debugging, use a proper storage driver for production use.

const storage = new MemoryStorage();

Storage engines

This library comes equipped with two storage engines:

  1. MemoryStorage, which stores events in memory.
  2. MongoStorage, which stores events in MongoDB.

Creating a new MemoryStorage is easy, it just needs to implement the EventStorage interface.