mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-06 01:47:48 +00:00
Bump to v4.0.0.
This commit is contained in:
32
startsWith.js
Normal file
32
startsWith.js
Normal file
@@ -0,0 +1,32 @@
|
||||
import baseClamp from './internal/baseClamp';
|
||||
import toInteger from './toInteger';
|
||||
import toString from './toString';
|
||||
|
||||
/**
|
||||
* Checks if `string` starts 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=0] The position to search from.
|
||||
* @returns {boolean} Returns `true` if `string` starts with `target`, else `false`.
|
||||
* @example
|
||||
*
|
||||
* _.startsWith('abc', 'a');
|
||||
* // => true
|
||||
*
|
||||
* _.startsWith('abc', 'b');
|
||||
* // => false
|
||||
*
|
||||
* _.startsWith('abc', 'b', 1);
|
||||
* // => true
|
||||
*/
|
||||
function startsWith(string, target, position) {
|
||||
string = toString(string);
|
||||
position = baseClamp(toInteger(position), 0, string.length);
|
||||
return string.lastIndexOf(target, position) == position;
|
||||
}
|
||||
|
||||
export default startsWith;
|
||||
Reference in New Issue
Block a user