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