Skip to content

Commit 277f50a

Browse files
committed
add polyfill for String.includes
1 parent e2031b1 commit 277f50a

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
export function initialize() {
2+
3+
// Source: https://developer.mozilla.org/cs/docs/Web/JavaScript/Reference/Global_Objects/String/includes#Polyfill
4+
if (!String.prototype.includes) {
5+
String.prototype.includes = function(search, start) {
6+
'use strict';
7+
if (typeof start !== 'number') {
8+
start = 0;
9+
}
10+
11+
if (start + search.length > this.length) {
12+
return false;
13+
} else {
14+
return this.indexOf(search, start) !== -1;
15+
}
16+
};
17+
}
18+
}
19+
20+
export default {
21+
name: 'add-string-includes-polyfill',
22+
initialize
23+
};

0 commit comments

Comments
 (0)