code-block-writer
Advanced tools
Comparing version 6.12.0 to 6.13.0
@@ -5,2 +5,12 @@ # Change Log | ||
<a name="6.13.0"></a> | ||
# [6.13.0](https://github.com/dsherret/code-block-writer/compare/v6.12.0...v6.13.0) (2018-04-08) | ||
### Features | ||
* Add getOptions(). ([a58dc31](https://github.com/dsherret/code-block-writer/commit/a58dc31)) | ||
<a name="6.12.0"></a> | ||
@@ -7,0 +17,0 @@ # [6.12.0](https://github.com/dsherret/code-block-writer/compare/v6.11.0...v6.12.0) (2018-04-07) |
@@ -0,1 +1,7 @@ | ||
export interface Options { | ||
newLine: string; | ||
indentNumberOfSpaces: number; | ||
useTabs: boolean; | ||
useSingleQuote: boolean; | ||
} | ||
export default class CodeBlockWriter { | ||
@@ -14,9 +20,8 @@ private readonly _indentationText; | ||
private _isOnFirstLineOfBlock; | ||
constructor(opts?: { | ||
newLine?: string; | ||
indentNumberOfSpaces?: number; | ||
useTabs?: boolean; | ||
useSingleQuote?: boolean; | ||
}); | ||
constructor(opts?: Partial<Options>); | ||
/** | ||
* Gets the options. | ||
*/ | ||
getOptions(): Options; | ||
/** | ||
* Queues the indentation level for the next lines written. | ||
@@ -23,0 +28,0 @@ * @param indentationLevel - Indentation level to be at. |
@@ -21,2 +21,13 @@ "use strict"; | ||
} | ||
/** | ||
* Gets the options. | ||
*/ | ||
CodeBlockWriter.prototype.getOptions = function () { | ||
return { | ||
indentNumberOfSpaces: this._indentNumberOfSpaces, | ||
newLine: this._newLine, | ||
useTabs: this._useTabs, | ||
useSingleQuote: this._quoteChar === "'" | ||
}; | ||
}; | ||
CodeBlockWriter.prototype.queueIndentationLevel = function (countOrText) { | ||
@@ -23,0 +34,0 @@ this._queuedIndentation = this._getIndentationLevelFromArg(countOrText); |
@@ -1,2 +0,1 @@ | ||
export declare function escapeForWithinString(str: string, quoteKind: string): string; | ||
export declare function escapeChar(str: string, char: string): string; | ||
export {}; |
@@ -22,2 +22,3 @@ "use strict"; | ||
exports.es5StringRepeat = es5StringRepeat; | ||
/** @internal */ | ||
function escapeForWithinString(str, quoteKind) { | ||
@@ -27,2 +28,3 @@ return escapeChar(str, quoteKind).replace(/(\r?\n)/g, "\\$1"); | ||
exports.escapeForWithinString = escapeForWithinString; | ||
/** @internal */ | ||
function escapeChar(str, char) { | ||
@@ -29,0 +31,0 @@ if (char.length !== 1) |
{ | ||
"name": "code-block-writer", | ||
"version": "6.12.0", | ||
"version": "6.13.0", | ||
"description": "A simple code writer that assists with formatting and visualizing blocks of code.", | ||
@@ -43,4 +43,4 @@ "main": "dist/code-block-writer.js", | ||
"tslint": "^5.6.0", | ||
"typescript": "^2.5.2" | ||
"typescript": "^2.8.1" | ||
} | ||
} |
@@ -82,2 +82,3 @@ code-block-writer | ||
* `getLastChar()` - Gets the last character written. | ||
* `getOptions()` - Gets the writer options. | ||
* `toString()` - Gets the string. |
import {stringRepeat, escapeForWithinString} from "./utils/stringUtils"; | ||
import {CommentChar} from "./CommentChar"; | ||
export interface Options { | ||
newLine: string; | ||
indentNumberOfSpaces: number; | ||
useTabs: boolean; | ||
useSingleQuote: boolean; | ||
} | ||
export default class CodeBlockWriter { | ||
@@ -20,3 +27,3 @@ private readonly _indentationText: string; | ||
constructor(opts?: { newLine?: string; indentNumberOfSpaces?: number; useTabs?: boolean; useSingleQuote?: boolean; }) { | ||
constructor(opts?: Partial<Options>) { | ||
this._newLine = (opts && opts.newLine) || "\n"; | ||
@@ -30,2 +37,14 @@ this._useTabs = (opts && opts.useTabs) || false; | ||
/** | ||
* Gets the options. | ||
*/ | ||
getOptions(): Options { | ||
return { | ||
indentNumberOfSpaces: this._indentNumberOfSpaces, | ||
newLine: this._newLine, | ||
useTabs: this._useTabs, | ||
useSingleQuote: this._quoteChar === "'" | ||
}; | ||
} | ||
/** | ||
* Queues the indentation level for the next lines written. | ||
@@ -32,0 +51,0 @@ * @param indentationLevel - Indentation level to be at. |
@@ -1125,1 +1125,13 @@ import * as assert from "assert"; | ||
}); | ||
describe("#getOptions", () => { | ||
it("should have the options that were passed in", () => { | ||
const writer = new CodeBlockWriter({ useTabs: true, indentNumberOfSpaces: 8, newLine: "\r\n", useSingleQuote: false }); | ||
assert.deepEqual(writer.getOptions(), { | ||
useTabs: true, | ||
indentNumberOfSpaces: 8, | ||
newLine: "\r\n", | ||
useSingleQuote: false | ||
}); | ||
}); | ||
}); |
@@ -21,2 +21,3 @@ /** @internal */ | ||
/** @internal */ | ||
export function escapeForWithinString(str: string, quoteKind: string) { | ||
@@ -26,2 +27,3 @@ return escapeChar(str, quoteKind).replace(/(\r?\n)/g, "\\$1"); | ||
/** @internal */ | ||
export function escapeChar(str: string, char: string) { | ||
@@ -28,0 +30,0 @@ if (char.length !== 1) |
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
197818
2329
84