index.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. export function applyPolyfills() {
  2. var promises = [];
  3. if (typeof window !== 'undefined') {
  4. var win = window;
  5. if (!win.customElements ||
  6. (win.Element && (!win.Element.prototype.closest || !win.Element.prototype.matches || !win.Element.prototype.remove || !win.Element.prototype.getRootNode))) {
  7. promises.push(import(/* webpackChunkName: "polyfills-dom" */ './dom.js'));
  8. }
  9. var checkIfURLIsSupported = function() {
  10. try {
  11. var u = new URL('b', 'http://a');
  12. u.pathname = 'c%20d';
  13. return (u.href === 'http://a/c%20d') && u.searchParams;
  14. } catch (e) {
  15. return false;
  16. }
  17. };
  18. if (
  19. 'function' !== typeof Object.assign || !Object.entries ||
  20. !Array.prototype.find || !Array.prototype.includes ||
  21. !String.prototype.startsWith || !String.prototype.endsWith ||
  22. (win.NodeList && !win.NodeList.prototype.forEach) ||
  23. !win.fetch ||
  24. !checkIfURLIsSupported() ||
  25. typeof WeakMap == 'undefined'
  26. ) {
  27. promises.push(import(/* webpackChunkName: "polyfills-core-js" */ './core-js.js'));
  28. }
  29. }
  30. return Promise.all(promises);
  31. }