Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added RRULE and Duration; handle colons inside summary text #4

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions icsToJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ const DESCRIPTION = "DESCRIPTION";
const SUMMARY = "SUMMARY";
const LOCATION = "LOCATION";
const ALARM = "VALARM";
const RRULE = "RRULE";
const DURATION = "DURATION";

const keyMap = {
[START_DATE]: "startDate",
[END_DATE]: "endDate",
[DESCRIPTION]: "description",
[SUMMARY]: "summary",
[LOCATION]: "location"
[LOCATION]: "location",
[RRULE]: "rrule",
[DURATION]:"duration"
};

const clean = string => unescape(string).trim();
Expand All @@ -33,7 +37,7 @@ const icsToJson = icsData => {
const lineData = line.split(":");

let key = lineData[0];
const value = lineData[1];
let value = lineData[1];

if (key.indexOf(";") !== -1) {
const keyParts = key.split(";");
Expand Down Expand Up @@ -72,10 +76,22 @@ const icsToJson = icsData => {
if (!isAlarm) currentObj[keyMap[DESCRIPTION]] = clean(value);
break;
case SUMMARY:
if ( lineData.length > 2) {
// summary had colon's in the text, recombine
lineData.shift();
value = lineData.join(":"); // remove the key and then join remaining back seperated by :
}
currentObj[keyMap[SUMMARY]] = clean(value);
break;
case LOCATION:
currentObj[keyMap[LOCATION]] = clean(value);
break;
case RRULE:
currentObj[keyMap[RRULE]] = clean(value);
break;
case DURATION:
currentObj[keyMap[DURATION]] = clean(value);
break;
default:
continue;
}
Expand Down