1
+ /**
2
+ * Interface representing the options for a feed.
3
+ */
1
4
export interface FeedOptions {
2
5
title : string ;
3
6
description : string ;
@@ -19,6 +22,11 @@ export interface FeedOptions {
19
22
icon ?: string ;
20
23
}
21
24
25
+ /**
26
+ * Escapes special characters in a string to their corresponding XML entities.
27
+ * @param unsafe - The string to be escaped.
28
+ * @returns The escaped string.
29
+ */
22
30
export function escapeXml ( unsafe : string ) : string {
23
31
const escapeMap : { [ key : string ] : string } = {
24
32
"<" : "<" ,
@@ -30,11 +38,19 @@ export function escapeXml(unsafe: string): string {
30
38
return unsafe . replace ( / [ < > & ' " ] / g, ( c ) => escapeMap [ c ] || c ) ;
31
39
}
32
40
41
+ /**
42
+ * Abstract class representing a base feed.
43
+ * @template T - The type of items in the feed.
44
+ */
33
45
export abstract class BaseFeed < T > {
34
46
protected options : FeedOptions ;
35
47
protected items : Array < T > ;
36
48
protected categories : Set < string > ;
37
49
50
+ /**
51
+ * Creates an instance of BaseFeed.
52
+ * @param options - The options for the feed.
53
+ */
38
54
constructor ( options : FeedOptions ) {
39
55
this . options = {
40
56
...options ,
@@ -44,16 +60,32 @@ export abstract class BaseFeed<T> {
44
60
this . categories = new Set ( ) ;
45
61
}
46
62
63
+ /**
64
+ * Builds the feed and returns it as a string.
65
+ * @returns The feed as a string.
66
+ */
47
67
abstract build ( ) : string ;
48
68
69
+ /**
70
+ * Adds an item to the feed.
71
+ * @param item - The item to be added.
72
+ */
49
73
addItem ( item : T ) {
50
74
this . items . push ( item ) ;
51
75
}
52
76
77
+ /**
78
+ * Adds a category to the feed.
79
+ * @param category - The category to be added.
80
+ */
53
81
addCategory ( category : string ) {
54
82
this . categories . add ( category ) ;
55
83
}
56
84
85
+ /**
86
+ * Adds a contributor to the feed.
87
+ * @param contributor - The contributor to be added.
88
+ */
57
89
addContributor ( contributor : { name : string ; email : string ; link ?: string } ) {
58
90
this . options . authors . push ( contributor ) ;
59
91
}
0 commit comments