Skip to content

Instantly share code, notes, and snippets.

@developit
Last active November 15, 2020 21:19
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save developit/e96097d9b657f2a2f3e588ffde433437 to your computer and use it in GitHub Desktop.
Save developit/e96097d9b657f2a2f3e588ffde433437 to your computer and use it in GitHub Desktop.
polyfill ES2018 standard library stuff for ES Modules supporting browsers (Edge 16+, Firefox 60+, Chrome 61+, Safari 10.1+)
if (!('trimStart' in String.prototype)) String.prototype.trimStart = String.prototype.trimLeft;
if (!('trimEnd' in String.prototype)) String.prototype.trimEnd = String.prototype.trimRight;
if (!('forEach' in NodeList.prototype)) NodeList.prototype.forEach = [].forEach;
if (!('description' in Symbol.prototype)) {
Object.defineProperty(Symbol.prototype, 'description', {
get() { return /\((.+)\)/.exec(this)[1] }
});
}
if (!('finally' in Promise.prototype)) {
Promise.prototype.finally = function(t){if("function"!=typeof t)return this.then(t,t);const e=this.constructor||Promise;return this.then(o=>e.resolve(t()).then(()=>o),o=>e.resolve(t()).then(()=>{throw o}))});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment