1 | 'use strict';
|
2 | var $ = require('../internals/export');
|
3 | var toLength = require('../internals/to-length');
|
4 | var notARegExp = require('../internals/not-a-regexp');
|
5 | var requireObjectCoercible = require('../internals/require-object-coercible');
|
6 | var correctIsRegExpLogic = require('../internals/correct-is-regexp-logic');
|
7 |
|
8 | var nativeEndsWith = ''.endsWith;
|
9 | var min = Math.min;
|
10 |
|
11 |
|
12 |
|
13 | $({ target: 'String', proto: true, forced: !correctIsRegExpLogic('endsWith') }, {
|
14 | endsWith: function endsWith(searchString /* , endPosition = @length */) {
|
15 | var that = String(requireObjectCoercible(this));
|
16 | notARegExp(searchString);
|
17 | var endPosition = arguments.length > 1 ? arguments[1] : undefined;
|
18 | var len = toLength(that.length);
|
19 | var end = endPosition === undefined ? len : min(toLength(endPosition), len);
|
20 | var search = String(searchString);
|
21 | return nativeEndsWith
|
22 | ? nativeEndsWith.call(that, search, end)
|
23 | : that.slice(end - search.length, end) === search;
|
24 | }
|
25 | });
|