-
Notifications
You must be signed in to change notification settings - Fork 1
/
dynamicpolyfill.min.js
1 lines (1 loc) · 1.91 KB
/
dynamicpolyfill.min.js
1
const pf="https://polyfill.io/v3/polyfill.min.js?features=";function dynamicPolyfill(a,b,d){if("undefined"!==typeof Promise||window.hasOwnProperty("Promise")){var c=[];Array.isArray(a)?a.forEach(function(a){c.push(checking(a))}):c.push(checking(a));c=c.filter(function(a){return void 0!==a}).join(",");loadPolyfill(c,b,d)}else promiFill(a,b,d)}function promiFill(a,b,d){var c=document.createElement("script");c.src=pf+"Promise";document.body.appendChild(c);c.onerror=function(a){console.error("Polyfilling Promise failed",a)};c.onload=function(){dynamicPolyfill(a,b,d)}}function checking(a){if(!0!==window.hasOwnProperty(a)||"function"!==typeof this.check!==!0||!0!==a in this)if(1<=a.indexOf(".")){var b=a.split("."),d="window"===b[0]?b[0]:window[b[0]];b=Object(b[b.length-1]);if(!0!==d.prototype.hasOwnProperty(b)&&!0!==d.hasOwnProperty(b)&&!0!==b in d)return a}else return a}function loadPolyfill(a,b,d){if(""!==a){var c=document.createElement("script");c.src=pf+encodeURIComponent(a);c.onerror=function(a){console.error("Loading the polyfill(s) failed!",a)};c.onload=function(){loadMyScript(b,d)};document.body.appendChild(c)}else loadMyScript(b,d)}function loadMyScript(a,b){if(Array.isArray(a)){var d=[];a.forEach(function(a){d.push(nonblankURL(a))});Promise.all(d).then(function(){initialiseMyScript(b)})["catch"](function(a){return a})}else Array.isArray(a)||null===a||""===a?initialiseMyScript(b):nonblankURL(a).then(function(){initialiseMyScript(b)})["catch"](function(a){return a})}function nonblankURL(a){return new Promise(function(b,d){var c=document.createElement("script");c.src=encodeURI(a);c.onerror=function(a){return d("Loading the script failed!",a)};c.onload=function(){return b(a)};document.body.appendChild(c)})}function initialiseMyScript(a){function b(a){try{(new Function(a))()}catch(c){console.error("There was an error: ",c,c.name,c.stack)}}Array.isArray(a)?a.forEach(function(a){b(a)}):b(a)};module.exports = dynamicPolyfill;