From e3362c94e2b055043d3db74c51563d6107a5a097 Mon Sep 17 00:00:00 2001 From: Sam Ruby Date: Wed, 12 Aug 2020 11:48:15 -0400 Subject: [PATCH] feat: make domain optional (#209) * make domain optional * adjust indentation --- README.md | 9 ++++++--- src/event.js | 7 ++++++- test/test_event.js | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 3a59245c1..6744d0650 100755 --- a/README.md +++ b/README.md @@ -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]) @@ -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]) diff --git a/src/event.js b/src/event.js index 9363cc3e0..5d560cc19 100755 --- a/src/event.js +++ b/src/event.js @@ -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'; diff --git a/test/test_event.js b/test/test_event.js index 7a492943d..79f3eb2a9 100644 --- a/test/test_event.js +++ b/test/test_event.js @@ -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');