Version 1
[yaffs-website] / node_modules / uncss / node_modules / lodash / trimEnd.js
1 var charsEndIndex = require('./internal/charsEndIndex'),
2     stringToArray = require('./internal/stringToArray'),
3     toString = require('./toString');
4
5 /** Used to match leading and trailing whitespace. */
6 var reTrimEnd = /\s+$/;
7
8 /**
9  * Removes trailing whitespace or specified characters from `string`.
10  *
11  * @static
12  * @memberOf _
13  * @category 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.
18  * @example
19  *
20  * _.trimEnd('  abc  ');
21  * // => '  abc'
22  *
23  * _.trimEnd('-_-abc-_-', '_-');
24  * // => '-_-abc'
25  */
26 function trimEnd(string, chars, guard) {
27   string = toString(string);
28   if (!string) {
29     return string;
30   }
31   if (guard || chars === undefined) {
32     return string.replace(reTrimEnd, '');
33   }
34   chars = (chars + '');
35   if (!chars) {
36     return string;
37   }
38   var strSymbols = stringToArray(string);
39   return strSymbols.slice(0, charsEndIndex(strSymbols, stringToArray(chars)) + 1).join('');
40 }
41
42 module.exports = trimEnd;