Project

General

Profile

Download (1.19 KB) Statistics
| Branch: | Tag: | Revision:
1
/***
2
**
3
** Polyfill for older browsers that don't yet have the newer string "includes()" method implemented.
4
** Source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes?#Polyfill
5
** Documentation: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes
6
**
7
***/
8

    
9
if (!String.prototype.includes) {
10
	String.prototype.includes = function(search, start) {
11
		'use strict';
12
		if (typeof start !== 'number') {
13
			start = 0;
14
		}
15

    
16
		if (start + search.length > this.length) {
17
			return false;
18
		} else {
19
			return this.indexOf(search, start) !== -1;
20
		}
21
	};
22
}
23

    
24
/***
25
** 
26
** Polyfill for older browsers that don't yet have the newer string "startsWith()" method implemented.
27
** Source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith#Polyfill
28
** Documentation: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith
29
** 
30
***/
31

    
32
if (!String.prototype.startsWith) {
33
    String.prototype.startsWith = function(searchString, position){
34
      position = position || 0;
35
      return this.substr(position, searchString.length) === searchString;
36
  };
37
}
(3-3/3)