Skip to content

Commit

Permalink
feat(event): Add support for event class
Browse files Browse the repository at this point in the history
  • Loading branch information
b123400 committed Nov 5, 2021
1 parent 7e7eb62 commit a227aa2
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
44 changes: 44 additions & 0 deletions src/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ export enum ICalEventTransparency {
OPAQUE = 'OPAQUE'
}

export enum ICalEventClass {
PUBLIC = 'PUBLIC',
PRIVATE = 'PRIVATE',
CONFIDENTIAL = 'CONFIDENTIAL'
}

export interface ICalEventData {
id?: string | number | null,
sequence?: number,
Expand All @@ -72,6 +78,7 @@ export interface ICalEventData {
transparency?: ICalEventTransparency | null,
created?: ICalDateTimeValue | null,
lastModified?: ICalDateTimeValue | null,
class?: ICalEventClass | null;
x?: {key: string, value: string}[] | [string, string][] | Record<string, string>;
}

Expand Down Expand Up @@ -100,6 +107,7 @@ interface ICalEventInternalData {
transparency: ICalEventTransparency | null,
created: ICalDateTimeValue | null,
lastModified: ICalDateTimeValue | null,
class: ICalEventClass | null,
x: [string, string][];
}

Expand Down Expand Up @@ -190,6 +198,7 @@ export default class ICalEvent {
transparency: null,
created: null,
lastModified: null,
class: null,
x: []
};

Expand Down Expand Up @@ -222,6 +231,7 @@ export default class ICalEvent {
data.transparency !== undefined && this.transparency(data.transparency);
data.created !== undefined && this.created(data.created);
data.lastModified !== undefined && this.lastModified(data.lastModified);
data.class !== undefined && this.class(data.class);
data.x !== undefined && this.x(data.x);
}

Expand Down Expand Up @@ -1228,6 +1238,36 @@ export default class ICalEvent {
return this;
}

/**
* Get the event's class
* @since 2.0.0
*/
class(): ICalEventClass | null;

/**
* Set the event's class
*
* ```javascript
* import ical, { ICalEventClass } from 'ical-generator';
* event.class(ICalEventClass.PRIVATE);
* ```
*
* @since 2.0.0
*/
class(class_: ICalEventClass | null): this;
class(class_?: ICalEventClass | null): this | ICalEventClass | null {
if (class_ === undefined) {
return this.data.class;
}
if (class_ === null) {
this.data.class = null;
return this;
}

this.data.class = checkEnum(ICalEventClass, class_) as ICalEventClass;
return this;
}


/**
* Set X-* attributes. Woun't filter double attributes,
Expand Down Expand Up @@ -1545,6 +1585,10 @@ export default class ICalEvent {
g += 'LAST-MODIFIED:' + formatDate(this.calendar.timezone(), this.data.lastModified) + '\r\n';
}

if (this.data.class) {
g+= 'CLASS:' + this.data.class.toUpperCase() + '\r\n';
}

g += 'END:VEVENT\r\n';
return g;
}
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ export {
ICalEventBusyStatus,
ICalEventTransparency,
ICalEventData,
ICalEventJSONData
ICalEventJSONData,
ICalEventClass,
} from './event';

export {
Expand Down

0 comments on commit a227aa2

Please sign in to comment.