1 | import baseClamp from './_baseClamp';
|
2 | import toInteger from './toInteger';
|
3 | import toString from './toString';
|
4 |
|
5 | /**
|
6 | * Checks if `string` starts with the given target string.
|
7 | *
|
8 | * @static
|
9 | * @memberOf _
|
10 | * @since 3.0.0
|
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`,
|
16 | * else `false`.
|
17 | * @example
|
18 | *
|
19 | * _.startsWith('abc', 'a');
|
20 | * // => true
|
21 | *
|
22 | * _.startsWith('abc', 'b');
|
23 | * // => false
|
24 | *
|
25 | * _.startsWith('abc', 'b', 1);
|
26 | * // => true
|
27 | */
|
28 | function startsWith(string, target, position) {
|
29 | string = toString(string);
|
30 | position = baseClamp(toInteger(position), 0, string.length);
|
31 | return string.lastIndexOf(target, position) == position;
|
32 | }
|
33 |
|
34 | export default startsWith;
|