Skip to content

Commit

Permalink
feat(Calendar): add new clear method
Browse files Browse the repository at this point in the history
Closes #188

BREAKING CHANGE: Calendar's `clear()` method is a completely new implementation and, unlike previous versions, will not reset metadata such as `name` or `prodId`. Only the events will be removed
  • Loading branch information
sebbo2002 committed Mar 21, 2021
1 parent f2d68d4 commit 1ebefcb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,6 @@ export default class ICalCalendar {
* that have already been added are retained.
*
* @since 0.2.0
* @returns {ICalEvent[]|ICalCalendar}
*/
events(): ICalEvent[];
events(events: (ICalEvent | ICalEventData)[]): this;
Expand All @@ -308,6 +307,18 @@ export default class ICalCalendar {
}


/**
* Remove all events from the calendar without
* touching any other data like name or prodId.
*
* @since 2.0.0-develop.1
*/
clear(): this {
this.data.events = [];
return this;
}


/**
* Save ical file with `fs.save`. Only works in node.js environments.
* If no callback is specified, `fs/promises` is used and a promise is returned.
Expand Down
10 changes: 10 additions & 0 deletions test/calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,16 @@ describe('ical-generator Calendar', function () {
});
});

describe('clear()', function () {
it('should do the job', function () {
const cal = new ICalCalendar();
cal.createEvent({});
assert.strictEqual(cal.events().length, 1);
assert.deepStrictEqual(cal.clear(), cal);
assert.strictEqual(cal.events().length, 0);
});
});

describe('save()', function () {
it('should return all public methods and save it', function (done) {
const file = join(__dirname, 'save.ical');
Expand Down

0 comments on commit 1ebefcb

Please sign in to comment.