Skip to content

Commit 6e1cd56

Browse files
committed
Refactor types
1 parent 13b60ba commit 6e1cd56

File tree

3 files changed

+82
-29
lines changed

3 files changed

+82
-29
lines changed

lib/atom.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* @typedef {import('xast').Element} Element
33
* @typedef {import('xast').Root} Root
44
* @typedef {import('./types.js').Author} Author
5-
* @typedef {import('./types.js').Enclosure} Enclosure
65
* @typedef {import('./types.js').Channel} Channel
76
* @typedef {import('./types.js').Entry} Entry
87
*/
@@ -18,8 +17,11 @@ import {toAuthor, toDate} from './util.js'
1817
* Same API as `rss` otherwise.
1918
*
2019
* @param {Channel} channel
20+
* Data on the feed (the group of items).
2121
* @param {Array<Entry>} [data]
22+
* List of entries.
2223
* @returns {Root}
24+
* Atom feed.
2325
*/
2426
export function atom(channel, data) {
2527
const now = new Date()

lib/rss.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
/**
22
* @typedef {import('xast').Element} Element
33
* @typedef {import('xast').Root} Root
4-
* @typedef {import('./types.js').Author} Author
5-
* @typedef {import('./types.js').Enclosure} Enclosure
64
* @typedef {import('./types.js').Channel} Channel
75
* @typedef {import('./types.js').Entry} Entry
86
*/
@@ -18,8 +16,11 @@ import {toAuthor, toDate} from './util.js'
1816
* Same API as `atom` otherwise.
1917
*
2018
* @param {Channel} channel
19+
* Data on the feed (the group of items).
2120
* @param {Array<Entry>} [data]
21+
* List of entries.
2222
* @returns {Root}
23+
* RSS feed.
2324
*/
2425
export function rss(channel, data) {
2526
const now = new Date()

lib/types.js

Lines changed: 76 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,83 @@
11
/**
2-
* @typedef Author An author object
3-
* @property {string} name Example: `'Acme, Inc.'` or `'Jane Doe'`
4-
* @property {string} [email] Example: `john@example.org`
5-
* @property {string} [url] Example: `'https://example.org/john'`. `url` is used in `atom`, not in `rss`.
2+
* @typedef Author
3+
* An author object
4+
* @property {string} name
5+
* Example: `'Acme, Inc.'` or `'Jane Doe'`
6+
* @property {string} [email]
7+
* Example: `john@example.org`
8+
* @property {string} [url]
9+
* Example: `'https://example.org/john'`.
10+
* `url` is used in `atom`, not in `rss`.
611
*
7-
* @typedef Enclosure Media
8-
* @property {string} url Full URL to the resource (example: `'http://dallas.example.com/joebob_050689.mp3'`).
9-
* @property {number} size Resource size in bytes (example: `24986239`).
10-
* @property {string} type Mime type of the resource (example: `'audio/mpeg'`).
12+
* @typedef Enclosure
13+
* Media
14+
* @property {string} url
15+
* Full URL to the resource (example:
16+
* `'http://dallas.example.com/joebob_050689.mp3'`).
17+
* @property {number} size
18+
* Resource size in bytes (example: `24986239`).
19+
* @property {string} type
20+
* Mime type of the resource (example: `'audio/mpeg'`).
1121
*
12-
* @typedef Channel Data on the feed (the group of items).
13-
* @property {string} title Title of the channel (required, example: `Zimbabwe | The Guardian`).
14-
* @property {string} url Full URL to the site (required, example: `'https://www.theguardian.com/world/zimbabwe'`).
15-
* @property {string} [feedUrl] Full URL to this channel (example: `'https://www.adweek.com/feed/'`). Make sure to pass different ones to `rss` and `atom`! You *should* define this.
16-
* @property {string} [description] Short description of the channel (example: `Album Reviews`). You *should* define this.
17-
* @property {string} [lang] BCP 47 language tag representing the language of the whole channel (example: `'fr-BE'`). You *should* define this.
18-
* @property {string|Author} [author] Optional author of the whole channel. Either `string`, in which case it’s as passing `{name: string}`. Or an author object.
19-
* @property {Array<string>} [tags] Categories of the channel (example: `['JavaScript', 'React']`).
22+
* @typedef Channel
23+
* Data on the feed (the group of items).
24+
* @property {string} title
25+
* Title of the channel (required, example: `Zimbabwe | The Guardian`).
26+
* @property {string} url
27+
* Full URL to the site (required, example:
28+
* `'https://www.theguardian.com/world/zimbabwe'`).
29+
* @property {string} [feedUrl]
30+
* Full URL to this channel (example:
31+
* `'https://www.adweek.com/feed/'`).
32+
* Make sure to pass different ones to `rss` and `atom`!
33+
* You *should* define this.
34+
* @property {string} [description]
35+
* Short description of the channel (example: `Album Reviews`).
36+
* You *should* define this.
37+
* @property {string} [lang]
38+
* BCP 47 language tag representing the language of the whole channel (example:
39+
* `'fr-BE'`).
40+
* You *should* define this.
41+
* @property {string|Author} [author] Optional author of the whole channel.
42+
* Either `string`, in which case it’s as passing `{name: string}`.
43+
* Or an author object.
44+
* @property {Array<string>} [tags] Categories of the channel (example:
45+
* `['JavaScript', 'React']`).
2046
*
21-
* @typedef Entry Data on a single item.
22-
* @property {string} [title] Title of the item (example: `'Playboi Carti: Whole Lotta Red'`). Either `title`, `description`, or `descriptionHtml` must be set.
23-
* @property {string} [description] Either the whole post or an excerpt of it (example: `'Lorem'`). Should be plain text. `descriptionHtml` is preferred over plain text `description`. Either `title`, `description`, or `descriptionHtml` must be set.
24-
* @property {string} [descriptionHtml] Either the whole post or an excerpt of it (example: `'<p>Lorem</p>'`). Should be serialized HTML. `descriptionHtml` is preferred over plain text `description`. Either `title`, `description`, or `descriptionHtml` must be set.
25-
* @property {string|Author} [author] Entry version of `channel.author`. You *should* define this. For `atom`, it is required to either set `channel.author` or set `author` on all entries.
26-
* @property {string} [url] Full URL of this entry on the *site* (example: `'https://pitchfork.com/reviews/albums/roberta-flack-first-take'`).
27-
* @property {Date|number|string} [published] When the entry was first published (`Date` or value for `new Date(x)`, optional).
28-
* @property {Date|number|string} [modified] When the entry was last modified (`Date` or value for `new Date(x)`, optional).
29-
* @property {Array<string>} [tags] Categories of the entry (`Array<string>?`, example: `['laravel', 'debugging']`).
30-
* @property {Enclosure} [enclosure] Attached media
47+
* @typedef Entry
48+
* Data on a single item.
49+
* @property {string} [title]
50+
* Title of the item (example: `'Playboi Carti: Whole Lotta Red'`).
51+
* Either `title`, `description`, or `descriptionHtml` must be set.
52+
* @property {string} [description]
53+
* Either the whole post or an excerpt of it (example: `'Lorem'`).
54+
* Should be plain text.
55+
* `descriptionHtml` is preferred over plain text `description`.
56+
* Either `title`, `description`, or `descriptionHtml` must be set.
57+
* @property {string} [descriptionHtml]
58+
* Either the whole post or an excerpt of it (example: `'<p>Lorem</p>'`).
59+
* Should be serialized HTML.
60+
* `descriptionHtml` is preferred over plain text `description`.
61+
* Either `title`, `description`, or `descriptionHtml` must be set.
62+
* @property {string|Author} [author]
63+
* Entry version of `channel.author`.
64+
* You *should* define this.
65+
* For `atom`, it is required to either set `channel.author` or set `author`
66+
* on all entries.
67+
* @property {string} [url]
68+
* Full URL of this entry on the *site* (example:
69+
* `'https://pitchfork.com/reviews/albums/roberta-flack-first-take'`).
70+
* @property {Date|number|string} [published]
71+
* When the entry was first published (`Date` or value for `new Date(x)`,
72+
* optional).
73+
* @property {Date|number|string} [modified]
74+
* When the entry was last modified (`Date` or value for `new Date(x)`,
75+
* optional).
76+
* @property {Array<string>} [tags]
77+
* Categories of the entry (`Array<string>?`, example:
78+
* `['laravel', 'debugging']`).
79+
* @property {Enclosure} [enclosure]
80+
* Attached media.
3181
*/
3282

3383
export {}

0 commit comments

Comments
 (0)