core-js
Version:
Standard library
17 lines (16 loc) • 725 B
JavaScript
;
var $def = require('./$.def')
, toLength = require('./$.to-length')
, context = require('./$.string-context');
// should throw error on regex
$def($def.P + $def.F * !require('./$.fails')(function(){ 'q'.endsWith(/./); }), 'String', {
// 21.1.3.6 String.prototype.endsWith(searchString [, endPosition])
endsWith: function endsWith(searchString /*, endPosition = @length */){
var that = context(this, searchString, 'endsWith')
, endPosition = arguments[1]
, len = toLength(that.length)
, end = endPosition === undefined ? len : Math.min(toLength(endPosition), len)
, search = String(searchString);
return that.slice(end - search.length, end) === search;
}
});