1 | import charsStartIndex from './_charsStartIndex';
|
2 | import stringToArray from './_stringToArray';
|
3 | import toString from './toString';
|
4 |
|
5 | /** Used to match leading and trailing whitespace. */
|
6 | var reTrimStart = /^\s+/;
|
7 |
|
8 | /**
|
9 | * Removes leading whitespace or specified characters from `string`.
|
10 | *
|
11 | * @static
|
12 | * @memberOf _
|
13 | * @since 4.0.0
|
14 | * @category String
|
15 | * @param {string} [string=''] The string to trim.
|
16 | * @param {string} [chars=whitespace] The characters to trim.
|
17 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
18 | * @returns {string} Returns the trimmed string.
|
19 | * @example
|
20 | *
|
21 | * _.trimStart(' abc ');
|
22 | * // => 'abc '
|
23 | *
|
24 | * _.trimStart('-_-abc-_-', '_-');
|
25 | * // => 'abc-_-'
|
26 | */
|
27 | function trimStart(string, chars, guard) {
|
28 | string = toString(string);
|
29 | if (!string) {
|
30 | return string;
|
31 | }
|
32 | if (guard || chars === undefined) {
|
33 | return string.replace(reTrimStart, '');
|
34 | }
|
35 | chars = (chars + '');
|
36 | if (!chars) {
|
37 | return string;
|
38 | }
|
39 | var strSymbols = stringToArray(string);
|
40 | return strSymbols
|
41 | .slice(charsStartIndex(strSymbols, stringToArray(chars)))
|
42 | .join('');
|
43 | }
|
44 |
|
45 | export default trimStart;
|