cocos-enhance-kit/engine/polyfill/string.js

24 lines
743 B
JavaScript
Raw Normal View History

2022-06-24 16:23:03 +00:00
if (!String.prototype.startsWith) {
String.prototype.startsWith = function (searchString, position) {
position = position || 0;
return this.lastIndexOf(searchString, position) === position;
};
}
if (!String.prototype.endsWith) {
String.prototype.endsWith = function (searchString, position) {
if (typeof position === 'undefined' || position > this.length) {
position = this.length;
}
position -= searchString.length;
var lastIndex = this.indexOf(searchString, position);
return lastIndex !== -1 && lastIndex === position;
};
}
if (!String.prototype.trimLeft) {
String.prototype.trimLeft = function () {
return this.replace(/^\s+/, '');
};
}