-
Notifications
You must be signed in to change notification settings - Fork 7.1k
/
Copy pathtrimLeft.js
34 lines (32 loc) · 1.07 KB
/
trimLeft.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
define(['../internal/baseToString', '../internal/charsLeftIndex', '../internal/isIterateeCall', '../internal/trimmedLeftIndex'], function(baseToString, charsLeftIndex, isIterateeCall, trimmedLeftIndex) {
/**
* Removes leading whitespace or specified characters from `string`.
*
* @static
* @memberOf _
* @category String
* @param {string} [string=''] The string to trim.
* @param {string} [chars=whitespace] The characters to trim.
* @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
* @returns {string} Returns the trimmed string.
* @example
*
* _.trimLeft(' abc ');
* // => 'abc '
*
* _.trimLeft('-_-abc-_-', '_-');
* // => 'abc-_-'
*/
function trimLeft(string, chars, guard) {
var value = string;
string = baseToString(string);
if (!string) {
return string;
}
if (guard ? isIterateeCall(value, chars, guard) : chars == null) {
return string.slice(trimmedLeftIndex(string))
}
return string.slice(charsLeftIndex(string, baseToString(chars)));
}
return trimLeft;
});