From 95c9a645573306cf0d0049c59581d5f4b943babd Mon Sep 17 00:00:00 2001 From: sp Date: Mon, 17 Oct 2022 17:23:55 +0800 Subject: [PATCH] added location, geo, url and organizer fields --- main.ts | 19 ++++++++++++++++++- tests.ts | 7 +++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/main.ts b/main.ts index de718ce..e9f5bba 100644 --- a/main.ts +++ b/main.ts @@ -17,6 +17,14 @@ const eventBegin: ContentLine = ['BEGIN', 'VEVENT']; const eventEnd: ContentLine = ['END', 'VEVENT']; +const parseGeo = (geo?: {lat: number, lon: number}) => { + return geo ? `${geo.lat};${geo.lon}` : undefined; +} + +const parseOrganizer = (organizer?: {name: string, email: string}) => { + return organizer? `CN=${organizer.name}:mailto:${organizer.email}` : undefined +} + export class Event { constructor(protected config: EventConfig) { if (config.duration !== undefined) { @@ -39,7 +47,7 @@ export class Event { toLines(): ContentLine[] { const uid = crypto.randomUUID(); - const { title, desc, rrule, alarm } = this.config; + const { title, desc, rrule, alarm, location, url, organizer, geo, htmlContent } = this.config; const result = [ eventBegin, @@ -49,7 +57,11 @@ export class Event { ['DTEND', parseDate(this.config.endDate!)], ['SUMMARY', title], ['DESCRIPTION', desc], + ['LOCATION', location], + ['URL', url], + ['GEO', parseGeo(geo)], ['RRULE', parseRRule(rrule)], + ['ORGANIZER', parseOrganizer(organizer)], ...parseAlarm(alarm), eventEnd, ].filter(line => line[1] !== undefined) as ContentLine[]; @@ -80,6 +92,11 @@ export interface EventConfig { desc?: string; rrule?: RecurrenceRule; alarm?: AlarmConfig; + location?: string; + url?: string; + organizer?: { name: string; email: string; dir?: string; }; + geo?: { lat: number; lon: number; }; + htmlContent?: string; } export interface AlarmConfig { diff --git a/tests.ts b/tests.ts index 30cdc7b..46356de 100644 --- a/tests.ts +++ b/tests.ts @@ -38,6 +38,13 @@ Deno.test({ beginDate: [2022, 9, 6, 9, 30], endDate: [2022, 9, 6, 10], desc: 'Implement a module to generate .ics files', + organizer: { + name: 'Sam Worthington', + email: 'sam@dev.com' + }, + url: 'https://www.google.com/', + location: 'ABC Tank Warehouse', + geo: { lat: 10.4, lon: 44.5 } }; const cfg2: EventConfig = {