mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-04 00:57:48 +00:00
Bump to v4.0.0.
This commit is contained in:
39
endsWith.js
Normal file
39
endsWith.js
Normal file
@@ -0,0 +1,39 @@
|
||||
import baseClamp from './internal/baseClamp';
|
||||
import toInteger from './toInteger';
|
||||
import toString from './toString';
|
||||
|
||||
/**
|
||||
* Checks if `string` ends with the given target string.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category String
|
||||
* @param {string} [string=''] The string to search.
|
||||
* @param {string} [target] The string to search for.
|
||||
* @param {number} [position=string.length] The position to search from.
|
||||
* @returns {boolean} Returns `true` if `string` ends with `target`, else `false`.
|
||||
* @example
|
||||
*
|
||||
* _.endsWith('abc', 'c');
|
||||
* // => true
|
||||
*
|
||||
* _.endsWith('abc', 'b');
|
||||
* // => false
|
||||
*
|
||||
* _.endsWith('abc', 'b', 2);
|
||||
* // => true
|
||||
*/
|
||||
function endsWith(string, target, position) {
|
||||
string = toString(string);
|
||||
target = typeof target == 'string' ? target : (target + '');
|
||||
|
||||
var length = string.length;
|
||||
position = position === undefined
|
||||
? length
|
||||
: baseClamp(toInteger(position), 0, length);
|
||||
|
||||
position -= target.length;
|
||||
return position >= 0 && string.indexOf(target, position) == position;
|
||||
}
|
||||
|
||||
export default endsWith;
|
||||
Reference in New Issue
Block a user