1var baseToString = require('../internal/baseToString'); 2 3/* Native method references for those with the same name as other `lodash` methods. */ 4var nativeMin = Math.min; 5 6/** 7 * Checks if `string` starts with the given target string. 8 * 9 * @static 10 * @memberOf _ 11 * @category String 12 * @param {string} [string=''] The string to search. 13 * @param {string} [target] The string to search for. 14 * @param {number} [position=0] The position to search from. 15 * @returns {boolean} Returns `true` if `string` starts with `target`, else `false`. 16 * @example 17 * 18 * _.startsWith('abc', 'a'); 19 * // => true 20 * 21 * _.startsWith('abc', 'b'); 22 * // => false 23 * 24 * _.startsWith('abc', 'b', 1); 25 * // => true 26 */ 27function startsWith(string, target, position) { 28 string = baseToString(string); 29 position = position == null 30 ? 0 31 : nativeMin(position < 0 ? 0 : (+position || 0), string.length); 32 33 return string.lastIndexOf(target, position) == position; 34} 35 36module.exports = startsWith; 37 38