code-block-writer
Advanced tools
Comparing version 9.4.1 to 10.0.0
@@ -5,2 +5,24 @@ # Change Log | ||
<a name="10.0.0"></a> | ||
# [10.0.0](https://github.com/dsherret/code-block-writer/compare/v9.4.1...v10.0.0) (2019-09-02) | ||
### Bug Fixes | ||
* [#32](https://github.com/dsherret/code-block-writer/issues/32) - Doing a non-escaped newline within a string literal would not properly update the writer state. ([a155e47](https://github.com/dsherret/code-block-writer/commit/a155e47)) | ||
### Code Refactoring | ||
* Rename `indentBlock` to `indent`. ([34fd843](https://github.com/dsherret/code-block-writer/commit/34fd843)) | ||
* Rename `withHangingIndentation` to `hangingIndent`. ([f87cb91](https://github.com/dsherret/code-block-writer/commit/f87cb91)) | ||
### BREAKING CHANGES | ||
* `indentBlock` is now merged with `indent`. | ||
* `withHangingIndentation` is now `hangingIndent`. | ||
<a name="9.4.1"></a> | ||
@@ -7,0 +29,0 @@ ## [9.4.1](https://github.com/dsherret/code-block-writer/compare/v9.4.0...v9.4.1) (2019-07-16) |
@@ -53,3 +53,3 @@ /** | ||
*/ | ||
withHangingIndentation(action: () => void): this; | ||
hangingIndent(action: () => void): this; | ||
/** | ||
@@ -59,3 +59,3 @@ * Writes the text within the provided action with hanging indentation unless writing a block. | ||
*/ | ||
withHangingIndentationUnlessBlock(action: () => void): this; | ||
hangingIndentUnlessBlock(action: () => void): this; | ||
/** | ||
@@ -101,6 +101,10 @@ * Sets the current indentation level. | ||
/** | ||
* Indents the code one level for the current line. | ||
*/ | ||
indent(times?: number): this; | ||
/** | ||
* Indents a block of code. | ||
* @param block - Block to indent. | ||
*/ | ||
indentBlock(block: () => void): this; | ||
indent(block: () => void): this; | ||
/** | ||
@@ -141,6 +145,2 @@ * Conditionally writes a line of text. | ||
/** | ||
* Indents the code one level for the current line. | ||
*/ | ||
indent(times?: number): this; | ||
/** | ||
* Writes a newline if the condition is true. | ||
@@ -147,0 +147,0 @@ * @param condition - Condition to evaluate. |
@@ -58,3 +58,3 @@ "use strict"; | ||
*/ | ||
withHangingIndentation(action) { | ||
hangingIndent(action) { | ||
return this._withResetIndentation(() => this.queueIndentationLevel(this.getIndentationLevel() + 1), action); | ||
@@ -66,3 +66,3 @@ } | ||
*/ | ||
withHangingIndentationUnlessBlock(action) { | ||
hangingIndentUnlessBlock(action) { | ||
return this._withResetIndentation(() => { | ||
@@ -121,11 +121,13 @@ this.queueIndentationLevel(this.getIndentationLevel() + 1); | ||
} | ||
/** | ||
* Indents a block of code. | ||
* @param block - Block to indent. | ||
*/ | ||
indentBlock(block) { | ||
this._indentBlockInternal(block); | ||
if (!this.isLastNewLine()) | ||
this._newLineOnNextWrite = true; | ||
return this; | ||
indent(timesOrBlock = 1) { | ||
if (typeof timesOrBlock === "number") { | ||
this._newLineIfNewLineOnNextWrite(); | ||
return this.write(this._indentationText.repeat(timesOrBlock)); | ||
} | ||
else { | ||
this._indentBlockInternal(timesOrBlock); | ||
if (!this.isLastNewLine()) | ||
this._newLineOnNextWrite = true; | ||
return this; | ||
} | ||
} | ||
@@ -193,9 +195,2 @@ /** @internal */ | ||
/** | ||
* Indents the code one level for the current line. | ||
*/ | ||
indent(times = 1) { | ||
this._newLineIfNewLineOnNextWrite(); | ||
return this.write(this._indentationText.repeat(times)); | ||
} | ||
/** | ||
* Writes a newline if the condition is true. | ||
@@ -319,8 +314,6 @@ * @param condition - Condition to evaluate. | ||
const { index, localIndex } = getArrayIndexAndLocalIndex(); | ||
if (localIndex === 0) { | ||
if (localIndex === 0) | ||
texts.splice(index, 0, text); | ||
} | ||
else if (localIndex === texts[index].length) { | ||
else if (localIndex === texts[index].length) | ||
texts.splice(index + 1, 0, text); | ||
} | ||
else { | ||
@@ -411,4 +404,5 @@ const textItem = texts[index]; | ||
} | ||
else if (currentChar !== "\r") | ||
else if (currentChar !== "\r") { | ||
return false; | ||
} | ||
} | ||
@@ -510,2 +504,5 @@ } | ||
this._currentCommentChar = undefined; | ||
const lastStringCharOnStack = this._stringCharStack[this._stringCharStack.length - 1]; | ||
if ((lastStringCharOnStack === "\"" || lastStringCharOnStack === "'") && this.getLastChar() !== "\\") | ||
this._stringCharStack.pop(); | ||
this._internalWrite(this._newLine); | ||
@@ -650,4 +647,5 @@ this._isOnFirstLineOfBlock = false; | ||
} | ||
else | ||
else { | ||
throw new Error("Argument provided must be a string or number."); | ||
} | ||
} | ||
@@ -654,0 +652,0 @@ /** @internal */ |
{ | ||
"name": "code-block-writer", | ||
"version": "9.4.1", | ||
"version": "10.0.0", | ||
"description": "A simple code writer that assists with formatting and visualizing blocks of code.", | ||
@@ -9,4 +9,5 @@ "main": "dist/code-block-writer.js", | ||
"test": "nyc --reporter=lcov mocha --opts mocha.opts", | ||
"test:debug": "cross-env TS_NODE_TRANSPILE_ONLY=\"true\" mocha --opts mocha.opts --inspect-brk", | ||
"build": "rimraf dist && tsc", | ||
"lint": "tslint src/**/*.ts", | ||
"format": "dprint \"**/*{.ts|.json}\"", | ||
"dopublish": "npm run build && echo \"Run: npm publish --otp\"" | ||
@@ -47,12 +48,13 @@ }, | ||
"@types/mocha": "^5.2.7", | ||
"@types/node": "^12.6.3", | ||
"@types/node": "^12.6.8", | ||
"chai": "^4.2.0", | ||
"coveralls": "^3.0.5", | ||
"chai": "^4.2.0", | ||
"mocha": "^6.1.4", | ||
"cross-env": "^5.2.1", | ||
"dprint": "^0.2.0", | ||
"mocha": "^6.2.0", | ||
"nyc": "^14.1.1", | ||
"source-map-support": "^0.5.12", | ||
"ts-node": "^8.3.0", | ||
"tslint": "^5.18.0", | ||
"typescript": "^3.5.3" | ||
} | ||
} |
@@ -63,3 +63,3 @@ code-block-writer | ||
* `indent(times?: number)` - Indents the current line. Optionally indents multiple times when providing a number. | ||
* `indentBlock(block?: () => void)` - Indents a block of code. | ||
* `indent(block?: () => void)` - Indents a block of code. | ||
* `space(times?: number)` - Writes a space. Optionally writes multiple spaces when providing a number. | ||
@@ -83,4 +83,4 @@ * `spaceIfLastNot()` - Writes a space if the last was not a space. | ||
* `queueIndentationLevel(whitespaceText: string)` - Queues an indentation level to be used once a new line is written based on the provided whitespace text. | ||
* `withHangingIndentation(action: () => void)` - Writes the code within the action with hanging indentation. | ||
* `withHangingIndentationUnlessBlock(action: () => void)` - Writes the code within the action with hanging indentation unless a block is written going from the first line to the second. | ||
* `hangingIndent(action: () => void)` - Writes the code within the action with hanging indentation. | ||
* `hangingIndentUnlessBlock(action: () => void)` - Writes the code within the action with hanging indentation unless a block is written going from the first line to the second. | ||
* `closeComment()` - Writes text to exit a comment if in a comment. | ||
@@ -87,0 +87,0 @@ * `unsafeInsert(pos: number, text: string)` - Inserts text into the writer. This will not update the writer's state. Read more in its jsdoc. |
Sorry, the diff of this file is not supported yet
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
128824
12
990