Skip to content

Commit 7e8bb4f

Browse files
committed
feat(normalizers): Add trim normalizers
1 parent 2f70f89 commit 7e8bb4f

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

lib/normalizers.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ module.exports.toUpperCase = function(val) {
3535

3636
};
3737

38+
module.exports.trim = function(val) {
39+
if (!_.isString(val)) {
40+
return val;
41+
}
42+
43+
return val.trim();
44+
};
45+
3846
module.exports.abbreviateDirectionals = function(val) {
3947
if (!_.isString(val)) {
4048
return val;

test/normalizers.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ tape( 'toUpperCase should return string input uppercased', function(test) {
7171

7272
});
7373

74+
tape( 'trim returns string without leading and trailing whitespace', function(test) {
75+
var input = ' abc ';
76+
77+
test.equal(normalizers.trim(input), 'abc');
78+
test.end();
79+
});
80+
7481
tape( 'non-string input to abbreviateDirectionals should return input value unmodified', function(test) {
7582
var input = { 'foo': { 'bar': '!@#$'}, 'baz': 'AB*()CD'};
7683

0 commit comments

Comments
 (0)