Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

trimStart.js 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. var baseToString = require('./_baseToString'),
  2. castSlice = require('./_castSlice'),
  3. charsStartIndex = require('./_charsStartIndex'),
  4. stringToArray = require('./_stringToArray'),
  5. toString = require('./toString');
  6. /** Used to match leading and trailing whitespace. */
  7. var reTrimStart = /^\s+/;
  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 && (guard || chars === undefined)) {
  30. return string.replace(reTrimStart, '');
  31. }
  32. if (!string || !(chars = baseToString(chars))) {
  33. return string;
  34. }
  35. var strSymbols = stringToArray(string),
  36. start = charsStartIndex(strSymbols, stringToArray(chars));
  37. return castSlice(strSymbols, start).join('');
  38. }
  39. module.exports = trimStart;