77 * @typedef {import('./types.js').Entry } Entry
88 */
99
10- import { URL } from 'url'
10+ import { URL } from 'node: url'
1111import { u } from 'unist-builder'
1212import { x } from 'xastscript'
1313import { bcp47Normalize as normalize } from 'bcp-47-normalize'
@@ -22,33 +22,38 @@ import {toAuthor, toDate} from './util.js'
2222 * @returns {Root }
2323 */
2424export function rss ( channel , data ) {
25- var now = new Date ( )
25+ const now = new Date ( )
2626 /** @type {Channel } */
27- var meta = channel || { title : null , url : null }
27+ const meta = channel || { title : null , url : null }
2828 /** @type {Array.<Element> } */
29- var items = [ ]
30- var index = - 1
29+ const items = [ ]
30+ let index = - 1
3131 /** @type {boolean } */
32- var atom
32+ let atom
3333 /** @type {number } */
34- var offset
34+ let offset
3535 /** @type {Array.<Element> } */
36- var children
36+ let children
3737 /** @type {Entry } */
38- var datum
38+ let datum
3939 /** @type {string } */
40- var lang
40+ let lang
4141 /** @type {string } */
42- var copy
42+ let copy
4343 /** @type {string } */
44- var url
44+ let url
4545 /** @type {Author } */
46- var author
46+ let author
4747 /** @type {Enclosure } */
48- var enclosure
48+ let enclosure
4949
50- if ( meta . title == null ) throw new Error ( 'Expected `channel.title` to be set' )
51- if ( meta . url == null ) throw new Error ( 'Expected `channel.url` to be set' )
50+ if ( meta . title === undefined || meta . title === null ) {
51+ throw new Error ( 'Expected `channel.title` to be set' )
52+ }
53+
54+ if ( meta . url === undefined || meta . url === null ) {
55+ throw new Error ( 'Expected `channel.url` to be set' )
56+ }
5257
5358 items . push (
5459 x ( 'title' , String ( meta . title ) ) ,
@@ -123,15 +128,15 @@ export function rss(channel, data) {
123128 )
124129 }
125130
126- if ( datum . published != null ) {
131+ if ( datum . published !== undefined && datum . published !== null ) {
127132 children . push (
128133 // @ts -ignore `toGTMString` is exactly what we need.
129134 x ( 'pubDate' , toDate ( datum . published ) . toGMTString ( ) ) ,
130135 x ( 'dc:date' , toDate ( datum . published ) . toISOString ( ) )
131136 )
132137 }
133138
134- if ( datum . modified != null ) {
139+ if ( datum . modified !== undefined && datum . modified !== null ) {
135140 children . push ( x ( 'dc:modified' , toDate ( datum . modified ) . toISOString ( ) ) )
136141 }
137142
0 commit comments