Restore native js functions: startsWith, endsWith, contains.
startsWith and endsWith implementation taken from MDN.
This commit is contained in:
@@ -17,6 +17,29 @@
|
|||||||
(function (Kotlin) {
|
(function (Kotlin) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
// Shims for String
|
||||||
|
if (typeof String.prototype.startsWith === "undefined") {
|
||||||
|
String.prototype.startsWith = function(searchString, position) {
|
||||||
|
position = position || 0;
|
||||||
|
return this.lastIndexOf(searchString, position) === position;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (typeof String.prototype.endsWith === "undefined") {
|
||||||
|
String.prototype.endsWith = function(searchString, position) {
|
||||||
|
var subjectString = this.toString();
|
||||||
|
if (position === undefined || position > subjectString.length) {
|
||||||
|
position = subjectString.length;
|
||||||
|
}
|
||||||
|
position -= searchString.length;
|
||||||
|
var lastIndex = subjectString.indexOf(searchString, position);
|
||||||
|
return lastIndex !== -1 && lastIndex === position;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
String.prototype.contains = function (s) {
|
||||||
|
return this.indexOf(s) !== -1;
|
||||||
|
};
|
||||||
|
|
||||||
// Kotlin stdlib
|
// Kotlin stdlib
|
||||||
|
|
||||||
Kotlin.equals = function (obj1, obj2) {
|
Kotlin.equals = function (obj1, obj2) {
|
||||||
|
|||||||
Reference in New Issue
Block a user