Skip to content

Commit

Permalink
feat(Event): Make organizer.email optional
Browse files Browse the repository at this point in the history
Closes #137
  • Loading branch information
sebbo2002 committed Mar 23, 2021
1 parent 3f9ae02 commit 8450492
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
6 changes: 5 additions & 1 deletion src/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -994,10 +994,14 @@ export default class ICalEvent {
// ORGANIZER
if (this.data.organizer) {
g += 'ORGANIZER;CN="' + escape(this.data.organizer.name) + '"';

if (this.data.organizer.email && this.data.organizer.mailto) {
g += ';EMAIL=' + escape(this.data.organizer.email);
}
g += ':mailto:' + escape(this.data.organizer.mailto || this.data.organizer.email) + '\r\n';
if(this.data.organizer.email) {
g += ':mailto:' + escape(this.data.organizer.mailto || this.data.organizer.email);
}
g += '\r\n';
}

// ATTENDEES
Expand Down
5 changes: 1 addition & 4 deletions src/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,7 @@ export function checkNameAndMail (attribute: string, value: string | ICalOrganiz
}

if (!result.name) {
throw new Error('`organizer.name` is empty!');
}
if (!result.email) {
throw new Error('`organizer.email` is empty!');
throw new Error('`' + attribute + '.name` is empty!');
}

return result;
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export interface ICalGeo {

export interface ICalOrganizer {
name: string;
email: string;
email?: string;
mailto?: string;
}

Expand Down
19 changes: 14 additions & 5 deletions test/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1197,11 +1197,6 @@ describe('ical-generator Event', function () {

it('should throw error when object misses data', function () {
const e = new ICalEvent({}, new ICalCalendar());
assert.throws(function () {
// @ts-ignore
e.organizer({name: 'Sebastian Pekarek'});
}, /`organizer\.email`/);

assert.throws(function () {
// @ts-ignore
e.organizer({email: 'foo'});
Expand All @@ -1219,6 +1214,20 @@ describe('ical-generator Event', function () {
e.organizer(NaN);
}, /`organizer`/);
});

it('should work without an email', function () {
const event = new ICalEvent({
start: moment(),
summary: 'Example Event'
}, new ICalCalendar());

event.organizer({name: 'Sebastian Pekarek'});
assert.deepStrictEqual(event.organizer(), {
name: 'Sebastian Pekarek',
email: undefined,
mailto: undefined
});
});
});

describe('createAttendee()', function () {
Expand Down

0 comments on commit 8450492

Please sign in to comment.