mirror of
https://github.com/idanoo/GoScrobble.git
synced 2024-11-25 09:55:15 +00:00
35 lines
1.5 KiB
JavaScript
35 lines
1.5 KiB
JavaScript
|
'use strict';
|
||
|
var $ = require('../internals/export');
|
||
|
var getOwnPropertyDescriptor = require('../internals/object-get-own-property-descriptor').f;
|
||
|
var toLength = require('../internals/to-length');
|
||
|
var toString = require('../internals/to-string');
|
||
|
var notARegExp = require('../internals/not-a-regexp');
|
||
|
var requireObjectCoercible = require('../internals/require-object-coercible');
|
||
|
var correctIsRegExpLogic = require('../internals/correct-is-regexp-logic');
|
||
|
var IS_PURE = require('../internals/is-pure');
|
||
|
|
||
|
// eslint-disable-next-line es/no-string-prototype-startswith -- safe
|
||
|
var $startsWith = ''.startsWith;
|
||
|
var min = Math.min;
|
||
|
|
||
|
var CORRECT_IS_REGEXP_LOGIC = correctIsRegExpLogic('startsWith');
|
||
|
// https://github.com/zloirock/core-js/pull/702
|
||
|
var MDN_POLYFILL_BUG = !IS_PURE && !CORRECT_IS_REGEXP_LOGIC && !!function () {
|
||
|
var descriptor = getOwnPropertyDescriptor(String.prototype, 'startsWith');
|
||
|
return descriptor && !descriptor.writable;
|
||
|
}();
|
||
|
|
||
|
// `String.prototype.startsWith` method
|
||
|
// https://tc39.es/ecma262/#sec-string.prototype.startswith
|
||
|
$({ target: 'String', proto: true, forced: !MDN_POLYFILL_BUG && !CORRECT_IS_REGEXP_LOGIC }, {
|
||
|
startsWith: function startsWith(searchString /* , position = 0 */) {
|
||
|
var that = toString(requireObjectCoercible(this));
|
||
|
notARegExp(searchString);
|
||
|
var index = toLength(min(arguments.length > 1 ? arguments[1] : undefined, that.length));
|
||
|
var search = toString(searchString);
|
||
|
return $startsWith
|
||
|
? $startsWith.call(that, search, index)
|
||
|
: that.slice(index, index + search.length) === search;
|
||
|
}
|
||
|
});
|