ltrim.js 814 B

12345678910111213141516171819202122232425262728293031323334
  1. var toString = require('../lang/toString');
  2. var WHITE_SPACES = require('./WHITE_SPACES');
  3. /**
  4. * Remove chars from beginning of string.
  5. */
  6. function ltrim(str, chars) {
  7. str = toString(str);
  8. chars = chars || WHITE_SPACES;
  9. var start = 0,
  10. len = str.length,
  11. charLen = chars.length,
  12. found = true,
  13. i, c;
  14. while (found && start < len) {
  15. found = false;
  16. i = -1;
  17. c = str.charAt(start);
  18. while (++i < charLen) {
  19. if (c === chars[i]) {
  20. found = true;
  21. start++;
  22. break;
  23. }
  24. }
  25. }
  26. return (start >= len) ? '' : str.substr(start, len);
  27. }
  28. module.exports = ltrim;