From b4263aa3ecf41a857111d08c56fcfcb8b58cba46 Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Mon, 26 Jun 2017 15:50:08 +0200 Subject: [PATCH] =?UTF-8?q?New:=20Make=20sure=20we=20can=20use=20String=20?= =?UTF-8?q?function=20=E2=80=99startsWith=E2=80=99=20and=20=E2=80=99endsWi?= =?UTF-8?q?th=E2=80=99=20even=20if=20an=20older=20browser=20or=20Javascrip?= =?UTF-8?q?t=20engine=20is=20used.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Objective-J/OldBrowserCompatibility.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Objective-J/OldBrowserCompatibility.js b/Objective-J/OldBrowserCompatibility.js index cd3d30517..d4e43b937 100644 --- a/Objective-J/OldBrowserCompatibility.js +++ b/Objective-J/OldBrowserCompatibility.js @@ -115,3 +115,24 @@ if (!Array.prototype.indexOf) return -1; }; } + +// ECMAScript 6 has added this. It is copied from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String +if (!String.prototype.startsWith) { + String.prototype.startsWith = function(searchString, position){ + position = position || 0; + return this.substr(position, searchString.length) === searchString; + }; +} + +// ECMAScript 6 has added this. It is copied from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String +if (!String.prototype.endsWith) { + String.prototype.endsWith = function(searchString, position) { + var subjectString = this.toString(); + if (typeof position !== 'number' || !isFinite(position) || Math.floor(position) !== position || position > subjectString.length) { + position = subjectString.length; + } + position -= searchString.length; + var lastIndex = subjectString.indexOf(searchString, position); + return lastIndex !== -1 && lastIndex === position; + }; +}; \ No newline at end of file