aboutsummaryrefslogtreecommitdiff
path: root/static/ts/jcal.ts
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--static/ts/jcal.ts (renamed from static/jcal.ts)34
1 files changed, 34 insertions, 0 deletions
diff --git a/static/jcal.ts b/static/ts/jcal.ts
index 41f33db4..feac297b 100644
--- a/static/jcal.ts
+++ b/static/ts/jcal.ts
@@ -1,8 +1,19 @@
+/**
+ Operations for working with jCal.
+
+ jCal is defined in RFC 7265, and is a JSON mapping of the iCalendar standard.
+*/
+
+
export { jcal_to_xcal }
import { xcal, ical_type, JCalProperty, JCal } from './types'
import { asList } from './lib'
+/**
+ * A document with the xcal namespace, and @code{icalendar} as its root
+ * element. Each child is a valid xcal representation of our JCal object.
+ */
function jcal_type_to_xcal(doc: Document, type: ical_type, value: any): Element {
let el = doc.createElementNS(xcal, type);
switch (type) {
@@ -157,6 +168,17 @@ function jcal_property_to_xcal_property(
}
+/**
+ Convert a jCal document into an xCal document.
+
+ @param jcals A list of jcal components. Most iCal formats supports multiple
+ "root" levels components. jCal might do it, which is why this parameter is
+ multi-valued.
+
+ @return A document note which is the root of an xCal document.
+ The root will be an icalendar tag, with each child getting its data from each
+ element of the input.
+ */
function jcal_to_xcal(...jcals: JCal[]): Document {
let doc = document.implementation.createDocument(xcal, 'icalendar');
for (let jcal of jcals) {
@@ -165,6 +187,18 @@ function jcal_to_xcal(...jcals: JCal[]): Document {
return doc;
}
+/**
+ Convert a single jCal entry into a single xCal entry.
+
+ @param doc
+ A Document element in the xcal namespace.
+
+ @param jcal
+ The object to convert
+
+ @return
+ A 1-to-1 mapping of the jCal object as xCal.
+ */
function jcal_to_xcal_inner(doc: Document, jcal: JCal) {
let [tagname, properties, components] = jcal;