Skip to content

Commit

Permalink
Add char = " " param on trim, leftTrim and rightTrim methods #17
Browse files Browse the repository at this point in the history
  • Loading branch information
dleitee committed Apr 28, 2016
1 parent 9d38fc2 commit a0828f2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/string.utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export {isString};
* @params value - String to trim
* @return String without boarders spaces
*/
const trim = value => leftTrim(rightTrim(value));
const trim = (value, char = ' ') => leftTrim(rightTrim(value, char), char);

export {trim};

Expand All @@ -27,7 +27,7 @@ export {trim};
* @params value
* @return string
*/
const leftTrim = value => replace(value, '^\\s+', '');
const leftTrim = (value, char = ' ') => replace(value, `^${char}+`, '');

export {leftTrim};

Expand All @@ -36,7 +36,7 @@ export {leftTrim};
* @params value
* @return string
*/
const rightTrim = value => replace(value, '\\s+$', '');
const rightTrim = (value, char = ' ') => replace(value, `${char}+$`, '');

export {rightTrim};

Expand Down
26 changes: 25 additions & 1 deletion test/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,37 @@ describe('trim, ltrim and rtrim function', () => {
'foo bar',
'foo bar ',
' foo bar',
' foo bar '
' foo bar '
];

fixtures.forEach(el => {
chai.expect(trim(el)).to.equal('foo bar');
});
});
it('should be foo bar without @', () => {
let fixtures = [
'foo bar',
'foo bar@',
'@foo bar',
'@@foo bar@@@'
];

fixtures.forEach(el => {
chai.expect(trim(el, '@')).to.equal('foo bar');
});
});
it('should be foo bar without @ and with #', () => {
let fixtures = [
'@#foo bar',
'#foo bar@',
'@#foo bar@',
'@@#foo bar@@@'
];

fixtures.forEach(el => {
chai.expect(trim(el, '@')).to.equal('#foo bar');
});
});
});

describe('removeSpaces function', () => {
Expand Down

0 comments on commit a0828f2

Please sign in to comment.