code-block-writer
Advanced tools
Comparing version 6.10.1 to 6.11.0
@@ -6,16 +6,20 @@ # Change Log | ||
<a name="6.11.0"></a> | ||
# [6.11.0](https://github.com/dsherret/code-block-writer/compare/v6.9.0...v6.11.0) (2018-04-04) | ||
# [6.11.0](https://github.com/dsherret/code-block-writer/compare/v6.10.0...v6.11.0) (2018-04-07) | ||
### Bug Fixes | ||
### Features | ||
* Remove warning for now. ([ee36fac](https://github.com/dsherret/code-block-writer/commit/ee36fac)) | ||
* Add .isOnFirstLineOfBlock() ([b2a10c6](https://github.com/dsherret/code-block-writer/commit/b2a10c6)) | ||
### Features | ||
* Deprecate all XIfLastNotX methods to XIfLastNot. ([d6c31f1](https://github.com/dsherret/code-block-writer/commit/d6c31f1)) | ||
<a name="6.10.1"></a> | ||
# [6.10.1](https://github.com/dsherret/code-block-writer/compare/v6.9.0...v6.10.1) (2018-04-04) | ||
### Bug Fixes | ||
* Remove warning for now. ([ee36fac](https://github.com/dsherret/code-block-writer/commit/ee36fac)) | ||
<a name="6.10.0"></a> | ||
@@ -22,0 +26,0 @@ # [6.10.0](https://github.com/dsherret/code-block-writer/compare/v6.9.0...v6.10.0) (2018-04-03) |
@@ -13,2 +13,3 @@ export default class CodeBlockWriter { | ||
private _isInRegEx; | ||
private _isOnFirstLineOfBlock; | ||
constructor(opts?: { | ||
@@ -154,2 +155,6 @@ newLine?: string; | ||
/** | ||
* Gets if the writer is currently on the first line of the text, block, or indentation block. | ||
*/ | ||
isOnFirstLineOfBlock(): boolean; | ||
/** | ||
* Gets if the writer is currently in a string. | ||
@@ -156,0 +161,0 @@ */ |
@@ -14,2 +14,3 @@ "use strict"; | ||
this._isInRegEx = false; | ||
this._isOnFirstLineOfBlock = true; | ||
this._newLine = (opts && opts.newLine) || "\n"; | ||
@@ -71,4 +72,6 @@ this._useTabs = (opts && opts.useTabs) || false; | ||
this.newLineIfLastNot(); | ||
this._isOnFirstLineOfBlock = true; | ||
if (block != null) | ||
block(); | ||
this._isOnFirstLineOfBlock = false; | ||
if (this._currentIndentation > 0) | ||
@@ -232,2 +235,8 @@ this._currentIndentation--; | ||
/** | ||
* Gets if the writer is currently on the first line of the text, block, or indentation block. | ||
*/ | ||
CodeBlockWriter.prototype.isOnFirstLineOfBlock = function () { | ||
return this._isOnFirstLineOfBlock; | ||
}; | ||
/** | ||
* Gets if the writer is currently in a string. | ||
@@ -314,2 +323,3 @@ */ | ||
this._text += this._newLine; | ||
this._isOnFirstLineOfBlock = false; | ||
}; | ||
@@ -316,0 +326,0 @@ CodeBlockWriter.prototype._updateInternalState = function (str) { |
{ | ||
"name": "code-block-writer", | ||
"version": "6.10.1", | ||
"version": "6.11.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", |
@@ -75,2 +75,3 @@ code-block-writer | ||
* `isInComment()` - Gets if the writer is currently in a comment. | ||
* `isOnFirstLineOfBlock()` - Gets if the writer is currently on the first line of the text, block, or indentation block. | ||
* `isInString()` - Gets if the writer is currently in a string. | ||
@@ -77,0 +78,0 @@ * `isLastNewLine()` - Gets if the writer last wrote a newline. |
@@ -18,2 +18,3 @@ import {stringRepeat, escapeForWithinString} from "./utils/stringUtils"; | ||
private _isInRegEx = false; | ||
private _isOnFirstLineOfBlock = true; | ||
@@ -109,4 +110,6 @@ constructor(opts?: { newLine?: string; indentNumberOfSpaces?: number; useTabs?: boolean; useSingleQuote?: boolean; }) { | ||
this.newLineIfLastNot(); | ||
this._isOnFirstLineOfBlock = true; | ||
if (block != null) | ||
block(); | ||
this._isOnFirstLineOfBlock = false; | ||
if (this._currentIndentation > 0) | ||
@@ -304,2 +307,9 @@ this._currentIndentation--; | ||
/** | ||
* Gets if the writer is currently on the first line of the text, block, or indentation block. | ||
*/ | ||
isOnFirstLineOfBlock() { | ||
return this._isOnFirstLineOfBlock; | ||
} | ||
/** | ||
* Gets if the writer is currently in a string. | ||
@@ -398,2 +408,3 @@ */ | ||
this._text += this._newLine; | ||
this._isOnFirstLineOfBlock = false; | ||
} | ||
@@ -400,0 +411,0 @@ |
@@ -967,6 +967,44 @@ import * as assert from "assert"; | ||
it("should be true when a space", () => { | ||
doTest("t t\t\n\r", [false, false, true, false, false, false, false]); | ||
doTest("t t\t\r\n", [false, false, true, false, false, false, false]); | ||
}); | ||
}); | ||
describe("#isOnFirstLineOfBlock", () => { | ||
function doTest(str: string, expectedValues: boolean[]) { | ||
runSequentialCheck(str, expectedValues, writer => writer.isOnFirstLineOfBlock()); | ||
} | ||
it("should be true up until the new line", () => { | ||
doTest("t \t\n", [true, true, true, true, false]); | ||
}); | ||
it("should be true when on a new block", () => { | ||
const writer = new CodeBlockWriter(); | ||
writer.writeLine("testing"); | ||
assertState(false); | ||
writer.inlineBlock(() => { | ||
assertState(true); | ||
writer.newLine(); | ||
assertState(false); | ||
writer.indentBlock(() => { | ||
assertState(true); | ||
writer.write("testing\n"); | ||
assertState(false); | ||
writer.write("more\n"); | ||
assertState(false); | ||
}); | ||
assertState(false); | ||
writer.block(() => { | ||
assertState(true); | ||
}); | ||
assertState(false); | ||
}); | ||
assertState(false); | ||
function assertState(state: boolean) { | ||
assert.equal(writer.isOnFirstLineOfBlock(), state); | ||
} | ||
}); | ||
}); | ||
describe("#isLastNewLine", () => { | ||
@@ -973,0 +1011,0 @@ function doTest(str: string, expectedValues: boolean[], customWriter?: CodeBlockWriter) { |
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
193820
22
2228
82