Skip to content

Commit

Permalink
Ensure HTMLElement exists in all contexts
Browse files Browse the repository at this point in the history
When requiring this module in NodeJS, it will error as `HTMLElement`
does not exist. Creating a variable defaulting to `null` allows the
class to be created in the server without causing errors. This is useful
for introspecting the class within NodeJS.
  • Loading branch information
keithamus committed Nov 23, 2022
1 parent 11b35f5 commit b604b5c
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/relative-time-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import {DateTimeFormat as DateTimeFormatPonyFill} from './datetimeformat-ponyfil
import {RelativeTimeFormat as RelativeTimeFormatPonyfill} from './relative-time-ponyfill.js'
import {isDuration, withinDuration} from './duration.js'
import {strftime} from './strftime.js'
const root = (typeof globalThis !== 'undefined' ? globalThis : window) as typeof window
const HTMLElement = root.HTMLElement || (null as unknown as typeof window['HTMLElement'])

const supportsIntlDatetime = typeof Intl !== 'undefined' && 'DateTimeFormat' in Intl
const DateTimeFormat = supportsIntlDatetime ? Intl.DateTimeFormat : DateTimeFormatPonyFill
Expand Down

0 comments on commit b604b5c

Please sign in to comment.