Version 1
[yaffs-website] / node_modules / uncss / node_modules / lodash / endsWith.js
1 var baseClamp = require('./internal/baseClamp'),
2     toInteger = require('./toInteger'),
3     toString = require('./toString');
4
5 /**
6  * Checks if `string` ends with the given target string.
7  *
8  * @static
9  * @memberOf _
10  * @category 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`.
15  * @example
16  *
17  * _.endsWith('abc', 'c');
18  * // => true
19  *
20  * _.endsWith('abc', 'b');
21  * // => false
22  *
23  * _.endsWith('abc', 'b', 2);
24  * // => true
25  */
26 function endsWith(string, target, position) {
27   string = toString(string);
28   target = typeof target == 'string' ? target : (target + '');
29
30   var length = string.length;
31   position = position === undefined
32     ? length
33     : baseClamp(toInteger(position), 0, length);
34
35   position -= target.length;
36   return position >= 0 && string.indexOf(target, position) == position;
37 }
38
39 module.exports = endsWith;