1 | "use strict";
|
2 |
|
3 | if (!String.prototype.startsWith) {
|
4 | var toString = {}.toString;
|
5 | String.prototype.startsWith = function (search){
|
6 | if (this === null) {
|
7 | throw new TypeError();
|
8 | }
|
9 | var string = String(this);
|
10 | if (search && toString.call(search) === "[object RegExp]") {
|
11 | throw new TypeError();
|
12 | }
|
13 | var stringLength = string.length;
|
14 | var searchString = String(search);
|
15 | var searchLength = searchString.length;
|
16 | var position = arguments.length > 1 ? arguments[1] : undefined;
|
17 |
|
18 | var pos = position ? Number(position) : 0;
|
19 | if (pos !== pos) {
|
20 | pos = 0;
|
21 | }
|
22 | var start = Math.min(Math.max(pos, 0), stringLength);
|
23 |
|
24 | if (searchLength + start > stringLength) {
|
25 | return false;
|
26 | }
|
27 | var index = -1;
|
28 | while (++index < searchLength) {
|
29 | if (string.charCodeAt(start + index) !== searchString.charCodeAt(index)) {
|
30 | return false;
|
31 | }
|
32 | }
|
33 | return true;
|
34 | };
|
35 | }
|