code-block-writer
Advanced tools
Comparing version 1.5.2 to 1.6.0
@@ -16,2 +16,3 @@ var CodeBlockWriter = (function () { | ||
block(); | ||
this.removeLastIfNewLine(); | ||
this._currentIndentation--; | ||
@@ -63,2 +64,7 @@ this.writeLine("}"); | ||
}; | ||
CodeBlockWriter.prototype.removeLastIfNewLine = function () { | ||
if (this.isLastLineBlankLine() && this.isCurrentLineBlank()) { | ||
this._text = this._text.substr(0, this._text.length - this._newLine.length); | ||
} | ||
}; | ||
CodeBlockWriter.prototype.isCurrentLineBlank = function () { | ||
@@ -65,0 +71,0 @@ return this.getCurrentLine().length === 0; |
@@ -76,2 +76,10 @@ var assert = require("assert"); | ||
}); | ||
it("should remove a newline if the last thing before the block was a newline", function () { | ||
var expected = "test {\n inside\n}\n"; | ||
doTest(expected, function (writer) { | ||
writer.write("test ").block(function () { | ||
writer.writeLine("inside").newLine(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
@@ -78,0 +86,0 @@ describe("writeLine()", function () { |
{ | ||
"name": "code-block-writer", | ||
"version": "1.5.2", | ||
"version": "1.6.0", | ||
"description": "A simple code writer that assists with formatting and visualizing blocks of code.", | ||
@@ -5,0 +5,0 @@ "main": "dist/code-block-writer.js", |
@@ -18,2 +18,3 @@ export default class CodeBlockWriter { | ||
block(); | ||
this.removeLastIfNewLine(); | ||
this._currentIndentation--; | ||
@@ -83,2 +84,8 @@ this.writeLine("}"); | ||
private removeLastIfNewLine() { | ||
if (this.isLastLineBlankLine() && this.isCurrentLineBlank()) { | ||
this._text = this._text.substr(0, this._text.length - this._newLine.length); | ||
} | ||
} | ||
private isCurrentLineBlank() { | ||
@@ -85,0 +92,0 @@ return this.getCurrentLine().length === 0; |
@@ -110,2 +110,15 @@ import * as assert from "assert"; | ||
}); | ||
it("should remove a newline if the last thing before the block was a newline", () => { | ||
const expected = | ||
`test { | ||
inside | ||
} | ||
`; | ||
doTest(expected, writer => { | ||
writer.write("test ").block(() => { | ||
writer.writeLine("inside").newLine(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
@@ -112,0 +125,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
127409
2949