parent
89a72a50cf
commit
feda4a9b67
@ -1,33 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
define(
|
||||
[
|
||||
], function () {
|
||||
|
||||
return {
|
||||
|
||||
startsWith: function (str, starts) {
|
||||
if (starts === '') {
|
||||
return true;
|
||||
}
|
||||
if (str == null || starts == null) {
|
||||
return false;
|
||||
}
|
||||
str = String(str);
|
||||
starts = String(starts);
|
||||
return str.length >= starts.length && str.slice(0, starts.length) === starts;
|
||||
},
|
||||
|
||||
endsWith: function (str, ends) {
|
||||
if (ends === '') {
|
||||
return true;
|
||||
}
|
||||
if (str == null || ends == null) {
|
||||
return false;
|
||||
}
|
||||
str = String(str);
|
||||
ends = String(ends);
|
||||
return str.length >= ends.length && str.slice(str.length - ends.length) === ends;
|
||||
}
|
||||
}
|
||||
});
|
@ -0,0 +1,32 @@
|
||||
if (!String.prototype.startsWith) {
|
||||
Object.defineProperty(String.prototype, 'startsWith', {
|
||||
enumerable: false,
|
||||
configurable: false,
|
||||
writable: false,
|
||||
value: function (searchString, position) {
|
||||
position = position || 0;
|
||||
return this.indexOf(searchString, position) === position;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (!String.prototype.endsWith) {
|
||||
Object.defineProperty(String.prototype, 'endsWith', {
|
||||
enumerable: false,
|
||||
configurable: false,
|
||||
writable: false,
|
||||
value: function (searchString, position) {
|
||||
position = position || this.length;
|
||||
position = position - searchString.length;
|
||||
var lastIndex = this.lastIndexOf(searchString);
|
||||
return lastIndex !== -1 && lastIndex === position;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if(!('contains' in String.prototype))
|
||||
{
|
||||
String.prototype.contains = function(str, startIndex) {
|
||||
return -1 !== String.prototype.indexOf.call(this, str, startIndex);
|
||||
};
|
||||
}
|
Loading…
Reference in new issue