11export const doc = document
22
3- export const win = window
3+ export const win = globalThis
44
55export const uniq = ( array ) => [ ...new Set ( array ) ]
66
@@ -19,7 +19,7 @@ export const toCamelCase = function (text) {
1919}
2020
2121export const $ = ( selectors , element ) =>
22- ( element || doc ) . querySelector ( selectors )
22+ ( element || doc ) . querySelector ( selectors ) || undefined
2323export const $$ = ( selectors , element ) => [
2424 ...( element || doc ) . querySelectorAll ( selectors ) ,
2525]
@@ -30,8 +30,8 @@ export const getRootElement = (type) =>
3030 type === 1
3131 ? doc . head || doc . body || doc . documentElement
3232 : type === 2
33- ? doc . body || doc . documentElement
34- : doc . documentElement
33+ ? doc . body || doc . documentElement
34+ : doc . documentElement
3535
3636export const createElement = ( tagName , attributes ) =>
3737 setAttributes ( doc . createElement ( tagName ) , attributes )
@@ -102,7 +102,7 @@ export const removeEventListener = (element, type, listener, options) => {
102102}
103103
104104export const getAttribute = ( element , name ) =>
105- element && element . getAttribute ? element . getAttribute ( name ) : null
105+ element && element . getAttribute ? element . getAttribute ( name ) : undefined
106106export const setAttribute = ( element , name , value ) =>
107107 element && element . setAttribute
108108 ? element . setAttribute ( name , value )
@@ -274,6 +274,7 @@ export const throttle = (func, interval) => {
274274// Polyfill for Object.hasOwn()
275275if ( typeof Object . hasOwn !== "function" ) {
276276 Object . hasOwn = ( instance , prop ) =>
277+ // eslint-disable-next-line prefer-object-has-own
277278 Object . prototype . hasOwnProperty . call ( instance , prop )
278279}
279280
@@ -287,19 +288,19 @@ export const extendHistoryApi = () => {
287288 history . pushState = function ( ) {
288289 // eslint-disable-next-line prefer-rest-params
289290 pushState . apply ( history , arguments )
290- window . dispatchEvent ( new Event ( "pushstate" ) )
291- window . dispatchEvent ( new Event ( "locationchange" ) )
291+ globalThis . dispatchEvent ( new Event ( "pushstate" ) )
292+ globalThis . dispatchEvent ( new Event ( "locationchange" ) )
292293 }
293294
294295 history . replaceState = function ( ) {
295296 // eslint-disable-next-line prefer-rest-params
296297 replaceState . apply ( history , arguments )
297- window . dispatchEvent ( new Event ( "replacestate" ) )
298- window . dispatchEvent ( new Event ( "locationchange" ) )
298+ globalThis . dispatchEvent ( new Event ( "replacestate" ) )
299+ globalThis . dispatchEvent ( new Event ( "locationchange" ) )
299300 }
300301
301- window . addEventListener ( "popstate" , function ( ) {
302- window . dispatchEvent ( new Event ( "locationchange" ) )
302+ globalThis . addEventListener ( "popstate" , function ( ) {
303+ globalThis . dispatchEvent ( new Event ( "locationchange" ) )
303304 } )
304305
305306 // Usage example:
0 commit comments