1 var charsEndIndex = require('./_charsEndIndex'),
2 stringToArray = require('./_stringToArray'),
3 toString = require('./toString');
5 /** Used to match leading and trailing whitespace. */
6 var reTrimEnd = /\s+$/;
9 * Removes trailing whitespace or specified characters from `string`.
14 * @param {string} [string=''] The string to trim.
15 * @param {string} [chars=whitespace] The characters to trim.
16 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
17 * @returns {string} Returns the trimmed string.
23 * _.trimEnd('-_-abc-_-', '_-');
26 function trimEnd(string, chars, guard) {
27 string = toString(string);
31 if (guard || chars === undefined) {
32 return string.replace(reTrimEnd, '');
38 var strSymbols = stringToArray(string);
39 return strSymbols.slice(0, charsEndIndex(strSymbols, stringToArray(chars)) + 1).join('');
42 module.exports = trimEnd;