dav
Version:
WebDAV, CalDAV, and CardDAV client for nodejs and the browser
58 lines (55 loc) • 1.17 kB
JavaScript
import * as ns from '../namespace';
/**
* @param {Object} filter looks like
*
* {
* type: 'comp-filter',
* attrs: {
* name: 'VCALENDAR'
* }
* }
*
* Or maybe
*
* {
* type: 'time-range',
* attrs: {
* start: '20060104T000000Z',
* end: '20060105T000000Z'
* }
* }
*
* You can nest them like so:
*
* {
* type: 'comp-filter',
* attrs: { name: 'VCALENDAR' },
* children: [{
* type: 'comp-filter',
* attrs: { name: 'VEVENT' },
* children: [{
* type: 'time-range',
* attrs: { start: '20060104T000000Z', end: '20060105T000000Z' }
* }]
* }]
* }
*/
export default function prop(item) {
return `<${xmlnsPrefix(item.namespace)}:${item.name} />`;
}
function xmlnsPrefix(namespace) {
switch (namespace) {
case ns.DAV:
return 'd';
case ns.CALENDAR_SERVER:
return 'cs';
case ns.CALDAV_APPLE:
return 'ca';
case ns.CALDAV:
return 'c';
case ns.CARDDAV:
return 'card';
default:
throw new Error('Unrecognized xmlns ' + namespace);
}
}