UNPKG

781 BJavaScriptView Raw
1var toString = require('../lang/toString');
2var WHITE_SPACES = require('./WHITE_SPACES');
3 /**
4 * Remove chars from end of string.
5 */
6 function rtrim(str, chars) {
7 str = toString(str);
8 chars = chars || WHITE_SPACES;
9
10 var end = str.length - 1,
11 charLen = chars.length,
12 found = true,
13 i, c;
14
15 while (found && end >= 0) {
16 found = false;
17 i = -1;
18 c = str.charAt(end);
19
20 while (++i < charLen) {
21 if (c === chars[i]) {
22 found = true;
23 end--;
24 break;
25 }
26 }
27 }
28
29 return (end >= 0) ? str.substring(0, end + 1) : '';
30 }
31
32 module.exports = rtrim;
33