1 | 'use strict';
|
---|
2 | var $ = require('../internals/export');
|
---|
3 | var getOwnPropertyDescriptor = require('../internals/object-get-own-property-descriptor').f;
|
---|
4 | var toLength = require('../internals/to-length');
|
---|
5 | var toString = require('../internals/to-string');
|
---|
6 | var notARegExp = require('../internals/not-a-regexp');
|
---|
7 | var requireObjectCoercible = require('../internals/require-object-coercible');
|
---|
8 | var correctIsRegExpLogic = require('../internals/correct-is-regexp-logic');
|
---|
9 | var IS_PURE = require('../internals/is-pure');
|
---|
10 |
|
---|
11 | // eslint-disable-next-line es/no-string-prototype-startswith -- safe
|
---|
12 | var $startsWith = ''.startsWith;
|
---|
13 | var min = Math.min;
|
---|
14 |
|
---|
15 | var CORRECT_IS_REGEXP_LOGIC = correctIsRegExpLogic('startsWith');
|
---|
16 | // https://github.com/zloirock/core-js/pull/702
|
---|
17 | var MDN_POLYFILL_BUG = !IS_PURE && !CORRECT_IS_REGEXP_LOGIC && !!function () {
|
---|
18 | var descriptor = getOwnPropertyDescriptor(String.prototype, 'startsWith');
|
---|
19 | return descriptor && !descriptor.writable;
|
---|
20 | }();
|
---|
21 |
|
---|
22 | // `String.prototype.startsWith` method
|
---|
23 | // https://tc39.es/ecma262/#sec-string.prototype.startswith
|
---|
24 | $({ target: 'String', proto: true, forced: !MDN_POLYFILL_BUG && !CORRECT_IS_REGEXP_LOGIC }, {
|
---|
25 | startsWith: function startsWith(searchString /* , position = 0 */) {
|
---|
26 | var that = toString(requireObjectCoercible(this));
|
---|
27 | notARegExp(searchString);
|
---|
28 | var index = toLength(min(arguments.length > 1 ? arguments[1] : undefined, that.length));
|
---|
29 | var search = toString(searchString);
|
---|
30 | return $startsWith
|
---|
31 | ? $startsWith.call(that, search, index)
|
---|
32 | : that.slice(index, index + search.length) === search;
|
---|
33 | }
|
---|
34 | });
|
---|