_trimmedEndIndex.js 515 B

1234567891011121314151617181920
  1. /** Used to match a single whitespace character. */
  2. var reWhitespace = /\s/;
  3. /**
  4. * Used by `_.trim` and `_.trimEnd` to get the index of the last non-whitespace
  5. * character of `string`.
  6. *
  7. * @private
  8. * @param {string} string The string to inspect.
  9. * @returns {number} Returns the index of the last non-whitespace character.
  10. */
  11. function trimmedEndIndex(string) {
  12. var index = string.length;
  13. while (index-- && reWhitespace.test(string.charAt(index))) {}
  14. return index;
  15. }
  16. module.exports = trimmedEndIndex;