Skip to content

Commit

Permalink
Merge pull request #176 from plaid/dc-trim
Browse files Browse the repository at this point in the history
string: add S.trim
  • Loading branch information
davidchambers committed Apr 13, 2016
2 parents d24b9bf + d175192 commit c469fa4
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
14 changes: 14 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2919,6 +2919,20 @@
[$.String, $.String],
function(s) { return s.toLowerCase(); });

//# trim :: String -> String
//.
//. Strips leading and trailing whitespace characters.
//.
//. ```javascript
//. > S.trim('\t\t foo bar \n')
//. 'foo bar'
//. ```
S.trim =
def('trim',
{},
[$.String, $.String],
R.trim);

//# words :: String -> [String]
//.
//. Takes a string and returns the list of words the string contains
Expand Down
33 changes: 33 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5553,6 +5553,39 @@ describe('string', function() {

});

describe('trim', function() {

it('is a unary function', function() {
eq(typeof S.trim, 'function');
eq(S.trim.length, 1);
});

it('type checks its arguments', function() {
throws(function() { S.trim(/XXX/); },
errorEq(TypeError,
'Invalid value\n' +
'\n' +
'trim :: String -> String\n' +
' ^^^^^^\n' +
' 1\n' +
'\n' +
'1) /XXX/ :: RegExp\n' +
'\n' +
'The value at position 1 is not a member of ‘String’.\n'));
});

it('strips leading and trailing whitespace characters', function() {
eq(S.trim(''), '');
eq(S.trim(' '), '');
eq(S.trim('x'), 'x');
eq(S.trim(' x'), 'x');
eq(S.trim('x '), 'x');
eq(S.trim(' x '), 'x');
eq(S.trim('\n\r\t x \n\r\t x \n\r\t'), 'x \n\r\t x');
});

});

describe('words', function() {

it('is a unary function', function() {
Expand Down

0 comments on commit c469fa4

Please sign in to comment.