Skip to content

Migration Guide: v5 → v6

Sebastian edited this page Oct 19, 2023 · 4 revisions

In version 6 some breaking changes were made to make ical-generator even better. For more details on why these changes were made, check out these tickets:



Calendar.save() / saveSync() was removed

Before

// with Promises
await cal.save(path);

// with Callback
cal.save(path, err => {});

// Sync
cal.saveSync(path);

After

// with Promises
import { writeFile } from 'node:fs/promises';
await writeFile(path, cal.toString());

// with Callback
import { writeFile } from 'node:fs';
writeFile(path, cal.toString(), err => {});

// Sync
import { writeFileSync } from 'node:fs';
writeFileSync(path, cal.toString());

serve() was removed

Before

cal.serve(res);

After

res.writeHead(200, {
    'Content-Type': 'text/calendar; charset=utf-8',
    'Content-Disposition': 'attachment; filename="calendar.ics"'
});

res.end(this.toString());

toBlob() was removed

Before

const blob = cal.toBlob();

After

const blob = new Blob([cal.toString()], {type: 'text/calendar'});

toURL() was removed

Before

const url = cal.toURL();

After

const url = URL.createObjectURL(
    new Blob([cal.toString()], {type: 'text/calendar'})
);

Alarm.interval() got removed, use Alarm.repeat() instead

Before

const alarm = event.createAlarm({
    repeat: 4,
    interval: 2
});

After

const alarm = event.createAlarm({
    repeat: {
        times: 4,
        interval: 2
    }
});

Alarm.repeat() now gives/takes an object instead of a number

Before

const alarm = event.createAlarm({
    repeat: 4,
    interval: 2
});

After

const alarm = event.createAlarm({
    repeat: {
        times: 4,
        interval: 2
    }
});

Attendee.email can’t be null | undefined

Before

const attendee = event.createAttendee(); // ← Attendee.email would be undefined
attendee.email('mail@example.com');

After

const attendee = event.createAttendee({ email: 'mail@example.com' });

Category.name can’t be null | undefined

Before

const category = event.createCategory(); // ← Category.name would be undefined
category.name('APPOINTMENT');

After

const category = event.createCategory({ name: 'APPOINTMENT' });