1 var baseToString = require('../internal/baseToString');
3 /* Native method references for those with the same name as other `lodash` methods. */
4 var nativeMin = Math.min;
7 * Checks if `string` ends with the given target string.
12 * @param {string} [string=''] The string to search.
13 * @param {string} [target] The string to search for.
14 * @param {number} [position=string.length] The position to search from.
15 * @returns {boolean} Returns `true` if `string` ends with `target`, else `false`.
18 * _.endsWith('abc', 'c');
21 * _.endsWith('abc', 'b');
24 * _.endsWith('abc', 'b', 2);
27 function endsWith(string, target, position) {
28 string = baseToString(string);
29 target = (target + '');
31 var length = string.length;
32 position = position === undefined
34 : nativeMin(position < 0 ? 0 : (+position || 0), length);
36 position -= target.length;
37 return position >= 0 && string.indexOf(target, position) == position;
40 module.exports = endsWith;