time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

trimStart.js (1228B)


      1 var baseToString = require('./_baseToString'),
      2     castSlice = require('./_castSlice'),
      3     charsStartIndex = require('./_charsStartIndex'),
      4     stringToArray = require('./_stringToArray'),
      5     toString = require('./toString');
      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 module.exports = trimStart;