charsLeftIndex.js 543 B

123456789101112131415161718
  1. /**
  2. * Used by `_.trim` and `_.trimLeft` to get the index of the first character
  3. * of `string` that is not found in `chars`.
  4. *
  5. * @private
  6. * @param {string} string The string to inspect.
  7. * @param {string} chars The characters to find.
  8. * @returns {number} Returns the index of the first character not found in `chars`.
  9. */
  10. function charsLeftIndex(string, chars) {
  11. var index = -1,
  12. length = string.length;
  13. while (++index < length && chars.indexOf(string.charAt(index)) > -1) {}
  14. return index;
  15. }
  16. module.exports = charsLeftIndex;