Skip to content

Commit eb63fcc

Browse files
committedOct 28, 2024··
feat: add symbol documentation
1 parent c741826 commit eb63fcc

File tree

5 files changed

+64
-0
lines changed

5 files changed

+64
-0
lines changed
 

‎mod.ts

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ import { AtomFeed } from "./src/atom.ts";
22
import { RssFeed } from "./src/rss.ts";
33
import { JsonFeed } from "./src/json.ts";
44

5+
/** Atom feed export */
56
export const Atom = AtomFeed;
7+
8+
/** RSS feed export */
69
export const Rss = RssFeed;
10+
11+
/** JSON feed export */
712
export const Json = JsonFeed;

‎src/atom.ts

+9
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,20 @@ interface AtomEntry {
1313
};
1414
}
1515

16+
/** Class representing an Atom feed. */
1617
export class AtomFeed extends BaseFeed<AtomEntry> {
18+
/**
19+
* Create an AtomFeed.
20+
* @param {FeedOptions} options - The feed options.
21+
*/
1722
constructor(options: FeedOptions) {
1823
super(options);
1924
}
2025

26+
/**
27+
* Build the Atom feed XML string.
28+
* @returns {string} The XML string of the Atom feed.
29+
*/
2130
build(): string {
2231
const xmlParts: string[] = [
2332
`<?xml version="1.0" encoding="UTF-8"?>\n`,

‎src/common.ts

+32
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/**
2+
* Interface representing the options for a feed.
3+
*/
14
export 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+
*/
2230
export function escapeXml(unsafe: string): string {
2331
const escapeMap: { [key: string]: string } = {
2432
"<": "&lt;",
@@ -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+
*/
3345
export 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
}

‎src/json.ts

+9
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,20 @@ interface JsonItem {
88
url: string;
99
}
1010

11+
/** This class represents a JSON Feed and provides methods to build the feed. */
1112
export class JsonFeed extends BaseFeed<JsonItem> {
13+
/**
14+
* Constructs a new JsonFeed instance.
15+
* @param options - The options for the feed.
16+
*/
1217
constructor(options: FeedOptions) {
1318
super(options);
1419
}
1520

21+
/**
22+
* Builds the JSON feed and returns it as a string.
23+
* @returns The JSON feed as a string.
24+
*/
1625
build(): string {
1726
const json: Record<string, unknown> = {
1827
version: "https://jsonfeed.org/version/1",

‎src/rss.ts

+9
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,20 @@ interface RssItem {
1212
};
1313
}
1414

15+
/** Class representing an RSS feed. */
1516
export class RssFeed extends BaseFeed<RssItem> {
17+
/**
18+
* Create an RSS feed.
19+
* @param {FeedOptions} options - The options for the feed.
20+
*/
1621
constructor(options: FeedOptions) {
1722
super(options);
1823
}
1924

25+
/**
26+
* Build the RSS feed XML string.
27+
* @returns {string} The RSS feed as an XML string.
28+
*/
2029
build(): string {
2130
const xmlParts: string[] = [
2231
`<?xml version="1.0" encoding="UTF-8"?>\n`,

0 commit comments

Comments
 (0)
Please sign in to comment.