code-block-writer
Advanced tools
Comparing version 1.5.0 to 1.5.1
@@ -33,3 +33,4 @@ var CodeBlockWriter = (function () { | ||
CodeBlockWriter.prototype.newLine = function () { | ||
if (this.isLastLineNotBlankNewLine() && !this._isAtStartOfBlock && this._text.length !== 0) { | ||
var willCreateAConsecutiveBlankLine = this.isLastLineBlankLine() && this.isCurrentLineBlank(); | ||
if (!willCreateAConsecutiveBlankLine && !this._isAtStartOfBlock && this._text.length !== 0) { | ||
this.write(this._newline); | ||
@@ -62,5 +63,17 @@ } | ||
}; | ||
CodeBlockWriter.prototype.isLastLineNotBlankNewLine = function () { | ||
return this.getLastLine() !== this._newline; | ||
CodeBlockWriter.prototype.isCurrentLineBlank = function () { | ||
return this.getCurrentLine().length === 0; | ||
}; | ||
CodeBlockWriter.prototype.isLastLineBlankLine = function () { | ||
return this.getLastLine() === this._newline; | ||
}; | ||
CodeBlockWriter.prototype.getCurrentLine = function () { | ||
var lastNewLineIndex = this._text.lastIndexOf(this._newline); | ||
if (lastNewLineIndex >= 0) { | ||
return this._text.substr(lastNewLineIndex + 1); | ||
} | ||
else { | ||
return ""; | ||
} | ||
}; | ||
CodeBlockWriter.prototype.getLastLine = function () { | ||
@@ -67,0 +80,0 @@ var lastLine; |
@@ -47,2 +47,10 @@ var assert = require("assert"); | ||
}); | ||
it("should put the brace on the next space if there is a newline before it", function () { | ||
var expected = "test {\n inside\n\n inside\n}\n"; | ||
doTest(expected, function (writer) { | ||
writer.write("test ").block(function () { | ||
writer.writeLine("inside").newLine().write("inside"); | ||
}); | ||
}); | ||
}); | ||
}); | ||
@@ -49,0 +57,0 @@ describe("writeLine()", function () { |
{ | ||
"name": "code-block-writer", | ||
"version": "1.5.0", | ||
"version": "1.5.1", | ||
"description": "A simple code writer that assists with formatting and visualizing blocks of code.", | ||
@@ -5,0 +5,0 @@ "main": "dist/code-block-writer.js", |
@@ -41,3 +41,4 @@ export default class CodeBlockWriter { | ||
newLine() { | ||
if (this.isLastLineNotBlankNewLine() && !this._isAtStartOfBlock && this._text.length !== 0) { | ||
const willCreateAConsecutiveBlankLine = this.isLastLineBlankLine() && this.isCurrentLineBlank(); | ||
if (!willCreateAConsecutiveBlankLine && !this._isAtStartOfBlock && this._text.length !== 0) { | ||
this.write(this._newline); | ||
@@ -81,6 +82,21 @@ } | ||
private isLastLineNotBlankNewLine() { | ||
return this.getLastLine() !== this._newline; | ||
private isCurrentLineBlank() { | ||
return this.getCurrentLine().length === 0; | ||
} | ||
private isLastLineBlankLine() { | ||
return this.getLastLine() === this._newline; | ||
} | ||
private getCurrentLine() { | ||
const lastNewLineIndex = this._text.lastIndexOf(this._newline); | ||
if (lastNewLineIndex >= 0) { | ||
return this._text.substr(lastNewLineIndex + 1); | ||
} | ||
else { | ||
return ""; | ||
} | ||
} | ||
private getLastLine() { | ||
@@ -87,0 +103,0 @@ let lastLine: string; |
@@ -69,2 +69,17 @@ import * as assert from "assert"; | ||
}); | ||
it("should put the brace on the next space if there is a newline before it", () => { | ||
const expected = | ||
`test { | ||
inside | ||
inside | ||
} | ||
`; | ||
doTest(expected, writer => { | ||
writer.write("test ").block(() => { | ||
writer.writeLine("inside").newLine().write("inside"); | ||
}); | ||
}); | ||
}); | ||
}); | ||
@@ -71,0 +86,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
123126
2849