kenchris / urlpattern-polyfill

URLPattern polyfill
https://www.npmjs.com/package/urlpattern-polyfill
MIT License
267 stars 30 forks source link

use conditional loading? #115

Closed jimmywarting closed 1 year ago

jimmywarting commented 1 year ago

looking at the source i found this:

import { URLPattern } from "./dist/urlpattern.js";

export { URLPattern };

if (!globalThis.URLPattern) {
  globalThis.URLPattern = URLPattern;
}
globalThis.URLPattern ??= await import('./dist/urlpattern.js')
export { URLPattern }
globalThis.URLPattern ??= require('./dist/urlpattern.cjs')
export { URLPattern }

??= maybe is to new-ish but you get my point... you could use top level await to conditionally load URLPattern if needed.

jimmywarting commented 1 year ago

nvm, getting ahead of myself. i look at the source code before i read the README 😅