Skip to content

Commit a93f095

Browse files
authored
Merge pull request #2 from panigrah/main
Added location, geo, url and organizer fields
2 parents ae482be + 95c9a64 commit a93f095

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

main.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ const eventBegin: ContentLine = ['BEGIN', 'VEVENT'];
1717

1818
const eventEnd: ContentLine = ['END', 'VEVENT'];
1919

20+
const parseGeo = (geo?: {lat: number, lon: number}) => {
21+
return geo ? `${geo.lat};${geo.lon}` : undefined;
22+
}
23+
24+
const parseOrganizer = (organizer?: {name: string, email: string}) => {
25+
return organizer? `CN=${organizer.name}:mailto:${organizer.email}` : undefined
26+
}
27+
2028
export class Event {
2129
constructor(protected config: EventConfig) {
2230
if (config.duration !== undefined) {
@@ -39,7 +47,7 @@ export class Event {
3947

4048
toLines(): ContentLine[] {
4149
const uid = crypto.randomUUID();
42-
const { title, desc, rrule, alarm } = this.config;
50+
const { title, desc, rrule, alarm, location, url, organizer, geo, htmlContent } = this.config;
4351

4452
const result = [
4553
eventBegin,
@@ -49,7 +57,11 @@ export class Event {
4957
['DTEND', parseDate(this.config.endDate!)],
5058
['SUMMARY', title],
5159
['DESCRIPTION', desc],
60+
['LOCATION', location],
61+
['URL', url],
62+
['GEO', parseGeo(geo)],
5263
['RRULE', parseRRule(rrule)],
64+
['ORGANIZER', parseOrganizer(organizer)],
5365
...parseAlarm(alarm),
5466
eventEnd,
5567
].filter(line => line[1] !== undefined) as ContentLine[];
@@ -80,6 +92,11 @@ export interface EventConfig {
8092
desc?: string;
8193
rrule?: RecurrenceRule;
8294
alarm?: AlarmConfig;
95+
location?: string;
96+
url?: string;
97+
organizer?: { name: string; email: string; dir?: string; };
98+
geo?: { lat: number; lon: number; };
99+
htmlContent?: string;
83100
}
84101

85102
export interface AlarmConfig {

tests.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ Deno.test({
3838
beginDate: [2022, 9, 6, 9, 30],
3939
endDate: [2022, 9, 6, 10],
4040
desc: 'Implement a module to generate .ics files',
41+
organizer: {
42+
name: 'Sam Worthington',
43+
44+
},
45+
url: 'https://www.google.com/',
46+
location: 'ABC Tank Warehouse',
47+
geo: { lat: 10.4, lon: 44.5 }
4148
};
4249

4350
const cfg2: EventConfig = {

0 commit comments

Comments
 (0)