Skip to content

Commit

Permalink
Merge pull request #164 from pelias/trim-normalizer
Browse files Browse the repository at this point in the history
feat(normalizers): Add `trim` normalizers
  • Loading branch information
orangejulius authored Feb 21, 2019
2 parents 2f70f89 + 7e8bb4f commit 217c8f7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/normalizers.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ module.exports.toUpperCase = function(val) {

};

module.exports.trim = function(val) {
if (!_.isString(val)) {
return val;
}

return val.trim();
};

module.exports.abbreviateDirectionals = function(val) {
if (!_.isString(val)) {
return val;
Expand Down
7 changes: 7 additions & 0 deletions test/normalizers.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ tape( 'toUpperCase should return string input uppercased', function(test) {

});

tape( 'trim returns string without leading and trailing whitespace', function(test) {
var input = ' abc ';

test.equal(normalizers.trim(input), 'abc');
test.end();
});

tape( 'non-string input to abbreviateDirectionals should return input value unmodified', function(test) {
var input = { 'foo': { 'bar': '!@#$'}, 'baz': 'AB*()CD'};

Expand Down

0 comments on commit 217c8f7

Please sign in to comment.