From 375bba3c3110b1da35a1ffe99f81a3bf109e2cc3 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Fri, 26 Oct 2018 23:10:03 +0100 Subject: [PATCH] FIX: Add `String.includes` polyfill for IE11 --- app/assets/javascripts/polyfills.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/assets/javascripts/polyfills.js b/app/assets/javascripts/polyfills.js index 71ced4c904e..93b18ae9ec0 100644 --- a/app/assets/javascripts/polyfills.js +++ b/app/assets/javascripts/polyfills.js @@ -94,4 +94,21 @@ if (!Array.prototype.includes) { } }); } + +// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes#Polyfill +if (!String.prototype.includes) { + Object.defineProperty(String.prototype, 'includes', { + value: function(search, start) { + if (typeof start !== 'number') { + start = 0 + } + + if (start + search.length > this.length) { + return false + } else { + return this.indexOf(search, start) !== -1 + } + } + }) +} /* eslint-enable */