trimmedRightIndex.js 474 B

123456789101112131415161718
  1. var isSpace = require('./isSpace');
  2. /**
  3. * Used by `_.trim` and `_.trimRight` to get the index of the last non-whitespace
  4. * character of `string`.
  5. *
  6. * @private
  7. * @param {string} string The string to inspect.
  8. * @returns {number} Returns the index of the last non-whitespace character.
  9. */
  10. function trimmedRightIndex(string) {
  11. var index = string.length;
  12. while (index-- && isSpace(string.charCodeAt(index))) {}
  13. return index;
  14. }
  15. module.exports = trimmedRightIndex;