mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-05 09:27:49 +00:00
Bump to v3.0.0.
This commit is contained in:
33
string/startsWith.js
Normal file
33
string/startsWith.js
Normal file
@@ -0,0 +1,33 @@
|
||||
import baseToString from '../internal/baseToString';
|
||||
|
||||
/* Native method references for those with the same name as other `lodash` methods. */
|
||||
var nativeMin = Math.min;
|
||||
|
||||
/**
|
||||
* 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 = baseToString(string);
|
||||
position = position == null ? 0 : nativeMin(position < 0 ? 0 : (+position || 0), string.length);
|
||||
return string.lastIndexOf(target, position) == position;
|
||||
}
|
||||
|
||||
export default startsWith;
|
||||
Reference in New Issue
Block a user