Repository: adamgibbons/ics
Pull request #147 (2020-08-13 21:36:37)

Format location
The location field needs to format the "comma" as well, otherwise it does not work properly on macOS Calendar app


Patch:
diff --git a/src/pipeline/format.js b/src/pipeline/format.js
index 5497d51..65d30e8 100644
--- a/src/pipeline/format.js
+++ b/src/pipeline/format.js
@@ -4,6 +4,7 @@ import {
     setOrganizer,
     formatDate,
     setDescription,
+    setLocation,
     setSummary,
     setGeolocation,
     formatDuration,
@@ -70,7 +71,7 @@ export default function formatEvent(attributes = {}) {
   icsFormat += description ? (foldLine(`DESCRIPTION:${setDescription(description)}`) + '\r\n') : ''
   icsFormat += url ? (foldLine(`URL:${url}`) + '\r\n') : ''
   icsFormat += geo ? (foldLine(`GEO:${setGeolocation(geo)}`) + '\r\n') : ''
-  icsFormat += location ? (foldLine(`LOCATION:${location}`) + '\r\n') : ''
+  icsFormat += location ? (foldLine(`LOCATION:${setLocation(location)}`) + '\r\n') : ''
   icsFormat += status ? (foldLine(`STATUS:${status}`) + '\r\n') : ''
   icsFormat += categories ? (foldLine(`CATEGORIES:${categories}`) + '\r\n') : ''
   icsFormat += organizer ? (foldLine(`ORGANIZER;${setOrganizer(organizer)}`) + '\r\n') : ''
@@ -82,7 +83,7 @@ export default function formatEvent(attributes = {}) {
       icsFormat += foldLine(`ATTENDEE;${setContact(attendee)}`) + '\r\n'
     })
   }
-  
+
   if (alarms) {
     alarms.map(function (alarm) {
       icsFormat += setAlarm(alarm)
diff --git a/src/utils/index.js b/src/utils/index.js
index a466ffb..4b5663c 100644
--- a/src/utils/index.js
+++ b/src/utils/index.js
@@ -11,6 +11,7 @@ import setDescription from './set-description'
 import setSummary from './set-summary'
 import formatDuration from './format-duration'
 import foldLine from './fold-line'
+import setLocation from './set-location'
 
 export {
   formatDate,
@@ -25,5 +26,6 @@ export {
   formatDuration,
   setSummary,
   setDescription,
-  foldLine
+  foldLine,
+  setLocation
 }
diff --git a/src/utils/set-location.js b/src/utils/set-location.js
new file mode 100644
index 0000000..58e4fbe
--- /dev/null
+++ b/src/utils/set-location.js
@@ -0,0 +1,5 @@
+import formatText from "./format-text";
+
+export default function setLocation(location) {
+  return formatText(location);
+}


Test patch:
diff --git a/test/pipeline/format.spec.js b/test/pipeline/format.spec.js
index f6a91ed..289a267 100644
--- a/test/pipeline/format.spec.js
+++ b/test/pipeline/format.spec.js
@@ -138,7 +138,7 @@ describe('pipeline.formatEvent', () => {
   it('writes a location', () => {
     const event = buildEvent({ location: 'Folsom Field, University of Colorado at Boulder' })
     const formattedEvent = formatEvent(event)
-    expect(formattedEvent).to.contain('LOCATION:Folsom Field, University of Colorado at Boulder')
+    expect(formattedEvent).to.contain('LOCATION:Folsom Field\\, University of Colorado at Boulder')
   })
   it('writes a status', () => {
     const event = buildEvent({ status: 'tentative' })
@@ -233,7 +233,7 @@ describe('pipeline.formatEvent', () => {
   })
   it('writes a recurrence rule', () => {
     const formattedEvent = formatEvent({ recurrenceRule: 'FREQ=DAILY'})
-    
+
     expect(formattedEvent).to.contain('RRULE:FREQ=DAILY')
   })
 })