Comparing version 4.2.0 to 4.2.1
@@ -18,2 +18,6 @@ var utils = require('./utils'); | ||
case 'text': return String(outputEntry.args[0]).split('\n').map(function (line) { | ||
if (line === '') { | ||
return []; | ||
} | ||
var args = [line].concat(outputEntry.args.slice(1)); | ||
@@ -37,2 +41,3 @@ return [{ style: 'text', args: args }]; | ||
var result = []; | ||
var linesLengths = []; | ||
@@ -48,23 +53,18 @@ var startIndex = 0; | ||
var padLines = blockIndex < line.length - 1; | ||
blockLines.forEach(function (blockLine, index) { | ||
var resultLine = result[index]; | ||
blockLines.forEach(function (blockLine, index) { | ||
if (!result[index]) { | ||
result[index] = [createPadding(startIndex)]; | ||
if (!resultLine) { | ||
result[index] = resultLine = []; | ||
linesLengths[index] = 0; | ||
} | ||
Array.prototype.push.apply(result[index], blockLine); | ||
var paddingLength = longestLineLength - blockLinesLengths[index]; | ||
if (padLines && paddingLength > 0) { | ||
result[index].push(createPadding(paddingLength)); | ||
if (blockLine.length) { | ||
var paddingLength = startIndex - linesLengths[index]; | ||
resultLine.push(createPadding(paddingLength)); | ||
Array.prototype.push.apply(resultLine, blockLine); | ||
linesLengths[index] = startIndex + blockLinesLengths[index]; | ||
} | ||
}); | ||
if (padLines) { | ||
for (var i = blockLines.length; i < result.length; i += 1) { | ||
result[i].push(createPadding(longestLineLength)); | ||
} | ||
} | ||
startIndex += longestLineLength; | ||
@@ -71,0 +71,0 @@ }, this); |
@@ -164,3 +164,5 @@ /*global window*/ | ||
lines.forEach(function (lineContent, index) { | ||
this.write({ style: 'text', args: [lineContent].concat(args) }); | ||
if (lineContent.length) { | ||
this.write({ style: 'text', args: [lineContent].concat(args) }); | ||
} | ||
if (index < lines.length - 1) { | ||
@@ -167,0 +169,0 @@ this.nl(); |
@@ -470,3 +470,5 @@ /*! | ||
lines.forEach(function (lineContent, index) { | ||
this.write({ style: 'text', args: [lineContent].concat(args) }); | ||
if (lineContent.length) { | ||
this.write({ style: 'text', args: [lineContent].concat(args) }); | ||
} | ||
if (index < lines.length - 1) { | ||
@@ -899,2 +901,6 @@ this.nl(); | ||
case 'text': return String(outputEntry.args[0]).split('\n').map(function (line) { | ||
if (line === '') { | ||
return []; | ||
} | ||
var args = [line].concat(outputEntry.args.slice(1)); | ||
@@ -918,2 +924,3 @@ return [{ style: 'text', args: args }]; | ||
var result = []; | ||
var linesLengths = []; | ||
@@ -929,23 +936,18 @@ var startIndex = 0; | ||
var padLines = blockIndex < line.length - 1; | ||
blockLines.forEach(function (blockLine, index) { | ||
var resultLine = result[index]; | ||
blockLines.forEach(function (blockLine, index) { | ||
if (!result[index]) { | ||
result[index] = [createPadding(startIndex)]; | ||
if (!resultLine) { | ||
result[index] = resultLine = []; | ||
linesLengths[index] = 0; | ||
} | ||
Array.prototype.push.apply(result[index], blockLine); | ||
var paddingLength = longestLineLength - blockLinesLengths[index]; | ||
if (padLines && paddingLength > 0) { | ||
result[index].push(createPadding(paddingLength)); | ||
if (blockLine.length) { | ||
var paddingLength = startIndex - linesLengths[index]; | ||
resultLine.push(createPadding(paddingLength)); | ||
Array.prototype.push.apply(resultLine, blockLine); | ||
linesLengths[index] = startIndex + blockLinesLengths[index]; | ||
} | ||
}); | ||
if (padLines) { | ||
for (var i = blockLines.length; i < result.length; i += 1) { | ||
result[i].push(createPadding(longestLineLength)); | ||
} | ||
} | ||
startIndex += longestLineLength; | ||
@@ -952,0 +954,0 @@ }, this); |
{ | ||
"name": "magicpen", | ||
"version": "4.2.0", | ||
"version": "4.2.1", | ||
"description": "Styled output in both consoles and browsers", | ||
@@ -5,0 +5,0 @@ "main": "./lib/MagicPen.js", |
@@ -269,2 +269,13 @@ /*global describe, it, beforeEach*/ | ||
}); | ||
it('does not create trailing whitespace', function () { | ||
pen.block('text', 'tic') | ||
.block('text', '\ntac') | ||
.block('text', '\n\ntoe'); | ||
expect(pen.toString(), 'to equal', | ||
'tic\n' + | ||
' tac\n' + | ||
' toe'); | ||
}); | ||
}); | ||
@@ -271,0 +282,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
528472
3278