Skip to content

Commit

Permalink
feat: make domain optional (#209)
Browse files Browse the repository at this point in the history
* make domain optional

* adjust indentation
  • Loading branch information
rubys committed Aug 12, 2020
1 parent 15bfb43 commit e3362c9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ cal.domain('sebbo.net');

#### domain([_String_ domain])

Use this method to set your server's hostname. It will be used to generate the feed's UID. Default hostname is your
server's one (`require('os').hostname()`).
Use this method to set your server's hostname. If provided, it will be used to generate the feed's UID.
`require('os').hostname()` can be used to get your server's hostname.


#### prodId([_String_|_Object_ prodId])
Expand Down Expand Up @@ -289,7 +289,10 @@ Empty the Calender.

#### uid([_String_|_Number_ uid]) or id([_String_|_Number_ id])

Use this method to set the event's ID. If not set, an UID will be generated randomly. When output, the ID will be suffixed with '@' + your calendar's domain.
Use this method to set the event's ID. If not set, an UID will be generated randomly.
If your calendar's domain is provided, the ID will be suffixed with '@' + your calendar's domain.
If you do not provide a calendar domain, generating an ID using the
[uuid](https://www.npmjs.com/package/uuid) module is recommended.


#### sequence([_Number_ sequence])
Expand Down
7 changes: 6 additions & 1 deletion src/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,12 @@ class ICalEvent {

// DATE & TIME
g += 'BEGIN:VEVENT\r\n';
g += 'UID:' + this._data.id + '@' + this._calendar.domain() + '\r\n';
let domain = this._calendar.domain();
if (domain) {
g += 'UID:' + this._data.id + '@' + domain + '\r\n';
} else {
g += 'UID:' + this._data.id + '\r\n';
}

// SEQUENCE
g += 'SEQUENCE:' + this._data.sequence + '\r\n';
Expand Down
2 changes: 1 addition & 1 deletion test/test_event.js
Original file line number Diff line number Diff line change
Expand Up @@ -1731,7 +1731,7 @@ describe('ical-generator Event', function () {
summary: ':)'
}, cal);

assert.ok(event._generate().indexOf('UID:42@') > -1, 'without domain');
assert.ok(event._generate().indexOf('UID:42\r') > -1, 'without domain');

cal.domain('dojo-enterprises.wtf');
assert.ok(event._generate().indexOf('UID:42@dojo-enterprises.wtf') > -1, 'with domain');
Expand Down

0 comments on commit e3362c9

Please sign in to comment.