Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

code-block-writer

Package Overview
Dependencies
Maintainers
1
Versions
86
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 4.1.0 to 4.2.0

1

code-block-writer.d.ts

@@ -14,4 +14,5 @@ export default class CodeBlockWriter {

spaceIfLastNotSpace(): CodeBlockWriter;
indent(): CodeBlockWriter;
write(str: string): CodeBlockWriter;
toString(): string;
}

21

dist/code-block-writer.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var CodeBlockWriter = (function () {

@@ -8,4 +9,3 @@ function CodeBlockWriter(opts) {

this._newLine = (opts && opts.newLine) || "\n";
this._numberSpaces = (opts && opts.indentNumberOfSpaces) || 4;
this._useTabs = (opts && opts.useTabs) || false;
this._indentationText = getIndentationText((opts && opts.useTabs) || false, (opts && opts.indentNumberOfSpaces) || 4);
}

@@ -48,2 +48,5 @@ CodeBlockWriter.prototype.block = function (block) {

};
CodeBlockWriter.prototype.indent = function () {
return this.write(this._indentationText);
};
CodeBlockWriter.prototype.conditionalNewLine = function (condition) {

@@ -141,15 +144,13 @@ if (condition)

CodeBlockWriter.prototype.writeIndentation = function () {
if (this._useTabs)
this._text += Array(this._currentIndentation + 1).join("\t");
else
this._text += Array(this._getCurrentIndentationNumberSpaces() + 1).join(" ");
this._text += Array(this._currentIndentation + 1).join(this._indentationText);
};
CodeBlockWriter.prototype._getCurrentIndentationNumberSpaces = function () {
return this._currentIndentation * this._numberSpaces;
};
return CodeBlockWriter;
}());
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = CodeBlockWriter;
function getIndentationText(useTabs, numberSpaces) {
if (useTabs)
return "\t";
return Array(numberSpaces + 1).join(" ");
}
//# sourceMappingURL=code-block-writer.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var assert = require("assert");

@@ -150,2 +151,10 @@ var code_block_writer_1 = require("./../code-block-writer");

});
describe("#indent()", function () {
it("should indent as necessary", function () {
var expected = "test\n test";
doTest(expected, function (writer) {
writer.writeLine("test").indent().write("test");
});
});
});
describe("#newLineIfLastNotNewLine()", function () {

@@ -152,0 +161,0 @@ it("should do a newline if the last text was not a newline", function () {

@@ -37,4 +37,4 @@ var gulp = require("gulp");

return gulp.src(["./src/**/*.ts", "!./src/typings/**/*.d.ts"])
.pipe(tslint())
.pipe(tslint.report("verbose"));
.pipe(tslint({ formatter: "verbose" }))
.pipe(tslint.report());
});

@@ -41,0 +41,0 @@

{
"name": "code-block-writer",
"version": "4.1.0",
"version": "4.2.0",
"description": "A simple code writer that assists with formatting and visualizing blocks of code.",

@@ -31,14 +31,14 @@ "main": "dist/code-block-writer.js",

"devDependencies": {
"coveralls": "^2.11.6",
"coveralls": "^2.13.1",
"del": "^2.0.2",
"gulp": "^3.9.1",
"gulp-istanbul": "^0.10.3",
"gulp-istanbul": "^1.1.1",
"gulp-mocha": "^2.2.0",
"gulp-sourcemaps": "^1.6.0",
"gulp-tslint": "^4.1.1",
"gulp-typescript": "^2.9.2",
"mocha": "^2.3.3",
"tslint": "^3.1.1",
"typescript": "^2.1.6"
"gulp-tslint": "^8.1.1",
"gulp-typescript": "^2.13.3",
"mocha": "^3.3.0",
"tslint": "^5.6.0",
"typescript": "^2.5.2"
}
}

@@ -51,13 +51,15 @@ code-block-writer

* `block(block: () => void)` - Indents all the code written within and surrounds it in braces
* `inlineBlock(block: () => void)` - Same as block, but doesn't add a space before the first brace and doesn't add a newline at the end
* `getLength()` - Get the current number of characters
* `writeLine(str: string)` - Writes some text and adds a newline
* `newLineIfLastNotNewLine()` - Writes a newline if what was written last wasn't a newline
* `newLine()` - Writes a newline
* `spaceIfLastNotSpace()` - Writes a space if the last was not a space
* `write(str: string)` - Writes some text
* `conditionalNewLine(condition: boolean)` - Writes a newline if the condition is matched
* `conditionalWrite(condition: boolean, str: string)` - Writes if the condition is matched
* `conditionalWriteLine(condition: boolean, str: string)` - Writes some text and adds a newline if the condition is matched
* `toString()` - Gets the string
* `block(block: () => void)` - Indents all the code written within and surrounds it in braces.
* `inlineBlock(block: () => void)` - Same as block, but doesn't add a space before the first brace and doesn't add a newline at the end.
* `getLength()` - Get the current number of characters.
* `writeLine(str: string)` - Writes some text and adds a newline.
* `newLineIfLastNotNewLine()` - Writes a newline if what was written last wasn't a newline.
* `newLine()` - Writes a newline.
* `blankLine()` - Writes a blank line. Does not allow consecutive blank lines.
* `indent()` - Indents the current line.
* `spaceIfLastNotSpace()` - Writes a space if the last was not a space.
* `write(str: string)` - Writes some text.
* `conditionalNewLine(condition: boolean)` - Writes a newline if the condition is matched.
* `conditionalWrite(condition: boolean, str: string)` - Writes if the condition is matched.
* `conditionalWriteLine(condition: boolean, str: string)` - Writes some text and adds a newline if the condition is matched.
* `toString()` - Gets the string.
export default class CodeBlockWriter {
private readonly _indentationText: string;
private readonly _newLine: string;
private _currentIndentation = 0;
private _text = "";
private _numberSpaces: number;
private _useTabs: boolean;
private _newLine: string;
private _isAtStartOfBlock = false;

@@ -11,4 +10,3 @@

this._newLine = (opts && opts.newLine) || "\n";
this._numberSpaces = (opts && opts.indentNumberOfSpaces) || 4;
this._useTabs = (opts && opts.useTabs) || false;
this._indentationText = getIndentationText((opts && opts.useTabs) || false, (opts && opts.indentNumberOfSpaces) || 4);
}

@@ -20,3 +18,2 @@

this.newLine();
return this;

@@ -64,2 +61,6 @@ }

indent() {
return this.write(this._indentationText);
}
conditionalNewLine(condition: boolean) {

@@ -193,11 +194,10 @@ if (condition)

private writeIndentation() {
if (this._useTabs)
this._text += Array(this._currentIndentation + 1).join("\t");
else
this._text += Array(this._getCurrentIndentationNumberSpaces() + 1).join(" ");
this._text += Array(this._currentIndentation + 1).join(this._indentationText);
}
}
private _getCurrentIndentationNumberSpaces() {
return this._currentIndentation * this._numberSpaces;
}
function getIndentationText(useTabs: boolean, numberSpaces: number) {
if (useTabs)
return "\t";
return Array(numberSpaces + 1).join(" ");
}

@@ -211,2 +211,12 @@ import * as assert from "assert";

describe("#indent()", () => {
it("should indent as necessary", () => {
const expected = `test\n test`;
doTest(expected, writer => {
writer.writeLine("test").indent().write("test");
});
});
});
describe("#newLineIfLastNotNewLine()", () => {

@@ -213,0 +223,0 @@ it("should do a newline if the last text was not a newline", () => {

@@ -23,3 +23,2 @@ {

"label-position": true,
"label-undefined": true,
"max-line-length": [ true, 170 ],

@@ -45,3 +44,2 @@ "member-ordering": [

"no-debugger": true,
"no-duplicate-key": true,
"no-shadowed-variable": true,

@@ -60,6 +58,3 @@ "no-duplicate-variable": true,

"no-trailing-whitespace": true,
"no-unreachable": true,
"no-unused-expression": true,
"no-unused-variable": true,
"no-use-before-declare": true,
"no-var-keyword": true,

@@ -66,0 +61,0 @@ "no-var-requires": true,

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