Skip to content
develop
Switch branches/tags
Go to file
Code

Latest commit

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

ical-generator Logo

ical-generator

License Size Status Dependencies

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.

⚠️ Version 2.0.0

You are looking at the readme of the new version 2.0.0, which is currently still under development. The new version is a complete rewrite in Typescript, but I tried to keep most of the API. Nevertheless, there are some changes. You can install this future version by running npm i ical-generator@next.

If you are looking for the readme of the current version, you can find it here.

If you want to help out or want to know what's in the pipeline with the new version, you're welcome to take a look here and get an idea of what's in the new version.

📦 Installation

npm install ical-generator

⚡️ Quick Start

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

const calendar = ical({name: 'my first iCal'});
calendar.createEvent({
    start: moment(),
    end: moment().add(1, 'hour'),
    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/');
    });

📑 API-Reference

🕒 Date, Time & Timezones

ical-generator supports native Date, moment.js (and moment-timezone, Day.js and Luxon's DateTime 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:

{
  "node": {
    "fs": "empty"
  }
}

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 use Typescript and get TS2307: Cannot find module errors

ical-generator supports some third-party libraries such as moment.js or Day.js. To enable Typescript to do something with these types, they must of course also be installed. Unfortunately, npm does not install peerDependencies in versions 4-6, so these dependencies have to be installed manually. The best thing to do is to update your npm installation and reinstall ical-generator, which should solve the problem.

🙆🏼‍♂️ Copyright and license

Copyright (c) Sebastian Pekarek under the MIT license.

About

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

Resources

License

Packages

No packages published

Languages