serializeICal
Serializes an array of CalendarEvent objects into an iCalendar text string. Output is ready to write into a Blob or send to a server.
Usage
function serializeICal(events: CalendarEvent[]): string;
Each event is mapped as follows:
| CalendarEvent field | iCal output |
|---|---|
id | UID |
start, end | DTSTART, DTEND (UTC, YYYYMMDDTHHmmssZ) |
allDay: true | DTSTART;VALUE=DATE, DTEND;VALUE=DATE |
text | SUMMARY (escaped) |
description | DESCRIPTION (escaped) |
Recurrence rules, attendees, alarms, and timezone overrides are not serialized.
Example
Export the current calendar state as a downloadable .ics file:
<script setup>
import { ref } from "vue";
import { Calendar, serializeICal } from "@svar-ui/vue-calendar";
const api = ref();
function exportIcal() {
const ics = serializeICal(api.value.getEvents());
const blob = new Blob([ics], { type: "text/calendar" });
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = "calendar.ics";
a.click();
URL.revokeObjectURL(url);
}
</script>
<template>
<Calendar ref="api" :events="[]" :date="new Date()" />
<button :onclick="exportIcal">Export .ics</button>
</template>
Related articles
parseICal— counterpart that turns.icstext into events.getEvents— read the live event list before serializing.- Import and export — full round-trip and JSON alternatives.