1 var baseClamp = require('./_baseClamp'),
2 toInteger = require('./toInteger'),
3 toString = require('./toString');
6 * Checks if `string` ends with the given target string.
11 * @param {string} [string=''] The string to search.
12 * @param {string} [target] The string to search for.
13 * @param {number} [position=string.length] The position to search from.
14 * @returns {boolean} Returns `true` if `string` ends with `target`, else `false`.
17 * _.endsWith('abc', 'c');
20 * _.endsWith('abc', 'b');
23 * _.endsWith('abc', 'b', 2);
26 function endsWith(string, target, position) {
27 string = toString(string);
28 target = typeof target == 'string' ? target : (target + '');
30 var length = string.length;
31 position = position === undefined
33 : baseClamp(toInteger(position), 0, length);
35 position -= target.length;
36 return position >= 0 && string.indexOf(target, position) == position;
39 module.exports = endsWith;