main
Last change
on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
1015 bytes
|
Line | |
---|
1 | import baseClamp from './_baseClamp.js';
|
---|
2 | import baseToString from './_baseToString.js';
|
---|
3 | import toInteger from './toInteger.js';
|
---|
4 | import toString from './toString.js';
|
---|
5 |
|
---|
6 | /**
|
---|
7 | * Checks if `string` starts with the given target string.
|
---|
8 | *
|
---|
9 | * @static
|
---|
10 | * @memberOf _
|
---|
11 | * @since 3.0.0
|
---|
12 | * @category String
|
---|
13 | * @param {string} [string=''] The string to inspect.
|
---|
14 | * @param {string} [target] The string to search for.
|
---|
15 | * @param {number} [position=0] The position to search from.
|
---|
16 | * @returns {boolean} Returns `true` if `string` starts with `target`,
|
---|
17 | * else `false`.
|
---|
18 | * @example
|
---|
19 | *
|
---|
20 | * _.startsWith('abc', 'a');
|
---|
21 | * // => true
|
---|
22 | *
|
---|
23 | * _.startsWith('abc', 'b');
|
---|
24 | * // => false
|
---|
25 | *
|
---|
26 | * _.startsWith('abc', 'b', 1);
|
---|
27 | * // => true
|
---|
28 | */
|
---|
29 | function startsWith(string, target, position) {
|
---|
30 | string = toString(string);
|
---|
31 | position = position == null
|
---|
32 | ? 0
|
---|
33 | : baseClamp(toInteger(position), 0, string.length);
|
---|
34 |
|
---|
35 | target = baseToString(target);
|
---|
36 | return string.slice(position, position + target.length) == target;
|
---|
37 | }
|
---|
38 |
|
---|
39 | export default startsWith;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.