cocos-enhance-kit/engine/polyfill/string.js
2022-06-25 00:23:03 +08:00

24 lines
743 B
JavaScript

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+/, '');
};
}