• Stars
    star
    729
  • Rank 62,157 (Top 2 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 11 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

ical-generator is a small piece of code which generates ical calendar files


ical-generator

MIT License Module Size CI Status


ical-generator is a small but fine library with which you can very easily create a valid iCal calendars, for example to generate subscriptionable calendar feeds.



📦 Installation

npm install ical-generator

# For TypeScript Users
# (see "I use Typescript and get TS2307: Cannot find module errors" section below)
npm i -D @types/node rrule moment-timezone moment dayjs @types/luxon

⚡️ Quick Start

import ical from 'ical-generator';
import http from 'node:http';

const calendar = ical({name: 'my first iCal'});
const startTime = new Date();
const endTime = new Date();
endTime.setHours(startTime.getHours()+1);
calendar.createEvent({
    start: startTime,
    end: endTime,
    summary: 'Example Event',
    description: 'It works ;)',
    location: 'my room',
    url: 'http://sebbo.net/'
});

http.createServer((req, res) => calendar.serve(res))
    .listen(3000, '127.0.0.1', () => {
        console.log('Server running at http://127.0.0.1:3000/');
    });

See the examples folder for more examples.

📑 API-Reference

🕒 Date, Time & Timezones

ical-generator supports native Date, Day.js, Luxon's DateTime and the older moment.js and moment-timezone objects. You can also pass a string which is then passed to javascript's Date internally.

It is recommended to use UTC time as far as possible. ical-generator will output all time information as UTC time as long as no time zone is defined. For day.js, a plugin is necessary for this, which is a prerequisite. If a time zone is set, ical-generator assumes that the given time matches the time zone. If a time zone is used, it is also recommended to use a VTimezone generator. Such a function generates a VTimezone entry and returns it. For example, ical-timezones can be used for this:

import ical from 'ical-generator';
import {getVtimezoneComponent} from '@touch4it/ical-timezones';

const cal = new ICalCalendar();
cal.timezone({
    name: 'FOO',
    generator: getVtimezoneComponent
});
cal.createEvent({
    start: new Date(),
    timezone: 'Europe/London'
});

If a moment-timezone object or Luxon's setZone method works, ical-generator sets it according to the time zone set in the calendar/event.

🚦 Tests

npm test
npm run coverage
npm run browser-test

🙋 FAQ

What's Error: Can't resolve 'fs'?

ical-generator uses the node.js fs module to save your calendar on the filesystem. In browser environments, you usually don't need this, so if you pass null for fs in your bundler. In webpack this looks like this:

{
  "resolve": {
    "fallback": {
      "fs": false
    }
  }
}

Where's the changelog?

It's here. If you need the changelog for ical-generator 1.x.x and older, you'll find it here.

I get a ReferenceError: TextEncoder is not defined error (in some browsers)

This library uses TextEncoder, which is available in node.js ≥ 11.0.0 and all modern browsers. Outdated browsers may not have the necessary API and generate this error when generating the calendar.

🙆🏼‍♂️ Copyright and license

Copyright (c) Sebastian Pekarek under the MIT license.

More Repositories

1

gitlab-badges

It's like a very tiny shields.io (without website) for your private GitLab instance…
TypeScript
39
star
2

pyatv-mqtt-bridge

Bridge which allows you to control your Apple TV via MQTT
TypeScript
36
star
3

node-pyatv

A lightweight node.js wrapper around pyatv…
TypeScript
26
star
4

ble2mqtt

ble2mqtt is a small script that writes data from Bluetooth-LE devices to MQTT Topics
JavaScript
15
star
5

freeze-it

Mini-WebApp that I use to organize the food in my freezer.
JavaScript
5
star
6

vestaboard

Just another client for the Vestaboard APIs.
TypeScript
4
star
7

node-max

node-max is a node.js module to communicate with a eQ3 MAX! Cube.
JavaScript
4
star
8

semantic-release-jsr

Small semantic-release plugin, which adjusts the version in jsr.json and executes jsr publish
TypeScript
4
star
9

fhem-cli

My small toolbox I use do configure and manage FHEM…
JavaScript
3
star
10

vestaboard2mqtt

Small script to connect a Vestaboard with my home automation via MQTT.
TypeScript
3
star
11

atv2mqtt

Bridge which allows you to control your Apple TV via MQTT
JavaScript
3
star
12

fhws-hackmd-to-confluence

Export a HackMD Pad to Confluence…
JavaScript
1
star
13

fileee-backup-downloader

A hacked script that logs into Fileee and downloads a full backup. Written for offsite backups.
JavaScript
1
star
14

plex-notifications

Tiny script which sends pushover notifications for plex server events.
JavaScript
1
star
15

genderize

genderize is a simple client for genderize.io, a gender prediction API
TypeScript
1
star
16

semantic-release-docker

Plugin for semantic-release that tags a previously built Docker image and pushes it to one or more Docker registries
TypeScript
1
star
17

fhws-find-a-room-for-me

Backend for find-a-room-for.me
JavaScript
1
star
18

wakeup

A very simple CLI with which I use to start and stop servers as required.
TypeScript
1
star