1
+ /* eslint-disable max-depth */
2
+
1
3
/**
2
- * @typedef {import('xast').Root } Root
3
4
* @typedef {import('xast').Element } Element
5
+ * @typedef {import('xast').Root } Root
4
6
*/
5
7
6
8
/**
7
- * @typedef {string | Omit<Entry, 'lang ' | 'alternate'> } Alternate
9
+ * @typedef {Omit<Entry, 'alternate ' | 'lang'> | string } Alternate
8
10
* Alternative content, typically a translation.
9
11
*
10
12
* To define different fields, either use a full entry object:
45
47
* Entries represent a single URL and describe them with metadata.
46
48
* @property {string } url
47
49
* 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) .
50
52
* @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).
52
55
* @property {Record<string, Alternate> | null | undefined } [alternate]
53
56
* 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 ).
55
58
*
56
59
* Alternate resources inherit fields from the entry they are described in.
57
60
*/
@@ -66,11 +69,12 @@ const own = {}.hasOwnProperty
66
69
/**
67
70
* Build a sitemap.
68
71
*
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) .
71
74
* @returns {Root }
72
75
* Sitemap.
73
76
*/
77
+ // eslint-disable-next-line complexity
74
78
export function sitemap ( data ) {
75
79
/** @type {Array<Element> } */
76
80
const nodes = [ ]
@@ -166,7 +170,7 @@ export function sitemap(data) {
166
170
167
171
nodes . push ( node )
168
172
169
- if ( entry . modified !== undefined && entry . modified !== null ) {
173
+ if ( entry . modified !== null && entry . modified !== undefined ) {
170
174
const modified = toDate ( entry . modified )
171
175
172
176
if ( Number . isNaN ( modified . valueOf ( ) ) ) {
@@ -209,7 +213,7 @@ export function sitemap(data) {
209
213
}
210
214
211
215
/**
212
- * @param {string | Entry } d
216
+ * @param {Entry | string } d
213
217
*/
214
218
function toEntry ( d ) {
215
219
/** @type {Entry } */
@@ -221,10 +225,15 @@ function toEntry(d) {
221
225
url = d
222
226
} else {
223
227
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 )
226
234
entry . modified = d . modified
227
- if ( d . alternate !== undefined && d . alternate !== null )
235
+
236
+ if ( d . alternate !== null && d . alternate !== undefined )
228
237
entry . alternate = d . alternate
229
238
}
230
239
@@ -233,7 +242,7 @@ function toEntry(d) {
233
242
}
234
243
235
244
/**
236
- * @param {Date | string | number } value
245
+ * @param {Date | number | string } value
237
246
* @returns {Date }
238
247
*/
239
248
export function toDate ( value ) {
0 commit comments