Skip to content

Commit

Permalink
Add strict to tsconfig.json
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Jul 24, 2021
1 parent 5c6975f commit 7fb8891
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 91 deletions.
45 changes: 16 additions & 29 deletions lib/atom.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,6 @@ export function atom(channel, data) {
const now = new Date()
/** @type {Channel} */
const meta = channel || {title: null, url: null}
/** @type {Array.<Element>} */
const items = []
let index = -1
/** @type {number} */
let offset
/** @type {Array.<Element>} */
let children
/** @type {Entry} */
let datum
/** @type {string} */
let url
/** @type {Author} */
let author
/** @type {Enclosure} */
let enclosure

if (meta.title === undefined || meta.title === null) {
throw new Error('Expected `channel.title` to be set')
Expand All @@ -49,17 +34,16 @@ export function atom(channel, data) {
throw new Error('Expected `channel.url` to be set')
}

url = new URL(meta.url).href

items.push(
const url = new URL(meta.url).href
const items = [
x('title', String(meta.title)),
x('subtitle', String(meta.description || '') || null),
// `rel: 'alternate'` is the default.
x('link', url),
x('id', url),
// @ts-ignore `toGTMString` is exactly what we need.
// @ts-expect-error `toGTMString` is exactly what we need.
x('updated', now.toGMTString())
)
]

if (meta.feedUrl) {
items.push(
Expand All @@ -72,24 +56,27 @@ export function atom(channel, data) {
}

if (meta.author) {
author = toAuthor(meta.author)
const author = toAuthor(meta.author)
items.push(
x('rights', '© ' + now.getUTCFullYear() + ' ' + author.name),
createAuthor(author)
)
}

if (meta.tags) {
offset = -1
while (++offset < meta.tags.length) {
items.push(x('category', {term: String(meta.tags[offset])}))
let index = -1
while (++index < meta.tags.length) {
items.push(x('category', {term: String(meta.tags[index])}))
}
}

if (data) {
let index = -1

while (++index < data.length) {
datum = data[index]
children = []
const datum = data[index]
/** @type {Array.<Element>} */
const children = []

if (!datum.title && !datum.description && !datum.descriptionHtml) {
throw new Error(
Expand All @@ -112,7 +99,7 @@ export function atom(channel, data) {
}

if (datum.url) {
url = new URL(datum.url).href
const url = new URL(datum.url).href
children.push(x('link', {href: url}), x('id', url))
}

Expand All @@ -125,13 +112,13 @@ export function atom(channel, data) {
}

if (datum.tags) {
offset = -1
let offset = -1
while (++offset < datum.tags.length) {
items.push(x('category', {term: String(datum.tags[offset])}))
}
}

enclosure = datum.enclosure
const enclosure = datum.enclosure

if (enclosure) {
if (!enclosure.url) {
Expand Down
54 changes: 19 additions & 35 deletions lib/rss.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,8 @@ export function rss(channel, data) {
const now = new Date()
/** @type {Channel} */
const meta = channel || {title: null, url: null}
/** @type {Array.<Element>} */
const items = []
let index = -1
/** @type {boolean} */
/** @type {boolean|undefined} */
let atom
/** @type {number} */
let offset
/** @type {Array.<Element>} */
let children
/** @type {Entry} */
let datum
/** @type {string} */
let lang
/** @type {string} */
let copy
/** @type {string} */
let url
/** @type {Author} */
let author
/** @type {Enclosure} */
let enclosure

if (meta.title === undefined || meta.title === null) {
throw new Error('Expected `channel.title` to be set')
Expand All @@ -55,14 +36,14 @@ export function rss(channel, data) {
throw new Error('Expected `channel.url` to be set')
}

items.push(
const items = [
x('title', String(meta.title)),
x('description', String(meta.description || '') || null),
x('link', new URL(meta.url).href),
// @ts-ignore `toGTMString` is exactly what we need.
// @ts-expect-error `toGTMString` is exactly what we need.
x('lastBuildDate', now.toGMTString()),
x('dc:date', now.toISOString())
)
]

if (meta.feedUrl) {
atom = true
Expand All @@ -76,26 +57,28 @@ export function rss(channel, data) {
}

if (meta.lang) {
lang = normalize(meta.lang)
const lang = normalize(meta.lang)
items.push(x('language', lang), x('dc:language', lang))
}

if (meta.author) {
copy = '© ' + now.getUTCFullYear() + ' ' + meta.author
const copy = '© ' + now.getUTCFullYear() + ' ' + meta.author
items.push(x('copyright', copy), x('dc:rights', copy))
}

if (meta.tags) {
offset = -1
while (++offset < meta.tags.length) {
items.push(x('category', String(meta.tags[offset])))
let index = -1
while (++index < meta.tags.length) {
items.push(x('category', String(meta.tags[index])))
}
}

if (data) {
let index = -1
while (++index < data.length) {
datum = data[index]
children = []
const datum = data[index]
/** @type {Array.<Element>} */
const children = []

if (!datum.title && !datum.description && !datum.descriptionHtml) {
throw new Error(
Expand All @@ -108,7 +91,7 @@ export function rss(channel, data) {
if (datum.title) children.push(x('title', String(datum.title)))

if (datum.author) {
author = toAuthor(datum.author)
const author = toAuthor(datum.author)
children.push(x('dc:creator', author.name))

if (author.email) {
Expand All @@ -117,7 +100,7 @@ export function rss(channel, data) {
}

if (datum.url) {
url = new URL(datum.url).href
const url = new URL(datum.url).href
children.push(
x('link', url),
// Do not treat it as a URL, just an opaque identifier.
Expand All @@ -130,7 +113,7 @@ export function rss(channel, data) {

if (datum.published !== undefined && datum.published !== null) {
children.push(
// @ts-ignore `toGTMString` is exactly what we need.
// @ts-expect-error `toGTMString` is exactly what we need.
x('pubDate', toDate(datum.published).toGMTString()),
x('dc:date', toDate(datum.published).toISOString())
)
Expand All @@ -141,13 +124,14 @@ export function rss(channel, data) {
}

if (datum.tags) {
offset = -1
let offset = -1
while (++offset < datum.tags.length) {
children.push(x('category', String(datum.tags[offset])))
}
}

enclosure = datum.enclosure
const enclosure = datum.enclosure

if (enclosure) {
if (!enclosure.url) {
throw new Error(
Expand Down
Loading

0 comments on commit 7fb8891

Please sign in to comment.