Skip to content

Commit

Permalink
Merge pull request #2 from panigrah/main
Browse files Browse the repository at this point in the history
Added location, geo, url and organizer fields
  • Loading branch information
PeronGH authored Oct 17, 2022
2 parents ae482be + 95c9a64 commit a93f095
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
19 changes: 18 additions & 1 deletion main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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,
Expand All @@ -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[];
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: '[email protected]'
},
url: 'https://www.google.com/',
location: 'ABC Tank Warehouse',
geo: { lat: 10.4, lon: 44.5 }
};

const cfg2: EventConfig = {
Expand Down

0 comments on commit a93f095

Please sign in to comment.