| 31 | |
| 32 | // Convert a date string to ISO 8601 when parseable, otherwise return the raw value |
| 33 | const toIso = (raw) => { |
| 34 | if (!raw || typeof raw !== 'string') return raw; |
| 35 | const trimmed = raw.trim().replace(/\s*#.*$/, ''); |
| 36 | const t = Date.parse(trimmed); |
| 37 | if (!Number.isNaN(t)) return new Date(t).toISOString(); |
| 38 | const m = trimmed.match(/^(\d{4})(\d{2})(\d{2})$/); |
| 39 | if (m) return new Date(`${m[1]}-${m[2]}-${m[3]}T00:00:00Z`).toISOString(); |
| 40 | return raw; |
| 41 | }; |
| 42 | |
| 43 | // Reduce a hostname to its registrable domain so registry WHOIS lookups succeed |
| 44 | const baseDomain = (host) => psl.parse(host)?.domain || host; |