1 var baseToString = require('../internal/baseToString');
3 /* Native method references for those with the same name as other `lodash` methods. */
4 var nativeMin = Math.min;
7 * Checks if `string` starts with the given target 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`.
18 * _.startsWith('abc', 'a');
21 * _.startsWith('abc', 'b');
24 * _.startsWith('abc', 'b', 1);
27 function startsWith(string, target, position) {
28 string = baseToString(string);
29 position = position == null
31 : nativeMin(position < 0 ? 0 : (+position || 0), string.length);
33 return string.lastIndexOf(target, position) == position;
36 module.exports = startsWith;