Version 1
[yaffs-website] / node_modules / core-js / library / modules / es6.string.ends-with.js
1 // 21.1.3.6 String.prototype.endsWith(searchString [, endPosition])
2 'use strict';
3 var $export   = require('./_export')
4   , toLength  = require('./_to-length')
5   , context   = require('./_string-context')
6   , ENDS_WITH = 'endsWith'
7   , $endsWith = ''[ENDS_WITH];
8
9 $export($export.P + $export.F * require('./_fails-is-regexp')(ENDS_WITH), 'String', {
10   endsWith: function endsWith(searchString /*, endPosition = @length */){
11     var that = context(this, searchString, ENDS_WITH)
12       , endPosition = arguments.length > 1 ? arguments[1] : undefined
13       , len    = toLength(that.length)
14       , end    = endPosition === undefined ? len : Math.min(toLength(endPosition), len)
15       , search = String(searchString);
16     return $endsWith
17       ? $endsWith.call(that, search, end)
18       : that.slice(end - search.length, end) === search;
19   }
20 });