1 var baseClamp = require('./_baseClamp'),
2 baseToString = require('./_baseToString'),
3 toInteger = require('./toInteger'),
4 toString = require('./toString');
7 * Checks if `string` ends with the given target string.
13 * @param {string} [string=''] The string to inspect.
14 * @param {string} [target] The string to search for.
15 * @param {number} [position=string.length] The position to search up to.
16 * @returns {boolean} Returns `true` if `string` ends with `target`,
20 * _.endsWith('abc', 'c');
23 * _.endsWith('abc', 'b');
26 * _.endsWith('abc', 'b', 2);
29 function endsWith(string, target, position) {
30 string = toString(string);
31 target = baseToString(target);
33 var length = string.length;
34 position = position === undefined
36 : baseClamp(toInteger(position), 0, length);
39 position -= target.length;
40 return position >= 0 && string.slice(position, end) == target;
43 module.exports = endsWith;