aboutsummaryrefslogtreecommitdiff
path: root/static/jcal.ts
diff options
context:
space:
mode:
Diffstat (limited to 'static/jcal.ts')
-rw-r--r--static/jcal.ts143
1 files changed, 74 insertions, 69 deletions
diff --git a/static/jcal.ts b/static/jcal.ts
index 003294d1..db833a3c 100644
--- a/static/jcal.ts
+++ b/static/jcal.ts
@@ -1,60 +1,63 @@
-function jcal_type_to_xcal(doc, type, value) {
+function jcal_type_to_xcal(doc: Document, type: ical_type, value: any): Element {
let el = doc.createElementNS(xcal, type);
switch (type) {
- case 'boolean':
- el.textContent = value ? "true" : "false";
- break;
-
- case 'float':
- case 'integer':
- el.textContent = '' + value;
- break;
-
- case 'period':
- let [start, end] = value;
- let startEl = doc.createElementNS(xcal, 'start');
- startEl.textContent = start;
- let endEL;
- if (end.find('P')) {
- endEl = doc.createElementNS(xcal, 'duration');
- } else {
- endEl = doc.createElementNS(xcal, 'end');
- }
- endEl.textContent = end;
- el.appendChild(startEl);
- el.appendChild(endEl);
- break;
-
- case 'recur':
- for (var key in value) {
- if (! value.hasOwnProperty(key)) continue;
- let e = doc.createElementNS(xcal, key);
- e.textContent = value[key];
- el.appendChild(e);
- }
- break;
+ case 'boolean':
+ el.textContent = value ? "true" : "false";
+ break;
+
+ case 'float':
+ case 'integer':
+ el.textContent = '' + value;
+ break;
+
+ case 'period':
+ let [start, end] = value;
+ let startEl = doc.createElementNS(xcal, 'start');
+ startEl.textContent = start;
+ let endEl: Element;
+ if (end.find('P')) {
+ endEl = doc.createElementNS(xcal, 'duration');
+ } else {
+ endEl = doc.createElementNS(xcal, 'end');
+ }
+ endEl.textContent = end;
+ el.appendChild(startEl);
+ el.appendChild(endEl);
+ break;
+
+ case 'recur':
+ for (var key in value) {
+ if (!value.hasOwnProperty(key)) continue;
+ let e = doc.createElementNS(xcal, key);
+ e.textContent = value[key];
+ el.appendChild(e);
+ }
+ break;
- case 'date':
- case 'time':
- case 'date-time':
+ case 'date':
+ // case 'time':
+ case 'date-time':
- case 'duration':
+ case 'duration':
- case 'binary':
- case 'text':
- case 'uri':
- case 'cal-address':
- case 'utc-offset':
- el.textContent = value;
- break;
+ case 'binary':
+ case 'text':
+ case 'uri':
+ case 'cal-address':
+ case 'utc-offset':
+ el.textContent = value;
+ break;
- default:
+ default:
/* TODO error */
}
return el;
}
-function jcal_property_to_xcal_property(doc, jcal) {
+function jcal_property_to_xcal_property(
+ doc: Document,
+ jcal: JCalProperty
+): Element {
let [propertyName, params, type, ...values] = jcal;
let tag = doc.createElementNS(xcal, propertyName);
@@ -71,7 +74,7 @@ function jcal_property_to_xcal_property(doc, jcal) {
is empty beforehand, and instead check the
number of children of paramEl below.
*/
- if (! params.hasOwnProperty(key)) continue;
+ if (!params.hasOwnProperty(key)) continue;
let el = doc.createElementNS(xcal, key);
@@ -84,7 +87,7 @@ function jcal_property_to_xcal_property(doc, jcal) {
paramEl.appendChild(el);
}
- if (paramEl.childCount > 0) {
+ if (paramEl.childElementCount > 0) {
tag.appendChild(paramEl);
}
@@ -92,20 +95,21 @@ function jcal_property_to_xcal_property(doc, jcal) {
// let typeEl = doc.createElementNS(xcal, type);
switch (propertyName) {
- case 'geo':
- if (type == 'float') {
- // assert values[0] == [x, y]
- let [x, y] = values[0];
- let lat = doc.createElementNS(xcal, 'latitude')
- let lon = doc.createElementNS(xcal, 'longitude')
- lat.textContent = x;
- lon.textContent = y;
- tag.appendChild(lat);
- tag.appendChild(lon);
- } else {
- /* TODO, error */
- }
- break;
+ case 'geo':
+ if (type == 'float') {
+ // assert values[0] == [x, y]
+ let [x, y] = values[0];
+ let lat = doc.createElementNS(xcal, 'latitude')
+ let lon = doc.createElementNS(xcal, 'longitude')
+ lat.textContent = x;
+ lon.textContent = y;
+ tag.appendChild(lat);
+ tag.appendChild(lon);
+ } else {
+ /* TODO, error */
+ }
+ break;
+ /* TODO reenable this
case 'request-status':
if (type == 'text') {
// assert values[0] instanceof Array
@@ -126,20 +130,21 @@ function jcal_property_to_xcal_property(doc, jcal) {
tag.appendChild(dataEl);
}
} else {
- /* TODO, error */
+ /* TODO, error * /
}
break;
- default:
- for (let value of values) {
- tag.appendChild(jcal_type_to_xcal(doc, type, value))
- }
+ */
+ default:
+ for (let value of values) {
+ tag.appendChild(jcal_type_to_xcal(doc, type, value))
+ }
}
return tag;
}
-function jcal_to_xcal(...jcals) {
+function jcal_to_xcal(...jcals: JCal[]): Document {
let doc = document.implementation.createDocument(xcal, 'icalendar');
for (let jcal of jcals) {
doc.documentElement.appendChild(jcal_to_xcal_inner(doc, jcal));
@@ -147,7 +152,7 @@ function jcal_to_xcal(...jcals) {
return doc;
}
-function jcal_to_xcal_inner(doc, jcal) {
+function jcal_to_xcal_inner(doc: Document, jcal: JCal) {
let [tagname, properties, components] = jcal;
let xcal_tag = doc.createElementNS(xcal, tagname);