Skip to content

Commit 8ba1842

Browse files
committed
Refactor code-style
1 parent 09c8a19 commit 8ba1842

File tree

2 files changed

+807
-788
lines changed

2 files changed

+807
-788
lines changed

lib/index.js

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
/* eslint-disable max-depth */
2+
13
/**
2-
* @typedef {import('xast').Root} Root
34
* @typedef {import('xast').Element} Element
5+
* @typedef {import('xast').Root} Root
46
*/
57

68
/**
7-
* @typedef {string | Omit<Entry, 'lang' | 'alternate'>} Alternate
9+
* @typedef {Omit<Entry, 'alternate' | 'lang'> | string} Alternate
810
* Alternative content, typically a translation.
911
*
1012
* To define different fields, either use a full entry object:
@@ -45,13 +47,14 @@
4547
* Entries represent a single URL and describe them with metadata.
4648
* @property {string} url
4749
* Full URL (`<loc>`, example: `'https://example.org/'`).
48-
* @property {number | string | Date | null | undefined} [modified]
49-
* Value indicating when the page last changed (`<lastmod>`).
50+
* @property {Date | number | string | null | undefined} [modified]
51+
* Value indicating when the page last changed (`<lastmod>`) (optional).
5052
* @property {string | null | undefined} [lang]
51-
* BCP 47 tag indicating the language of the page (example: `'en-GB'`).
53+
* BCP 47 tag indicating the language of the page (example: `'en-GB'`,
54+
* optional).
5255
* @property {Record<string, Alternate> | null | undefined} [alternate]
5356
* Translations of the page, where each key is a BCP 47 tag and each value an
54-
* entry (example: `{nl: 'https://example.nl/'}`).
57+
* entry (example: `{nl: 'https://example.nl/'}`, optional).
5558
*
5659
* Alternate resources inherit fields from the entry they are described in.
5760
*/
@@ -66,11 +69,12 @@ const own = {}.hasOwnProperty
6669
/**
6770
* Build a sitemap.
6871
*
69-
* @param {Array<string | Entry> | null | undefined} [data]
70-
* Entries to build a sitemap for.
72+
* @param {Array<Entry | string> | null | undefined} [data]
73+
* Entries to build a sitemap for (optional).
7174
* @returns {Root}
7275
* Sitemap.
7376
*/
77+
// eslint-disable-next-line complexity
7478
export function sitemap(data) {
7579
/** @type {Array<Element>} */
7680
const nodes = []
@@ -166,7 +170,7 @@ export function sitemap(data) {
166170

167171
nodes.push(node)
168172

169-
if (entry.modified !== undefined && entry.modified !== null) {
173+
if (entry.modified !== null && entry.modified !== undefined) {
170174
const modified = toDate(entry.modified)
171175

172176
if (Number.isNaN(modified.valueOf())) {
@@ -209,7 +213,7 @@ export function sitemap(data) {
209213
}
210214

211215
/**
212-
* @param {string | Entry} d
216+
* @param {Entry | string} d
213217
*/
214218
function toEntry(d) {
215219
/** @type {Entry} */
@@ -221,10 +225,15 @@ function toEntry(d) {
221225
url = d
222226
} else {
223227
url = d.url
224-
if (d.lang !== undefined && d.lang !== null) entry.lang = normalize(d.lang)
225-
if (d.modified !== undefined && d.modified !== null)
228+
229+
if (d.lang !== null && d.lang !== undefined) {
230+
entry.lang = normalize(d.lang)
231+
}
232+
233+
if (d.modified !== null && d.modified !== undefined)
226234
entry.modified = d.modified
227-
if (d.alternate !== undefined && d.alternate !== null)
235+
236+
if (d.alternate !== null && d.alternate !== undefined)
228237
entry.alternate = d.alternate
229238
}
230239

@@ -233,7 +242,7 @@ function toEntry(d) {
233242
}
234243

235244
/**
236-
* @param {Date | string | number} value
245+
* @param {Date | number | string} value
237246
* @returns {Date}
238247
*/
239248
export function toDate(value) {

0 commit comments

Comments
 (0)