1 | 'use strict';
|
2 | var $ = require('../internals/export');
|
3 | var uncurryThis = require('../internals/function-uncurry-this-clause');
|
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');
|
11 |
|
12 | var slice = uncurryThis(''.slice);
|
13 | var min = Math.min;
|
14 |
|
15 | var CORRECT_IS_REGEXP_LOGIC = correctIsRegExpLogic('endsWith');
|
16 |
|
17 | var MDN_POLYFILL_BUG = !IS_PURE && !CORRECT_IS_REGEXP_LOGIC && !!function () {
|
18 | var descriptor = getOwnPropertyDescriptor(String.prototype, 'endsWith');
|
19 | return descriptor && !descriptor.writable;
|
20 | }();
|
21 |
|
22 |
|
23 |
|
24 | $({ target: 'String', proto: true, forced: !MDN_POLYFILL_BUG && !CORRECT_IS_REGEXP_LOGIC }, {
|
25 | endsWith: function endsWith(searchString /* , endPosition = @length */) {
|
26 | var that = toString(requireObjectCoercible(this));
|
27 | notARegExp(searchString);
|
28 | var endPosition = arguments.length > 1 ? arguments[1] : undefined;
|
29 | var len = that.length;
|
30 | var end = endPosition === undefined ? len : min(toLength(endPosition), len);
|
31 | var search = toString(searchString);
|
32 | return slice(that, end - search.length, end) === search;
|
33 | }
|
34 | });
|