Skip to content

Commit 9d61011

Browse files
committed
Refactor code-style
* Add more docs to JSDoc * Add support for `null` in input of API types
1 parent 8a6de7f commit 9d61011

File tree

5 files changed

+33
-23
lines changed

5 files changed

+33
-23
lines changed

lib/atom.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ import {toAuthor, toDate} from './util.js'
1414

1515
/**
1616
* Build an Atom feed.
17+
*
1718
* Same API as `rss` otherwise.
1819
*
1920
* @param {Channel} channel
2021
* Data on the feed (the group of items).
21-
* @param {Array<Entry>} [data]
22+
* @param {Array<Entry> | null | undefined} [data]
2223
* List of entries.
2324
* @returns {Root}
2425
* Atom feed.

lib/rss.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ import {toAuthor, toDate} from './util.js'
1313

1414
/**
1515
* Build an RSS feed.
16+
*
1617
* Same API as `atom` otherwise.
1718
*
1819
* @param {Channel} channel
1920
* Data on the feed (the group of items).
20-
* @param {Array<Entry>} [data]
21+
* @param {Array<Entry> | null | undefined} [data]
2122
* List of entries.
2223
* @returns {Root}
2324
* RSS feed.
@@ -26,8 +27,8 @@ export function rss(channel, data) {
2627
const now = new Date()
2728
/** @type {Channel} */
2829
const meta = channel || {title: null, url: null}
29-
/** @type {boolean|undefined} */
30-
let atom
30+
/** @type {boolean} */
31+
let atom = false
3132

3233
if (meta.title === undefined || meta.title === null) {
3334
throw new Error('Expected `channel.title` to be set')

lib/types.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
* An author object
44
* @property {string} name
55
* Example: `'Acme, Inc.'` or `'Jane Doe'`
6-
* @property {string|undefined} [email]
6+
* @property {string | null | undefined} [email]
77
* Example: `john@example.org`
8-
* @property {string|undefined} [url]
8+
* @property {string | null | undefined} [url]
99
* Example: `'https://example.org/john'`.
1010
* `url` is used in `atom`, not in `rss`.
1111
*
@@ -26,57 +26,57 @@
2626
* @property {string} url
2727
* Full URL to the site (required, example:
2828
* `'https://www.theguardian.com/world/zimbabwe'`).
29-
* @property {string|undefined} [feedUrl]
29+
* @property {string | null | undefined} [feedUrl]
3030
* Full URL to this channel (example:
3131
* `'https://www.adweek.com/feed/'`).
3232
* Make sure to pass different ones to `rss` and `atom`!
3333
* You *should* define this.
34-
* @property {string|undefined} [description]
34+
* @property {string | null | undefined} [description]
3535
* Short description of the channel (example: `Album Reviews`).
3636
* You *should* define this.
37-
* @property {string|undefined} [lang]
37+
* @property {string | null | undefined} [lang]
3838
* BCP 47 language tag representing the language of the whole channel (example:
3939
* `'fr-BE'`).
4040
* You *should* define this.
41-
* @property {string|Author|undefined} [author] Optional author of the whole channel.
41+
* @property {string | Author | null | undefined} [author] Optional author of the whole channel.
4242
* Either `string`, in which case it’s as passing `{name: string}`.
4343
* Or an author object.
44-
* @property {Array<string>|undefined} [tags] Categories of the channel (example:
44+
* @property {Array<string> | null | undefined} [tags] Categories of the channel (example:
4545
* `['JavaScript', 'React']`).
4646
*
4747
* @typedef Entry
4848
* Data on a single item.
49-
* @property {string|undefined} [title]
49+
* @property {string | null | undefined} [title]
5050
* Title of the item (example: `'Playboi Carti: Whole Lotta Red'`).
5151
* Either `title`, `description`, or `descriptionHtml` must be set.
52-
* @property {string|undefined} [description]
52+
* @property {string | null | undefined} [description]
5353
* Either the whole post or an excerpt of it (example: `'Lorem'`).
5454
* Should be plain text.
5555
* `descriptionHtml` is preferred over plain text `description`.
5656
* Either `title`, `description`, or `descriptionHtml` must be set.
57-
* @property {string|undefined} [descriptionHtml]
57+
* @property {string | null | undefined} [descriptionHtml]
5858
* Either the whole post or an excerpt of it (example: `'<p>Lorem</p>'`).
5959
* Should be serialized HTML.
6060
* `descriptionHtml` is preferred over plain text `description`.
6161
* Either `title`, `description`, or `descriptionHtml` must be set.
62-
* @property {string|Author|undefined} [author]
62+
* @property {string | Author | null | undefined} [author]
6363
* Entry version of `channel.author`.
6464
* You *should* define this.
6565
* For `atom`, it is required to either set `channel.author` or set `author`
6666
* on all entries.
67-
* @property {string|undefined} [url]
67+
* @property {string | null | undefined} [url]
6868
* Full URL of this entry on the *site* (example:
6969
* `'https://pitchfork.com/reviews/albums/roberta-flack-first-take'`).
70-
* @property {Date|number|string|undefined} [published]
70+
* @property {Date | number | string | null | undefined} [published]
7171
* When the entry was first published (`Date` or value for `new Date(x)`,
7272
* optional).
73-
* @property {Date|number|string|undefined} [modified]
73+
* @property {Date | number | string | null | undefined} [modified]
7474
* When the entry was last modified (`Date` or value for `new Date(x)`,
7575
* optional).
76-
* @property {Array<string>|undefined} [tags]
76+
* @property {Array<string> | null | undefined} [tags]
7777
* Categories of the entry (`Array<string>?`, example:
7878
* `['laravel', 'debugging']`).
79-
* @property {Enclosure|undefined} [enclosure]
79+
* @property {Enclosure | null | undefined} [enclosure]
8080
* Attached media.
8181
*/
8282

lib/util.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
*/
44

55
/**
6-
* @param {Author|string} value
6+
* Create an author object.
7+
*
8+
* @param {Author | string} value
9+
* Author or string.
710
* @returns {Author}
11+
* Valid author.
812
*/
913
export function toAuthor(value) {
1014
if (typeof value === 'string') {
@@ -19,8 +23,12 @@ export function toAuthor(value) {
1923
}
2024

2125
/**
22-
* @param {Date|string|number} value
26+
* Create a date object.
27+
*
28+
* @param {Date | string | number} value
29+
* Serialized date, numeric date, actual date.
2330
* @returns {Date}
31+
* Valid date.
2432
*/
2533
export function toDate(value) {
2634
/* c8 ignore next */

test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {atom, rss} from './index.js'
55
const ODate = global.Date
66

77
// @ts-expect-error
8-
global.Date = function (/** @type {string|number} */ value) {
8+
global.Date = function (/** @type {string | number} */ value) {
99
return new ODate(value || 1_234_567_890_123)
1010
}
1111

0 commit comments

Comments
 (0)