### Create an Event with Common Options Source: https://context7.com/sebbo2002/ical-generator/llms.txt Events are created using the `createEvent()` method on a calendar instance. This example demonstrates creating an event with start and end dates, summary, description (plain and HTML), location (including geo coordinates), URL, organizer details, status, busy status, transparency, priority, sequence, and timestamps. ```javascript import ical from 'ical-generator'; const cal = ical(); // Create an event with all common options const event = cal.createEvent({ start: new Date('2024-03-15T10:00:00'), end: new Date('2024-03-15T12:00:00'), summary: 'Team Meeting', description: { plain: 'Quarterly planning meeting', html: '

Quarterly planning meeting

' }, location: { title: 'Conference Room A', address: '123 Main St, City, State 12345', geo: { lat: 40.7128, lon: -74.0060 }, radius: 100 }, url: 'https://example.com/meeting', organizer: { name: 'John Doe', email: 'john@example.com', mailto: 'john.doe@example.com' }, status: 'CONFIRMED', busystatus: 'BUSY', transparency: 'OPAQUE', priority: 5, sequence: 0, created: new Date(), lastModified: new Date() }); // Use fluent setters to modify the event event.summary('Updated Team Meeting'); event.description('New description'); console.log(cal.toString()); ``` -------------------------------- ### Create an iCal Calendar Server Source: https://github.com/sebbo2002/ical-generator/blob/develop/README.md A basic example showing how to initialize a calendar, add an event, and serve it via an HTTP server. ```javascript import ical, { ICalCalendarMethod } from 'ical-generator'; import http from 'node:http'; const calendar = ical({ name: 'my first iCal' }); // A method is required for outlook to display event as an invitation calendar.method(ICalCalendarMethod.REQUEST); 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) => { res.writeHead(200, { 'Content-Type': 'text/calendar; charset=utf-8', 'Content-Disposition': 'attachment; filename="calendar.ics"', }); res.end(calendar.toString()); }).listen(3000, '127.0.0.1', () => { console.log('Server running at http://127.0.0.1:3000/'); }); ``` -------------------------------- ### Install ical-generator Source: https://github.com/sebbo2002/ical-generator/blob/develop/README.md Use npm to install the library in your project. ```bash npm install ical-generator ``` -------------------------------- ### Integrate Date Libraries with ical-generator Source: https://context7.com/sebbo2002/ical-generator/llms.txt Use popular date libraries like Moment.js, Luxon, or Day.js to define event start and end times. ```javascript import ical from 'ical-generator'; import moment from 'moment-timezone'; import { DateTime } from 'luxon'; import dayjs from 'dayjs'; import utc from 'dayjs/plugin/utc'; import timezone from 'dayjs/plugin/timezone'; dayjs.extend(utc); dayjs.extend(timezone); const cal = ical(); // Using moment.js cal.createEvent({ start: moment().add(1, 'hour'), end: moment().add(2, 'hours'), summary: 'Moment.js Event' }); // Using moment-timezone cal.createEvent({ start: moment.tz('2024-03-15 10:00', 'America/Los_Angeles'), end: moment.tz('2024-03-15 11:00', 'America/Los_Angeles'), summary: 'LA Meeting' }); // Using Luxon cal.createEvent({ start: DateTime.now().plus({ hours: 3 }), end: DateTime.now().plus({ hours: 4 }), summary: 'Luxon Event' }); // Using Day.js cal.createEvent({ start: dayjs().add(5, 'hour').toDate(), end: dayjs().add(6, 'hour').toDate(), summary: 'Day.js Event' }); console.log(cal.toString()); ``` -------------------------------- ### Example with timezones-ical-library Source: https://github.com/sebbo2002/ical-generator/blob/develop/README.md Demonstrates how to use the `ical-generator` library with `timezones-ical-library` to set calendar and event timezones. Ensure `Europe/Berlin` and `Europe/London` are valid timezone identifiers. ```typescript import { ICalCalendar } from 'ical-generator'; import { tzlib_get_ical_block } from 'timezones-ical-library'; const cal = new ICalCalendar(); cal.timezone({ name: 'Europe/Berlin', generator: (tz) => tzlib_get_ical_block(tz)[0], }); cal.createEvent({ start: new Date(), timezone: 'Europe/London', }); ``` -------------------------------- ### Create a Calendar Instance with Options Source: https://context7.com/sebbo2002/ical-generator/llms.txt Use the `ical()` function to create a new calendar instance. Configuration options can be passed directly or set using fluent setter methods. This example shows creating a calendar with properties like name, description, timezone, prodId, method, ttl, url, and source. ```javascript import ical, { ICalCalendarMethod } from 'ical-generator'; // Create a new calendar with options const calendar = ical({ name: 'My Calendar', description: 'A calendar with upcoming events', timezone: 'America/New_York', prodId: { company: 'My Company', product: 'My Product', language: 'EN' }, method: ICalCalendarMethod.PUBLISH, ttl: 60 * 60 * 24, // 1 day refresh interval url: 'https://example.com/calendar.ics', source: 'https://example.com/calendar.ics' }); // Or use fluent setters const cal = ical(); cal.name('My Calendar'); cal.timezone('America/New_York'); cal.method(ICalCalendarMethod.REQUEST); // Generate the iCal string console.log(calendar.toString()); ``` -------------------------------- ### Create an All-Day Event Source: https://context7.com/sebbo2002/ical-generator/llms.txt To create an all-day event, set the `allDay` property to `true`. This example shows creating a single all-day event for Christmas Day and a multi-day all-day event for a holiday break. ```javascript import ical from 'ical-generator'; const cal = ical(); // Create an all-day event cal.createEvent({ start: new Date('2024-12-25'), summary: 'Christmas Day', allDay: true }); // Multi-day all-day event cal.createEvent({ start: new Date('2024-12-24'), end: new Date('2024-12-27'), summary: 'Holiday Break', allDay: true }); console.log(cal.toString()); ``` -------------------------------- ### Create Weekly Recurring Event Source: https://context7.com/sebbo2002/ical-generator/llms.txt Define a weekly recurring event with a specific count and days of the week. Ensure the start and end times are correctly set for the initial occurrence. ```javascript import ical, { ICalEventRepeatingFreq, ICalWeekday } from 'ical-generator'; const cal = ical(); // Weekly recurring event cal.createEvent({ start: new Date('2024-01-01T09:00:00'), end: new Date('2024-01-01T10:00:00'), summary: 'Weekly Standup', repeating: { freq: ICalEventRepeatingFreq.WEEKLY, count: 52, interval: 1, byDay: [ICalWeekday.MO, ICalWeekday.WE, ICalWeekday.FR] } }); console.log(cal.toString()); ``` -------------------------------- ### Remove Calendar.save() and saveSync() in ical-generator Source: https://github.com/sebbo2002/ical-generator/wiki/Migration-Guide:-v5-→-v6 The `Calendar.save()` and `saveSync()` methods have been removed. Use Node.js file system modules like `fs/promises.writeFile` or `fs.writeFile` for promises/callbacks, and `fs.writeFileSync` for synchronous operations, along with `cal.toString()` to get the calendar data. ```typescript // with Promises import { writeFile } from 'node:fs/promises'; await writeFile(path, cal.toString()); ``` ```typescript // with Callback import { writeFile } from 'node:fs'; writeFile(path, cal.toString(), err => {}); ``` ```typescript // Sync import { writeFileSync } from 'node:fs'; writeFileSync(path, cal.toString()); ``` -------------------------------- ### Configure Apple Calendar Travel Time Source: https://context7.com/sebbo2002/ical-generator/llms.txt Set travel time for events, including dynamic recalculation based on traffic. Supports fixed durations or dynamic suggestions with starting locations and transportation modes. ```javascript import ical, { ICalEventTravelTimeSuggestion, ICalEventTravelTimeTransportation } from 'ical-generator'; const cal = ical(); // Simple fixed travel time cal.createEvent({ start: new Date('2024-03-15T10:00:00'), summary: 'Office Meeting', location: { title: 'Main Office', address: '123 Business Ave', geo: { lat: 40.7128, lon: -74.0060 } }, travelTime: 1800 // 30 minutes in seconds }); // Dynamic travel time with starting location cal.createEvent({ start: new Date('2024-03-15T14:00:00'), summary: 'Client Meeting', location: { title: 'Client Office', address: '456 Client St', geo: { lat: 40.7580, lon: -73.9855 } }, travelTime: { seconds: 2700, // 45 minutes suggestionBehavior: ICalEventTravelTimeSuggestion.AUTOMATIC, startFrom: { location: { title: 'Home', address: '789 Home Lane', geo: { lat: 40.6892, lon: -74.0445 } }, transportation: ICalEventTravelTimeTransportation.CAR } } }); console.log(cal.toString()); ``` -------------------------------- ### Running Tests Source: https://github.com/sebbo2002/ical-generator/blob/develop/README.md Execute tests and coverage reports for the project using npm commands. ```bash npm test ``` ```bash npm run coverage ``` -------------------------------- ### Create Monthly Recurring Event with Exclusions Source: https://context7.com/sebbo2002/ical-generator/llms.txt Set up a monthly recurring event that repeats until a specified date, with specific days of the month and exclusions for certain dates. The `until` date is inclusive. ```javascript import ical, { ICalEventRepeatingFreq, ICalWeekday } from 'ical-generator'; const cal = ical(); // Monthly recurring event on specific days cal.createEvent({ start: new Date('2024-01-15T14:00:00'), summary: 'Monthly Review', repeating: { freq: ICalEventRepeatingFreq.MONTHLY, until: new Date('2024-12-31'), byMonthDay: [15], exclude: [ new Date('2024-07-15'), // Skip July new Date('2024-08-15') // Skip August ] } }); console.log(cal.toString()); ``` -------------------------------- ### Configure Timezones with @touch4it/ical-timezones Source: https://github.com/sebbo2002/ical-generator/blob/develop/README.md Demonstrates how to set a timezone for a calendar and event using an external VTimezone generator. ```typescript import { ICalCalendar } from 'ical-generator'; import { getVtimezoneComponent } from '@touch4it/ical-timezones'; const cal = new ICalCalendar(); cal.timezone({ name: 'Europe/London', generator: getVtimezoneComponent, }); cal.createEvent({ start: new Date(), timezone: 'Europe/London', }); ``` -------------------------------- ### Add Attendee Using String Format Source: https://context7.com/sebbo2002/ical-generator/llms.txt Add an attendee by providing their name and email address in a standard string format. This is a concise way to add individual attendees. ```javascript import ical, { ICalAttendeeRole, ICalAttendeeStatus, ICalAttendeeType } from 'ical-generator'; const cal = ical(); const event = cal.createEvent({ start: new Date(), summary: 'Project Kickoff' }); // Add attendee using string format event.createAttendee('Carol Davis '); console.log(cal.toString()); ``` -------------------------------- ### Serve Calendar Files with HTTP Source: https://context7.com/sebbo2002/ical-generator/llms.txt Serve iCalendar files over HTTP by creating a simple Node.js HTTP server. Set the 'Content-Type' to 'text/calendar' and 'Content-Disposition' for file attachment. ```javascript import ical, { ICalCalendarMethod } from 'ical-generator'; import http from 'node:http'; const calendar = ical({ name: 'My Calendar Feed', method: ICalCalendarMethod.PUBLISH, ttl: 60 * 60 // Refresh every hour }); calendar.createEvent({ start: new Date(), end: new Date(Date.now() + 3600000), summary: 'Example Event', description: 'This is a sample event' }); http.createServer((req, res) => { res.writeHead(200, { 'Content-Type': 'text/calendar; charset=utf-8', 'Content-Disposition': 'attachment; filename="calendar.ics"' }); res.end(calendar.toString()); }).listen(3000, () => { console.log('Calendar server running at http://localhost:3000/'); }); ``` -------------------------------- ### Add Attendees with Full Options Source: https://context7.com/sebbo2002/ical-generator/llms.txt Include attendees in an event with detailed properties such as email, name, role, status, RSVP preference, and type. Ensure the email address is valid. ```javascript import ical, { ICalAttendeeRole, ICalAttendeeStatus, ICalAttendeeType } from 'ical-generator'; const cal = ical(); const event = cal.createEvent({ start: new Date(), summary: 'Project Kickoff' }); // Add attendees with full options event.createAttendee({ email: 'alice@example.com', name: 'Alice Smith', role: ICalAttendeeRole.REQ, status: ICalAttendeeStatus.ACCEPTED, rsvp: true, type: ICalAttendeeType.INDIVIDUAL }); event.createAttendee({ email: 'bob@example.com', name: 'Bob Jones', role: ICalAttendeeRole.OPT, status: ICalAttendeeStatus.TENTATIVE, rsvp: true }); console.log(cal.toString()); ``` -------------------------------- ### Remove serve() method in ical-generator Source: https://github.com/sebbo2002/ical-generator/wiki/Migration-Guide:-v5-→-v6 The `serve()` method has been removed. Manually set response headers for 'Content-Type' and 'Content-Disposition', then send the calendar data using `res.end(this.toString())`. ```typescript res.writeHead(200, { 'Content-Type': 'text/calendar; charset=utf-8', 'Content-Disposition': 'attachment; filename="calendar.ics"' }); res.end(this.toString()); ``` -------------------------------- ### Add Event Attachments Source: https://context7.com/sebbo2002/ical-generator/llms.txt Attach files to calendar events by providing URLs. Attachments can be added individually using `createAttachment` or in bulk using the `attachments` method. ```javascript import ical from 'ical-generator'; const cal = ical(); const event = cal.createEvent({ start: new Date(), summary: 'Meeting with Documents' }); // Add attachments event.createAttachment('https://example.com/documents/agenda.pdf'); event.createAttachment('https://example.com/documents/presentation.pptx'); // Or add multiple at once event.attachments([ 'https://example.com/documents/notes.docx', 'https://example.com/documents/data.xlsx' ]); console.log(cal.toString()); // Output includes: ATTACH:https://example.com/documents/agenda.pdf ``` -------------------------------- ### Add Multiple Attendees at Once Source: https://context7.com/sebbo2002/ical-generator/llms.txt Efficiently add multiple attendees to an event by passing an array of attendee objects. Each object can specify the email and name, with optional role. ```javascript import ical, { ICalAttendeeRole, ICalAttendeeStatus, ICalAttendeeType } from 'ical-generator'; const cal = ical(); const event = cal.createEvent({ start: new Date(), summary: 'Project Kickoff' }); // Add multiple attendees at once event.attendees([ { email: 'dave@example.com', name: 'Dave Wilson' }, { email: 'eve@example.com', name: 'Eve Brown', role: ICalAttendeeRole.NON } ]); console.log(cal.toString()); ``` -------------------------------- ### Set Calendar Methods for Invitations Source: https://context7.com/sebbo2002/ical-generator/llms.txt Control how calendar clients handle events by setting the calendar method using ICalCalendarMethod. This includes REQUEST for invitations and CANCEL for cancellations. ```javascript import ical, { ICalCalendarMethod } from 'ical-generator'; // Meeting invitation request const invitation = ical({ method: ICalCalendarMethod.REQUEST, name: 'Meeting Invitation' }); invitation.createEvent({ start: new Date('2024-03-15T10:00:00'), end: new Date('2024-03-15T11:00:00'), summary: 'Project Discussion', organizer: { name: 'Organizer', email: 'organizer@example.com' }, attendees: [ { email: 'attendee@example.com', name: 'Attendee', rsvp: true } ] }); // Cancel a meeting const cancellation = ical({ method: ICalCalendarMethod.CANCEL }); cancellation.createEvent({ id: 'original-event-id@example.com', start: new Date('2024-03-15T10:00:00'), summary: 'Project Discussion', status: 'CANCELLED', sequence: 1 }); console.log('Invitation:', invitation.toString()); console.log('Cancellation:', cancellation.toString()); ``` -------------------------------- ### Attendee Delegation Source: https://context7.com/sebbo2002/ical-generator/llms.txt Implement attendee delegation by assigning one attendee's responsibilities to another. This is useful for managing event participation when someone cannot attend. ```javascript import ical, { ICalAttendeeRole, ICalAttendeeStatus, ICalAttendeeType } from 'ical-generator'; const cal = ical(); const event = cal.createEvent({ start: new Date(), summary: 'Project Kickoff' }); // Add attendees with full options event.createAttendee({ email: 'alice@example.com', name: 'Alice Smith', role: ICalAttendeeRole.REQ, status: ICalAttendeeStatus.ACCEPTED, rsvp: true, type: ICalAttendeeType.INDIVIDUAL }); // Delegation: Alice delegates to Frank const alice = event.attendees()[0]; const frank = alice.delegatesTo({ email: 'frank@example.com', name: 'Frank Green' }); console.log(cal.toString()); ``` -------------------------------- ### Add Alarms to Events in ical-generator Source: https://context7.com/sebbo2002/ical-generator/llms.txt Configure display, audio, or email alarms for events using relative or absolute triggers. Email alarms require an attendee list. ```javascript import ical, { ICalAlarmType, ICalAlarmRelatesTo } from 'ical-generator'; const cal = ical(); const event = cal.createEvent({ start: new Date('2024-03-15T10:00:00'), summary: 'Important Meeting' }); // Display alarm 15 minutes before event event.createAlarm({ type: ICalAlarmType.display, trigger: 60 * 15, // 15 minutes in seconds description: 'Meeting starts in 15 minutes!' }); // Audio alarm 5 minutes before with custom sound event.createAlarm({ type: ICalAlarmType.audio, trigger: 60 * 5, attach: 'https://example.com/sounds/alert.wav' }); // Alarm at specific date/time event.createAlarm({ type: ICalAlarmType.display, trigger: new Date('2024-03-15T09:30:00'), description: 'Prepare for meeting' }); // Alarm relative to event end event.createAlarm({ type: ICalAlarmType.display, triggerAfter: 60 * 10, // 10 minutes after event starts relatesTo: ICalAlarmRelatesTo.end, description: 'Event ending soon' }); // Repeating alarm event.createAlarm({ type: ICalAlarmType.display, trigger: 60 * 30, repeat: { times: 3, interval: 60 * 5 // Repeat every 5 minutes } }); // Email alarm (requires attendees) event.createAlarm({ type: ICalAlarmType.email, trigger: 60 * 60 * 24, // 1 day before summary: 'Meeting Reminder', description: 'Don\'t forget about tomorrow\'s meeting!', attendees: [ { email: 'participant@example.com', name: 'Participant' } ] }); console.log(cal.toString()); ``` -------------------------------- ### Use RRule for Complex Recurrence Source: https://context7.com/sebbo2002/ical-generator/llms.txt Integrate the `rrule` library to define sophisticated recurrence patterns for events. This allows for more granular control over frequency, intervals, weekdays, and end conditions. ```javascript import ical from 'ical-generator'; import { RRule, datetime } from 'rrule'; const cal = ical(); // Create a complex RRule const rule = new RRule({ freq: RRule.WEEKLY, interval: 2, byweekday: [RRule.MO, RRule.FR], dtstart: datetime(2024, 1, 1, 10, 30), until: datetime(2024, 12, 31) }); cal.createEvent({ start: new Date('2024-01-01T10:30:00'), summary: 'Bi-weekly Meeting', repeating: rule }); console.log(cal.toString()); ``` -------------------------------- ### Create Complex Monthly Recurring Event Source: https://context7.com/sebbo2002/ical-generator/llms.txt Generate a monthly recurring event based on a complex rule, such as the second Tuesday of each month. `byDay` specifies the weekday, and `bySetPos` indicates the occurrence within the week. ```javascript import ical, { ICalEventRepeatingFreq, ICalWeekday } from 'ical-generator'; const cal = ical(); // Complex recurrence: Second Tuesday of each month cal.createEvent({ start: new Date('2024-01-09T10:00:00'), summary: 'Board Meeting', repeating: { freq: ICalEventRepeatingFreq.MONTHLY, byDay: [ICalWeekday.TU], bySetPos: 2, startOfWeek: ICalWeekday.SU } }); console.log(cal.toString()); ``` -------------------------------- ### Configure Timezones in ical-generator Source: https://context7.com/sebbo2002/ical-generator/llms.txt Set calendar-wide timezones using VTimezone generators or specify individual event timezones. Floating events ignore timezone offsets. ```javascript import ical from 'ical-generator'; import { getVtimezoneComponent } from '@touch4it/ical-timezones'; // Calendar with timezone and VTimezone generator const cal = ical({ timezone: { name: 'America/New_York', generator: getVtimezoneComponent } }); // Event inherits calendar timezone cal.createEvent({ start: new Date('2024-03-15T10:00:00'), summary: 'New York Meeting' }); // Event with different timezone cal.createEvent({ start: new Date('2024-03-15T10:00:00'), summary: 'London Meeting', timezone: 'Europe/London' }); // Floating time event (same local time in any timezone) cal.createEvent({ start: new Date('2024-03-15T20:00:00'), summary: 'Local News', floating: true }); console.log(cal.toString()); ``` -------------------------------- ### Add Custom X-Attributes to iCalendar Components Source: https://context7.com/sebbo2002/ical-generator/llms.txt Use the .x() method to add custom X-* attributes to calendars, events, and attendees for application-specific data. This method accepts a key-value pair or an object of attributes. ```javascript import ical from 'ical-generator'; const cal = ical(); // Custom calendar attributes cal.x('X-WR-CALDESC', 'My custom calendar description'); cal.x([ { key: 'X-CUSTOM-CAL-ATTR', value: 'calendar-value' } ]); const event = cal.createEvent({ start: new Date(), summary: 'Custom Event' }); // Custom event attributes event.x('X-CUSTOM-EVENT-ID', '12345'); event.x({ 'X-CUSTOM-PRIORITY': 'high', 'X-CUSTOM-DEPARTMENT': 'Engineering' }); const attendee = event.createAttendee({ email: 'user@example.com', name: 'User' }); // Custom attendee attributes attendee.x('X-CUSTOM-ATTENDEE-ROLE', 'presenter'); console.log(cal.toString()); ``` -------------------------------- ### Use Raw RRULE String for Recurrence Source: https://context7.com/sebbo2002/ical-generator/llms.txt Add events with recurrence defined by a raw RRULE string. This is useful for compatibility with systems that generate or expect RRULE strings directly. ```javascript import ical from 'ical-generator'; import { RRule, datetime } from 'rrule'; const cal = ical(); // Or use a raw RRULE string cal.createEvent({ start: new Date('2024-01-01T09:00:00'), summary: 'Daily Sync', repeating: 'FREQ=DAILY;COUNT=30;INTERVAL=1' }); console.log(cal.toString()); ``` -------------------------------- ### Set Event Status and Busy Status Source: https://context7.com/sebbo2002/ical-generator/llms.txt Control how calendar applications display event status (e.g., CONFIRMED, TENTATIVE, CANCELLED) and free/busy information (e.g., FREE, BUSY, OOF). Requires importing ICalEventStatus and ICalEventBusyStatus enums. ```javascript import ical, { ICalEventStatus, ICalEventBusyStatus, ICalEventClass } from 'ical-generator'; const cal = ical(); // Confirmed event showing as busy cal.createEvent({ start: new Date(), summary: 'Confirmed Meeting', status: ICalEventStatus.CONFIRMED, busystatus: ICalEventBusyStatus.BUSY }); // Tentative event cal.createEvent({ start: new Date(Date.now() + 86400000), summary: 'Possible Meeting', status: ICalEventStatus.TENTATIVE, busystatus: ICalEventBusyStatus.TENTATIVE }); // Cancelled event cal.createEvent({ start: new Date(Date.now() + 172800000), summary: 'Cancelled Meeting', status: ICalEventStatus.CANCELLED, sequence: 2 }); // Private event (visibility) cal.createEvent({ start: new Date(), summary: 'Private Appointment', class: ICalEventClass.PRIVATE }); // Free time block cal.createEvent({ start: new Date(), summary: 'Available for calls', busystatus: ICalEventBusyStatus.FREE, transparency: 'TRANSPARENT' }); console.log(cal.toString()); ``` -------------------------------- ### Manage Event Categories in ical-generator Source: https://context7.com/sebbo2002/ical-generator/llms.txt Organize events by adding single or multiple categories to an event object. ```javascript import ical from 'ical-generator'; const cal = ical(); const event = cal.createEvent({ start: new Date(), summary: 'Doctor Appointment' }); // Add categories event.createCategory({ name: 'APPOINTMENT' }); event.createCategory({ name: 'HEALTH' }); // Or add multiple at once event.categories([ { name: 'PERSONAL' }, { name: 'IMPORTANT' } ]); console.log(cal.toString()); // Output includes: CATEGORIES:APPOINTMENT,HEALTH,PERSONAL,IMPORTANT ``` -------------------------------- ### JSON Serialization and Persistence of Calendars Source: https://context7.com/sebbo2002/ical-generator/llms.txt Serialize calendars and events to JSON using .toJSON() for storage and later restoration. The ical-generator constructor can accept a JSON object to recreate a calendar. ```javascript import ical from 'ical-generator'; // Create and populate a calendar const cal = ical({ name: 'Persistent Calendar' }); cal.createEvent({ start: new Date('2024-03-15T10:00:00'), end: new Date('2024-03-15T11:00:00'), summary: 'Saved Event', description: 'This event will be persisted' }); // Serialize to JSON const jsonData = JSON.stringify(cal.toJSON()); console.log('Serialized:', jsonData); // Store jsonData in database, file, etc. // Later: Restore from JSON const restored = ical(JSON.parse(jsonData)); console.log('Restored calendar:', restored.toString()); // Individual event serialization const event = cal.events()[0]; const eventJson = JSON.stringify(event.toJSON()); // Restore individual event const newCal = ical(); newCal.createEvent(JSON.parse(eventJson)); ``` -------------------------------- ### Utilize ical-generator Enums Source: https://context7.com/sebbo2002/ical-generator/llms.txt Leverage TypeScript enums for type-safe configuration of calendar methods, event properties, repeating options, attendees, and alarms. Import necessary enums from 'ical-generator'. ```javascript import { // Calendar methods ICalCalendarMethod, // Event status ICalEventStatus, ICalEventBusyStatus, ICalEventClass, ICalEventTransparency, // Repeating options ICalEventRepeatingFreq, ICalWeekday, // Attendee options ICalAttendeeRole, ICalAttendeeStatus, ICalAttendeeType, // Alarm options ICalAlarmType, ICalAlarmRelatesTo } from 'ical-generator'; // Example usage const cal = ical({ method: ICalCalendarMethod.PUBLISH }); cal.createEvent({ start: new Date(), summary: 'Demo Event', status: ICalEventStatus.CONFIRMED, busystatus: ICalEventBusyStatus.BUSY, repeating: { freq: ICalEventRepeatingFreq.WEEKLY, byDay: [ICalWeekday.MO, ICalWeekday.WE, ICalWeekday.FR] } }); ``` -------------------------------- ### Remove toURL() method in ical-generator Source: https://github.com/sebbo2002/ical-generator/wiki/Migration-Guide:-v5-→-v6 The `toURL()` method is removed. Use `URL.createObjectURL` in conjunction with creating a new `Blob` from `cal.toString()` to achieve the same result. ```typescript const url = URL.createObjectURL( new Blob([cal.toString()], {type: 'text/calendar'}) ); ``` -------------------------------- ### Category.name cannot be null or undefined in ical-generator Source: https://github.com/sebbo2002/ical-generator/wiki/Migration-Guide:-v5-→-v6 The `Category.name` property must now be provided and cannot be null or undefined. Initialize it during category creation. ```typescript const category = event.createCategory({ name: 'APPOINTMENT' }); ``` -------------------------------- ### Remove toBlob() method in ical-generator Source: https://github.com/sebbo2002/ical-generator/wiki/Migration-Guide:-v5-→-v6 The `toBlob()` method is removed. Create a new `Blob` object directly using `cal.toString()` and specifying the 'text/calendar' type. ```typescript const blob = new Blob([cal.toString()], {type: 'text/calendar'}); ``` -------------------------------- ### Update Alarm.interval() to Alarm.repeat() object in ical-generator Source: https://github.com/sebbo2002/ical-generator/wiki/Migration-Guide:-v5-→-v6 The `Alarm.interval()` method is removed. Use `Alarm.repeat()` with an object containing `times` and `interval` properties instead of separate parameters. ```typescript const alarm = event.createAlarm({ repeat: { times: 4, interval: 2 } }); ``` -------------------------------- ### Attendee.email cannot be null or undefined in ical-generator Source: https://github.com/sebbo2002/ical-generator/wiki/Migration-Guide:-v5-→-v6 The `Attendee.email` property can no longer be null or undefined. Provide the email address during attendee creation or assignment. ```typescript const attendee = event.createAttendee({ email: 'mail@example.com' }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.