1+ /**
2+ * Interface representing the options for a feed.
3+ */
14export interface FeedOptions {
25 title : string ;
36 description : string ;
@@ -19,6 +22,11 @@ export interface FeedOptions {
1922 icon ?: string ;
2023}
2124
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+ */
2230export function escapeXml ( unsafe : string ) : string {
2331 const escapeMap : { [ key : string ] : string } = {
2432 "<" : "<" ,
@@ -30,11 +38,19 @@ export function escapeXml(unsafe: string): string {
3038 return unsafe . replace ( / [ < > & ' " ] / g, ( c ) => escapeMap [ c ] || c ) ;
3139}
3240
41+ /**
42+ * Abstract class representing a base feed.
43+ * @template T - The type of items in the feed.
44+ */
3345export abstract class BaseFeed < T > {
3446 protected options : FeedOptions ;
3547 protected items : Array < T > ;
3648 protected categories : Set < string > ;
3749
50+ /**
51+ * Creates an instance of BaseFeed.
52+ * @param options - The options for the feed.
53+ */
3854 constructor ( options : FeedOptions ) {
3955 this . options = {
4056 ...options ,
@@ -44,16 +60,32 @@ export abstract class BaseFeed<T> {
4460 this . categories = new Set ( ) ;
4561 }
4662
63+ /**
64+ * Builds the feed and returns it as a string.
65+ * @returns The feed as a string.
66+ */
4767 abstract build ( ) : string ;
4868
69+ /**
70+ * Adds an item to the feed.
71+ * @param item - The item to be added.
72+ */
4973 addItem ( item : T ) {
5074 this . items . push ( item ) ;
5175 }
5276
77+ /**
78+ * Adds a category to the feed.
79+ * @param category - The category to be added.
80+ */
5381 addCategory ( category : string ) {
5482 this . categories . add ( category ) ;
5583 }
5684
85+ /**
86+ * Adds a contributor to the feed.
87+ * @param contributor - The contributor to be added.
88+ */
5789 addContributor ( contributor : { name : string ; email : string ; link ?: string } ) {
5890 this . options . authors . push ( contributor ) ;
5991 }
0 commit comments