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