code-block-writer
Advanced tools
Comparing version 7.1.0 to 7.2.0
@@ -5,2 +5,12 @@ # Change Log | ||
<a name="7.2.0"></a> | ||
# [7.2.0](https://github.com/dsherret/code-block-writer/compare/v7.1.0...v7.2.0) (2018-05-28) | ||
### Features | ||
* Allow passing in a decimal indentation level. ([c77fa14](https://github.com/dsherret/code-block-writer/commit/c77fa14)) | ||
<a name="7.1.0"></a> | ||
@@ -7,0 +17,0 @@ # [7.1.0](https://github.com/dsherret/code-block-writer/compare/v7.0.0...v7.1.0) (2018-05-08) |
@@ -7,2 +7,3 @@ "use strict"; | ||
function CodeBlockWriter(opts) { | ||
if (opts === void 0) { opts = {}; } | ||
this._currentIndentation = 0; | ||
@@ -16,7 +17,7 @@ this._text = ""; | ||
this._isOnFirstLineOfBlock = true; | ||
this._newLine = (opts && opts.newLine) || "\n"; | ||
this._useTabs = (opts && opts.useTabs) || false; | ||
this._indentNumberOfSpaces = (opts && opts.indentNumberOfSpaces) || 4; | ||
this._newLine = opts.newLine || "\n"; | ||
this._useTabs = opts.useTabs || false; | ||
this._indentNumberOfSpaces = opts.indentNumberOfSpaces || 4; | ||
this._indentationText = getIndentationText(this._useTabs, this._indentNumberOfSpaces); | ||
this._quoteChar = (opts && opts.useSingleQuote) ? "'" : "\""; | ||
this._quoteChar = opts.useSingleQuote ? "'" : "\""; | ||
} | ||
@@ -88,4 +89,3 @@ /** | ||
this._isOnFirstLineOfBlock = false; | ||
if (this._currentIndentation > 0) | ||
this._currentIndentation--; | ||
this._currentIndentation = Math.max(0, this._currentIndentation - 1); | ||
}; | ||
@@ -383,3 +383,15 @@ CodeBlockWriter.prototype.conditionalWriteLine = function (condition, strOrFunc) { | ||
CodeBlockWriter.prototype._writeIndentation = function () { | ||
this._text += Array(this._currentIndentation + 1).join(this._indentationText); | ||
var flooredIndentation = Math.floor(this._currentIndentation); | ||
for (var i = 0; i < flooredIndentation; i++) | ||
this._text += this._indentationText; | ||
var overflow = this._currentIndentation - flooredIndentation; | ||
if (this._useTabs) { | ||
if (overflow > 0.5) | ||
this._text += this._indentationText; | ||
} | ||
else { | ||
var portion = Math.round(this._indentationText.length * overflow); | ||
for (var i = 0; i < portion; i++) | ||
this._text += this._indentationText[i]; | ||
} | ||
}; | ||
@@ -402,3 +414,3 @@ CodeBlockWriter.prototype._newLineIfNewLineOnNextWrite = function () { | ||
var _a = getSpacesAndTabsCount(countOrText), spacesCount = _a.spacesCount, tabsCount = _a.tabsCount; | ||
return tabsCount + Math.round(Math.max(0, spacesCount - 1) / this._indentNumberOfSpaces); | ||
return tabsCount + spacesCount / this._indentNumberOfSpaces; | ||
} | ||
@@ -405,0 +417,0 @@ else |
{ | ||
"name": "code-block-writer", | ||
"version": "7.1.0", | ||
"version": "7.2.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", |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
123755
694
0
12