ical-generator 3.5.2-develop.1 → 3.5.2-develop.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,98 @@
1
+ 'use strict';
2
+
3
+
4
+ import {escape} from './tools';
5
+
6
+
7
+ export interface ICalCategoryData {
8
+ name?: string | null
9
+ }
10
+
11
+ export interface ICalCategoryInternalData {
12
+ name: string | null
13
+ }
14
+
15
+
16
+ /**
17
+ * Usually you get an `ICalCategory` object like this:
18
+ *
19
+ * ```javascript
20
+ * import ical from 'ical-generator';
21
+ * const calendar = ical();
22
+ * const event = calendar.createEvent();
23
+ * const category = event.createCategory();
24
+ * ```
25
+ *
26
+ * You can also use the [[`ICalCategory`]] object directly:
27
+ *
28
+ * ```javascript
29
+ * import ical, {ICalCategory} from 'ical-generator';
30
+ * const category = new ICalCategory();
31
+ * event.categories([category]);
32
+ * ```
33
+ */
34
+ export default class ICalCategory {
35
+ private readonly data: ICalCategoryInternalData;
36
+
37
+ /**
38
+ * Constructor of [[`ICalCategory`]].
39
+ * @param data Category Data
40
+ */
41
+ constructor(data: ICalCategoryData) {
42
+ this.data = {
43
+ name: null
44
+ };
45
+
46
+ data.name !== undefined && this.name(data.name);
47
+ }
48
+
49
+
50
+ /**
51
+ * Get the category name
52
+ * @since 0.3.0
53
+ */
54
+ name(): string | null;
55
+
56
+ /**
57
+ * Set the category name
58
+ * @since 0.3.0
59
+ */
60
+ name(name: string | null): this;
61
+ name(name?: string | null): this | string | null {
62
+ if (name === undefined) {
63
+ return this.data.name;
64
+ }
65
+
66
+ this.data.name = name || null;
67
+ return this;
68
+ }
69
+
70
+
71
+ /**
72
+ * Return a shallow copy of the category's options for JSON stringification.
73
+ * Can be used for persistence.
74
+ *
75
+ * @since 0.2.4
76
+ */
77
+ toJSON(): ICalCategoryInternalData {
78
+ return Object.assign({}, this.data);
79
+ }
80
+
81
+
82
+ /**
83
+ * Return generated category name as a string.
84
+ *
85
+ * ```javascript
86
+ * console.log(category.toString());
87
+ * ```
88
+ */
89
+ toString(): string {
90
+
91
+ // CN / Name
92
+ if (!this.data.name) {
93
+ throw new Error('No value for `name` in ICalCategory given!');
94
+ }
95
+
96
+ return escape(this.data.name, false);
97
+ }
98
+ }