Socket
Socket
Sign inDemoInstall

code-block-writer

Package Overview
Dependencies
Maintainers
1
Versions
85
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

code-block-writer - npm Package Compare versions

Comparing version 1.5.0 to 1.5.1

19

dist/code-block-writer.js

@@ -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 () {

2

package.json
{
"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 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc