Permalink
Browse files

Make line() return the generated string instead of appending it to ret

This makes reasoning about the newly created line easier, to eg. skip
empty lines.
  • Loading branch information...
1 parent dbf75bb commit 912ec4477c0aed9985d5c9e796a8d536ab13670b @em- committed Mar 9, 2013
Showing with 16 additions and 15 deletions.
  1. +16 −15 lib/cli-table/index.js
View
@@ -147,16 +147,16 @@ Table.prototype.toString = function (){
line = line.substr(0, width) + intersection + line.substr(width + 1);
});
- ret += applyStyles(options.style.border, line);
+ return applyStyles(options.style.border, line);
};
// draws the top line
function lineTop (){
- line(chars.top
- , chars['top-left'] || chars.top
- , chars['top-right'] || chars.top
- , chars['top-mid']);
- ret += "\n";
+ var l = line(chars.top
+ , chars['top-left'] || chars.top
+ , chars['top-right'] || chars.top
+ , chars['top-mid']);
+ ret += l + "\n";
};
function generateRow (items, style) {
@@ -258,12 +258,12 @@ Table.prototype.toString = function (){
lineTop();
else {
if (!style.compact || i<(!!head.length) ?1:0 || cells.length == 0){
- line(chars.mid
- , chars['left-mid']
- , chars['right-mid']
- , chars['mid-mid']);
+ var l = line(chars.mid
+ , chars['left-mid']
+ , chars['right-mid']
+ , chars['mid-mid']);
- ret += "\n"
+ ret += l + "\n"
}
}
@@ -274,10 +274,11 @@ Table.prototype.toString = function (){
};
});
- line(chars.bottom
- , chars['bottom-left'] || chars.bottom
- , chars['bottom-right'] || chars.bottom
- , chars['bottom-mid']);
+ var l = line(chars.bottom
+ , chars['bottom-left'] || chars.bottom
+ , chars['bottom-right'] || chars.bottom
+ , chars['bottom-mid']);
+ ret += l;
return ret;
};

0 comments on commit 912ec44

Please sign in to comment.