1 var baseToString = require('./_baseToString'),
2 castSlice = require('./_castSlice'),
3 charsEndIndex = require('./_charsEndIndex'),
4 stringToArray = require('./_stringToArray'),
5 toString = require('./toString');
7 /** Used to match leading and trailing whitespace. */
8 var reTrimEnd = /\s+$/;
11 * Removes trailing whitespace or specified characters from `string`.
17 * @param {string} [string=''] The string to trim.
18 * @param {string} [chars=whitespace] The characters to trim.
19 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
20 * @returns {string} Returns the trimmed string.
26 * _.trimEnd('-_-abc-_-', '_-');
29 function trimEnd(string, chars, guard) {
30 string = toString(string);
31 if (string && (guard || chars === undefined)) {
32 return string.replace(reTrimEnd, '');
34 if (!string || !(chars = baseToString(chars))) {
37 var strSymbols = stringToArray(string),
38 end = charsEndIndex(strSymbols, stringToArray(chars)) + 1;
40 return castSlice(strSymbols, 0, end).join('');
43 module.exports = trimEnd;