Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80742 views
1
var baseToString = require('../internal/baseToString'),
2
charsLeftIndex = require('../internal/charsLeftIndex'),
3
isIterateeCall = require('../internal/isIterateeCall'),
4
trimmedLeftIndex = require('../internal/trimmedLeftIndex');
5
6
/**
7
* Removes leading whitespace or specified characters from `string`.
8
*
9
* @static
10
* @memberOf _
11
* @category String
12
* @param {string} [string=''] The string to trim.
13
* @param {string} [chars=whitespace] The characters to trim.
14
* @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
15
* @returns {string} Returns the trimmed string.
16
* @example
17
*
18
* _.trimLeft(' abc ');
19
* // => 'abc '
20
*
21
* _.trimLeft('-_-abc-_-', '_-');
22
* // => 'abc-_-'
23
*/
24
function trimLeft(string, chars, guard) {
25
var value = string;
26
string = baseToString(string);
27
if (!string) {
28
return string;
29
}
30
if (guard ? isIterateeCall(value, chars, guard) : chars == null) {
31
return string.slice(trimmedLeftIndex(string));
32
}
33
return string.slice(charsLeftIndex(string, (chars + '')));
34
}
35
36
module.exports = trimLeft;
37
38