Skip to content

Commit e4a2eaa

Browse files
🐛 Fix ICS file generation with CLRF and absent fields (#553)
* Fix ics file generation (CLRF, absent fields) PRODID, UID, DTSTAMP * Update src/index.ts --------- Co-authored-by: Anand Chowdhary <[email protected]>
1 parent bd51044 commit e4a2eaa

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/index.ts

+15-2
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ export const ics = (calendarEvent: CalendarEvent): string => {
177177
.replace(/(\\n)[\s\t]+/gm, "\\n");
178178

179179
const { start, end } = formatTimes(event, event.allDay ? "allDay" : "dateTimeUTC");
180+
const dateStamp = dayjs(new Date()).utc().format(TimeFormats["dateTimeUTC"]);
180181
const calendarChunks = [
181182
{
182183
key: "BEGIN",
@@ -186,6 +187,10 @@ export const ics = (calendarEvent: CalendarEvent): string => {
186187
key: "VERSION",
187188
value: "2.0",
188189
},
190+
{
191+
key: "PRODID",
192+
value: event.title
193+
},
189194
{
190195
key: "BEGIN",
191196
value: "VEVENT",
@@ -202,6 +207,10 @@ export const ics = (calendarEvent: CalendarEvent): string => {
202207
key: "DTEND",
203208
value: end,
204209
},
210+
{
211+
key: "DTSTAMP",
212+
value: dateStamp,
213+
},
205214
{
206215
key: "RRULE",
207216
value: event.rRule,
@@ -222,6 +231,10 @@ export const ics = (calendarEvent: CalendarEvent): string => {
222231
key: "ORGANIZER",
223232
value: event.organizer,
224233
},
234+
{
235+
key: "UID",
236+
value: Math.floor(Math.random() * 100000).toString().replace(".", ""),
237+
},
225238
{
226239
key: "END",
227240
value: "VEVENT",
@@ -239,10 +252,10 @@ export const ics = (calendarEvent: CalendarEvent): string => {
239252
if (chunk.key == "ORGANIZER") {
240253
const value = chunk.value as CalendarEventOrganizer;
241254
calendarUrl += `${chunk.key};${encodeURIComponent(
242-
`CN=${value.name}:MAILTO:${value.email}\n`
255+
`CN=${value.name}:MAILTO:${value.email}\r\n`
243256
)}`;
244257
} else {
245-
calendarUrl += `${chunk.key}:${encodeURIComponent(`${chunk.value}\n`)}`;
258+
calendarUrl += `${chunk.key}:${encodeURIComponent(`${chunk.value}\r\n`)}`;
246259
}
247260
}
248261
});

0 commit comments

Comments
 (0)