forked from javascript-tutorial/server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring.js
More file actions
executable file
·22 lines (19 loc) · 789 Bytes
/
string.js
File metadata and controls
executable file
·22 lines (19 loc) · 789 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
if (!String.prototype.startsWith) {
String.prototype.startsWith = function(string) {
let index = arguments.length < 2 ? 0 : arguments[1];
return this.slice(index).indexOf(string) === 0;
};
}
if (!String.prototype.endsWith) {
String.prototype.endsWith = function(string) {
let index = arguments.length < 2 ? this.length : arguments[1];
let foundIndex = this.lastIndexOf(string);
return foundIndex !== -1 && foundIndex === index - string.length;
};
}
if (!String.prototype.includes) {
String.prototype.includes = function(string, index) {
if (typeof string === 'object' && string instanceof RegExp) throw new TypeError("First argument to String.prototype.includes must not be a regular expression");
return this.indexOf(string, index) !== -1;
};
}