修改后台权限

This commit is contained in:
yoyuzh
2026-03-24 14:30:59 +08:00
parent 00f902f475
commit b2d9db7be9
9310 changed files with 1246063 additions and 48 deletions

22
node_modules/code-block-writer/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,22 @@
The MIT License (MIT)
Copyright (c) 2015-2024 David Sherret
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

119
node_modules/code-block-writer/README.md generated vendored Normal file
View File

@@ -0,0 +1,119 @@
# code-block-writer
[![npm version](https://badge.fury.io/js/code-block-writer.svg)](https://badge.fury.io/js/code-block-writer)
[![CI](https://github.com/dsherret/code-block-writer/workflows/CI/badge.svg)](https://github.com/dsherret/code-block-writer/actions?query=workflow%3ACI)
[![JSR](https://jsr.io/badges/@david/code-block-writer)](https://jsr.io/@david/code-block-writer)
[![stable](http://badges.github.io/stability-badges/dist/stable.svg)](http://github.com/badges/stability-badges)
Code writer for JavaScript and TypeScript code.
With Deno:
```ts
deno add jsr:@david/code-block-writer
```
Or with Node:
```
npm install --save code-block-writer
```
## Example
<!-- dprint-ignore -->
```typescript
// import CodeBlockWriter from "code-block-writer"; // for npm
import CodeBlockWriter from "@david/code-block-writer";
const writer = new CodeBlockWriter({
// optional options
newLine: "\r\n", // default: "\n"
indentNumberOfSpaces: 2, // default: 4
useTabs: false, // default: false
useSingleQuote: true // default: false
});
writer.write("class MyClass extends OtherClass").block(() => {
writer.writeLine(`@MyDecorator(1, 2)`);
writer.write(`myMethod(myParam: any)`).block(() => {
writer.write("return this.post(").quote("myArgument").write(");");
});
});
console.log(writer.toString());
```
Outputs (using "\r\n" for newlines):
<!-- dprint-ignore -->
```js
class MyClass extends OtherClass {
@MyDecorator(1, 2)
myMethod(myParam: any) {
return this.post('myArgument');
}
}
```
## Methods
- `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(text: string)` - Writes some text and adds a newline.
- `newLine()` - Writes a newline.
- `newLineIfLastNot()` - Writes a newline if what was written last wasn't a newline.
- `blankLine()` - Writes a blank line. Does not allow consecutive blank lines.
- `blankLineIfLastNot()` - Writes a blank line if what was written last wasn't a blank line.
- `quote()` - Writes a quote character.
- `quote(text: string)` - Writes text surrounded in quotes.
- `indent(times?: number)` - Indents the current line. Optionally indents multiple times when providing a number.
- `indent(block?: () => void)` - Indents a block of code.
- `space(times?: number)` - Writes a space. Optionally writes multiple spaces when providing a number.
- `spaceIfLastNot()` - Writes a space if the last was not a space.
- `tab(times?: number)` - Writes a tab. Optionally writes multiple tabs when providing a number.
- `tabIfLastNot()` - Writes a tab if the last was not a tab.
- `write(text: string)` - Writes some text.
- `conditionalNewLine(condition: boolean)` - Writes a newline if the condition is matched.
- `conditionalBlankLine(condition: boolean)` - Writes a blank line if the condition is matched.
- `conditionalWrite(condition: boolean, text: string)` - Writes if the condition is matched.
- `conditionalWrite(condition: boolean, textFunc: () => string)` - Writes if the condition is matched.
- `conditionalWriteLine(condition: boolean, text: string)` - Writes some text and adds a newline if the condition is matched.
- `conditionalWriteLine(condition: boolean, textFunc: () => string)` - Writes some text and adds a newline if the condition is matched.
- `setIndentationLevel(indentationLevel: number)` - Sets the current indentation level.
- `setIndentationLevel(whitespaceText: string)` - Sets the current indentation level based on the provided whitespace text.
- `withIndentationLevel(indentationLevel: number, action: () => void)` - Sets the indentation level within the provided action.
- `withIndentationLevel(whitespaceText: string, action: () => void)` - Sets the indentation level based on the provided whitespace text within the action.
- `getIndentationLevel()` - Gets the current indentation level.
- `queueIndentationLevel(indentationLevel: number)` - Queues an indentation level to be used once a new line is written.
- `queueIndentationLevel(whitespaceText: string)` - Queues an indentation level to be used once a new line is written based on the provided whitespace text.
- `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.
- `unsafeInsert(pos: number, text: string)` - Inserts text into the writer. This will not update the writer's state. Read more in its jsdoc.
- `isInComment()` - Gets if the writer is currently in a comment.
- `isAtStartOfFirstLineOfBlock()` - Gets if the writer is currently at the start of the first line of the text, block, or indentation block.
- `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.
- `isLastNewLine()` - Gets if the writer last wrote a newline.
- `isLastBlankLine()` - Gets if the writer last wrote a blank line.
- `isLastSpace()` - Gets if the writer last wrote a space.
- `isLastTab()` - Gets if the writer last wrote a tab.
- `getLastChar()` - Gets the last character written.
- `endsWith(text: string)` - Gets if the writer ends with the provided text.
- `iterateLastChars<T>(action: (char: string, index: number) => T | undefined): T | undefined` - Iterates over the writer's characters in reverse order, stopping once a non-null or undefined value is returned and returns that value.
- `iterateLastCharCodes<T>(action: (charCode: number, index: number) => T | undefined): T | undefined` - A slightly faster version of `iterateLastChars` that doesn't allocate a string per character.
- `getOptions()` - Gets the writer options.
- `toString()` - Gets the string.
## Other Features
- Does not indent within strings.
- Escapes newlines within double and single quotes created with `.quote(text)`.
## C# Version
See [CodeBlockWriterSharp](https://github.com/dsherret/CodeBlockWriterSharp).

View File

@@ -0,0 +1 @@
{"version":3,"file":"_dnt.test_shims.d.ts","sourceRoot":"","sources":["../src/_dnt.test_shims.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAKvC,eAAO,MAAM,aAAa;;CAA2C,CAAC"}

View File

@@ -0,0 +1 @@
{"version":3,"file":"_test.deps.d.ts","sourceRoot":"","sources":["../src/_test.deps.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,6CAA6C,CAAC;AAE3E,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC"}

View File

@@ -0,0 +1 @@
{"version":3,"file":"_test_suite.d.ts","sourceRoot":"","sources":["../../../../../src/deps/deno.land/std@0.193.0/testing/_test_suite.ts"],"names":[],"mappings":"AACA,wEAAwE;AACxE,OAAO,KAAK,OAAO,MAAM,gCAAgC,CAAC;AAE1D,MAAM,WAAW,kBAAkB,CAAC,CAAC,CAAE,SAAQ,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,cAAc,EAAE,IAAI,CAAC;IACpF,EAAE,CAAC,EAAE,MAAM,IAAI,CAAC;IAChB;;;;OAIG;IACH,KAAK,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;IACrB,kEAAkE;IAClE,SAAS,CAAC,EACN,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,GACnC,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC;IAC1C,oEAAoE;IACpE,QAAQ,CAAC,EACL,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAA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O,CAAC,IAAI,CAAC,WAAW;WAqEhB,OAAO,CAAC,CAAC,EACpB,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,WAAW,EAC3B,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,WAAW,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,EAClE,OAAO,EAAE,CAAC,EACV,WAAW,SAAI;CA8BlB"}

File diff suppressed because one or more lines are too long

276
node_modules/code-block-writer/esm/mod.d.ts generated vendored Normal file
View File

@@ -0,0 +1,276 @@
/**
* Options for the writer.
*/
export interface Options {
/**
* Newline character.
* @remarks Defaults to \n.
*/
newLine: "\n" | "\r\n";
/**
* Number of spaces to indent when `useTabs` is false.
* @remarks Defaults to 4.
*/
indentNumberOfSpaces: number;
/**
* Whether to use tabs (true) or spaces (false).
* @remarks Defaults to false.
*/
useTabs: boolean;
/**
* Whether to use a single quote (true) or double quote (false).
* @remarks Defaults to false.
*/
useSingleQuote: boolean;
}
/**
* Code writer that assists with formatting and visualizing blocks of JavaScript or TypeScript code.
*/
export default class CodeBlockWriter {
/**
* Constructor.
* @param opts - Options for the writer.
*/
constructor(opts?: Partial<Options>);
/**
* Gets the options.
*/
getOptions(): Options;
/**
* Queues the indentation level for the next lines written.
* @param indentationLevel - Indentation level to queue.
*/
queueIndentationLevel(indentationLevel: number): this;
/**
* Queues the indentation level for the next lines written using the provided indentation text.
* @param whitespaceText - Gets the indentation level from the indentation text.
*/
queueIndentationLevel(whitespaceText: string): this;
/**
* Writes the text within the provided action with hanging indentation.
* @param action - Action to perform with hanging indentation.
*/
hangingIndent(action: () => void): this;
/**
* Writes the text within the provided action with hanging indentation unless writing a block.
* @param action - Action to perform with hanging indentation unless a block is written.
*/
hangingIndentUnlessBlock(action: () => void): this;
/**
* Sets the current indentation level.
* @param indentationLevel - Indentation level to be at.
*/
setIndentationLevel(indentationLevel: number): this;
/**
* Sets the current indentation using the provided indentation text.
* @param whitespaceText - Gets the indentation level from the indentation text.
*/
setIndentationLevel(whitespaceText: string): this;
/**
* Sets the indentation level within the provided action and restores the writer's indentation
* state afterwards.
* @remarks Restores the writer's state after the action.
* @param indentationLevel - Indentation level to set.
* @param action - Action to perform with the indentation.
*/
withIndentationLevel(indentationLevel: number, action: () => void): this;
/**
* Sets the indentation level with the provided indentation text within the provided action
* and restores the writer's indentation state afterwards.
* @param whitespaceText - Gets the indentation level from the indentation text.
* @param action - Action to perform with the indentation.
*/
withIndentationLevel(whitespaceText: string, action: () => void): this;
/**
* Gets the current indentation level.
*/
getIndentationLevel(): number;
/**
* Writes a block using braces.
* @param block - Write using the writer within this block.
*/
block(block?: () => void): this;
/**
* Writes an inline block with braces.
* @param block - Write using the writer within this block.
*/
inlineBlock(block?: () => void): this;
/**
* Indents the code one level for the current line.
*/
indent(times?: number): this;
/**
* Indents a block of code.
* @param block - Block to indent.
*/
indent(block: () => void): this;
/**
* Conditionally writes a line of text.
* @param condition - Condition to evaluate.
* @param textFunc - A function that returns a string to write if the condition is true.
*/
conditionalWriteLine(condition: boolean | undefined, textFunc: () => string): this;
/**
* Conditionally writes a line of text.
* @param condition - Condition to evaluate.
* @param text - Text to write if the condition is true.
*/
conditionalWriteLine(condition: boolean | undefined, text: string): this;
/**
* Writes a line of text.
* @param text - String to write.
*/
writeLine(text: string): this;
/**
* Writes a newline if the last line was not a newline.
*/
newLineIfLastNot(): this;
/**
* Writes a blank line if the last written text was not a blank line.
*/
blankLineIfLastNot(): this;
/**
* Writes a blank line if the condition is true.
* @param condition - Condition to evaluate.
*/
conditionalBlankLine(condition: boolean | undefined): this;
/**
* Writes a blank line.
*/
blankLine(): this;
/**
* Writes a newline if the condition is true.
* @param condition - Condition to evaluate.
*/
conditionalNewLine(condition: boolean | undefined): this;
/**
* Writes a newline.
*/
newLine(): this;
/**
* Writes a quote character.
*/
quote(): this;
/**
* Writes text surrounded in quotes.
* @param text - Text to write.
*/
quote(text: string): this;
/**
* Writes a space if the last character was not a space.
*/
spaceIfLastNot(): this;
/**
* Writes a space.
* @param times - Number of times to write a space.
*/
space(times?: number): this;
/**
* Writes a tab if the last character was not a tab.
*/
tabIfLastNot(): this;
/**
* Writes a tab.
* @param times - Number of times to write a tab.
*/
tab(times?: number): this;
/**
* Conditionally writes text.
* @param condition - Condition to evaluate.
* @param textFunc - A function that returns a string to write if the condition is true.
*/
conditionalWrite(condition: boolean | undefined, textFunc: () => string): this;
/**
* Conditionally writes text.
* @param condition - Condition to evaluate.
* @param text - Text to write if the condition is true.
*/
conditionalWrite(condition: boolean | undefined, text: string): this;
/**
* Writes the provided text.
* @param text - Text to write.
*/
write(text: string): this;
/**
* Writes text to exit a comment if in a comment.
*/
closeComment(): this;
/**
* Inserts text at the provided position.
*
* This method is "unsafe" because it won't update the state of the writer unless
* inserting at the end position. It is biased towards being fast at inserting closer
* to the start or end, but slower to insert in the middle. Only use this if
* absolutely necessary.
* @param pos - Position to insert at.
* @param text - Text to insert.
*/
unsafeInsert(pos: number, text: string): this;
/**
* Gets the length of the string in the writer.
*/
getLength(): number;
/**
* Gets if the writer is currently in a comment.
*/
isInComment(): boolean;
/**
* Gets if the writer is currently at the start of the first line of the text, block, or indentation block.
*/
isAtStartOfFirstLineOfBlock(): boolean;
/**
* 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.
*/
isInString(): boolean;
/**
* Gets if the last chars written were for a newline.
*/
isLastNewLine(): boolean;
/**
* Gets if the last chars written were for a blank line.
*/
isLastBlankLine(): boolean;
/**
* Gets if the last char written was a space.
*/
isLastSpace(): boolean;
/**
* Gets if the last char written was a tab.
*/
isLastTab(): boolean;
/**
* Gets the last char written.
*/
getLastChar(): string | undefined;
/**
* Gets if the writer ends with the provided text.
* @param text - Text to check if the writer ends with the provided text.
*/
endsWith(text: string): boolean;
/**
* Iterates over the writer characters in reverse order. The iteration stops when a non-null or
* undefined value is returned from the action. The returned value is then returned by the method.
*
* @remarks It is much more efficient to use this method rather than `#toString()` since `#toString()`
* will combine the internal array into a string.
*/
iterateLastChars<T>(action: (char: string, index: number) => T | undefined): T | undefined;
/**
* Iterates over the writer character char codes in reverse order. The iteration stops when a non-null or
* undefined value is returned from the action. The returned value is then returned by the method.
*
* @remarks It is much more efficient to use this method rather than `#toString()` since `#toString()`
* will combine the internal array into a string. Additionally, this is slightly more efficient that
* `iterateLastChars` as this won't allocate a string per character.
*/
iterateLastCharCodes<T>(action: (charCode: number, index: number) => T | undefined): T | undefined;
/**
* Gets the writer's text.
*/
toString(): string;
}
//# sourceMappingURL=mod.d.ts.map

1
node_modules/code-block-writer/esm/mod.d.ts.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAQA;;GAEG;AACH,MAAM,WAAW,OAAO;IACtB;;;OAGG;IACH,OAAO,EAAE,IAAI,GAAG,MAAM,CAAC;IACvB;;;OAGG;IACH,oBAAoB,EAAE,MAAM,CAAC;IAC7B;;;OAGG;IACH,OAAO,EAAE,OAAO,CAAC;IACjB;;;OAGG;IACH,cAAc,EAAE,OAAO,CAAC;CACzB;AA+BD;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,eAAe;IAkClC;;;OAGG;gBACS,IAAI,GAAE,OAAO,CAAC,OAAO,CAAM;IAQvC;;OAEG;IACH,UAAU,IAAI,OAAO;IASrB;;;OAGG;IACH,qBAAqB,CAAC,gBAAgB,EAAE,MAAM,GAAG,IAAI;IACrD;;;OAGG;IACH,qBAAqB,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI;IASnD;;;OAGG;IACH,aAAa,CAAC,MAAM,EAAE,MAAM,IAAI,GAAG,IAAI;IAIvC;;;OAGG;IACH,wBAAwB,CAAC,MAAM,EAAE,MAAM,IAAI,GAAG,IAAI;IAOlD;;;OAGG;IACH,mBAAmB,CAAC,gBAAgB,EAAE,MAAM,GAAG,IAAI;IACn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I1F;;;;;;;OAOG;IACH,oBAAoB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,CAAC,GAAG,SAAS,GAAG,CAAC,GAAG,SAAS;IAelG;;OAEG;IACH,QAAQ,IAAI,MAAM;CAyPnB"}

887
node_modules/code-block-writer/esm/mod.js generated vendored Normal file
View File

@@ -0,0 +1,887 @@
import { escapeForWithinString, getStringFromStrOrFunc } from "./utils/string_utils.js";
/** @internal */
var CommentChar;
(function (CommentChar) {
CommentChar[CommentChar["Line"] = 0] = "Line";
CommentChar[CommentChar["Star"] = 1] = "Star";
})(CommentChar || (CommentChar = {}));
// Using the char codes is a performance improvement (about 5.5% faster when writing because it eliminates additional string allocations).
const CHARS = {
BACK_SLASH: "\\".charCodeAt(0),
FORWARD_SLASH: "/".charCodeAt(0),
NEW_LINE: "\n".charCodeAt(0),
CARRIAGE_RETURN: "\r".charCodeAt(0),
ASTERISK: "*".charCodeAt(0),
DOUBLE_QUOTE: "\"".charCodeAt(0),
SINGLE_QUOTE: "'".charCodeAt(0),
BACK_TICK: "`".charCodeAt(0),
OPEN_BRACE: "{".charCodeAt(0),
CLOSE_BRACE: "}".charCodeAt(0),
DOLLAR_SIGN: "$".charCodeAt(0),
SPACE: " ".charCodeAt(0),
TAB: "\t".charCodeAt(0),
};
const isCharToHandle = new Set([
CHARS.BACK_SLASH,
CHARS.FORWARD_SLASH,
CHARS.NEW_LINE,
CHARS.CARRIAGE_RETURN,
CHARS.ASTERISK,
CHARS.DOUBLE_QUOTE,
CHARS.SINGLE_QUOTE,
CHARS.BACK_TICK,
CHARS.OPEN_BRACE,
CHARS.CLOSE_BRACE,
]);
/**
* Code writer that assists with formatting and visualizing blocks of JavaScript or TypeScript code.
*/
class CodeBlockWriter {
/**
* Constructor.
* @param opts - Options for the writer.
*/
constructor(opts = {}) {
/** @internal */
Object.defineProperty(this, "_indentationText", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
/** @internal */
Object.defineProperty(this, "_newLine", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
/** @internal */
Object.defineProperty(this, "_useTabs", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
/** @internal */
Object.defineProperty(this, "_quoteChar", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
/** @internal */
Object.defineProperty(this, "_indentNumberOfSpaces", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
/** @internal */
Object.defineProperty(this, "_currentIndentation", {
enumerable: true,
configurable: true,
writable: true,
value: 0
});
/** @internal */
Object.defineProperty(this, "_queuedIndentation", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
/** @internal */
Object.defineProperty(this, "_queuedOnlyIfNotBlock", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
/** @internal */
Object.defineProperty(this, "_length", {
enumerable: true,
configurable: true,
writable: true,
value: 0
});
/** @internal */
Object.defineProperty(this, "_newLineOnNextWrite", {
enumerable: true,
configurable: true,
writable: true,
value: false
});
/** @internal */
Object.defineProperty(this, "_currentCommentChar", {
enumerable: true,
configurable: true,
writable: true,
value: undefined
});
/** @internal */
Object.defineProperty(this, "_stringCharStack", {
enumerable: true,
configurable: true,
writable: true,
value: []
});
/** @internal */
Object.defineProperty(this, "_isInRegEx", {
enumerable: true,
configurable: true,
writable: true,
value: false
});
/** @internal */
Object.defineProperty(this, "_isOnFirstLineOfBlock", {
enumerable: true,
configurable: true,
writable: true,
value: true
});
// An array of strings is used rather than a single string because it was
// found to be ~11x faster when printing a 10K line file (~11s to ~1s).
/** @internal */
Object.defineProperty(this, "_texts", {
enumerable: true,
configurable: true,
writable: true,
value: []
});
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.useSingleQuote ? "'" : `"`;
}
/**
* Gets the options.
*/
getOptions() {
return {
indentNumberOfSpaces: this._indentNumberOfSpaces,
newLine: this._newLine,
useTabs: this._useTabs,
useSingleQuote: this._quoteChar === "'",
};
}
queueIndentationLevel(countOrText) {
this._queuedIndentation = this._getIndentationLevelFromArg(countOrText);
this._queuedOnlyIfNotBlock = undefined;
return this;
}
/**
* Writes the text within the provided action with hanging indentation.
* @param action - Action to perform with hanging indentation.
*/
hangingIndent(action) {
return this._withResetIndentation(() => this.queueIndentationLevel(this.getIndentationLevel() + 1), action);
}
/**
* Writes the text within the provided action with hanging indentation unless writing a block.
* @param action - Action to perform with hanging indentation unless a block is written.
*/
hangingIndentUnlessBlock(action) {
return this._withResetIndentation(() => {
this.queueIndentationLevel(this.getIndentationLevel() + 1);
this._queuedOnlyIfNotBlock = true;
}, action);
}
setIndentationLevel(countOrText) {
this._currentIndentation = this._getIndentationLevelFromArg(countOrText);
return this;
}
withIndentationLevel(countOrText, action) {
return this._withResetIndentation(() => this.setIndentationLevel(countOrText), action);
}
/** @internal */
_withResetIndentation(setStateAction, writeAction) {
const previousState = this._getIndentationState();
setStateAction();
try {
writeAction();
}
finally {
this._setIndentationState(previousState);
}
return this;
}
/**
* Gets the current indentation level.
*/
getIndentationLevel() {
return this._currentIndentation;
}
/**
* Writes a block using braces.
* @param block - Write using the writer within this block.
*/
block(block) {
this._newLineIfNewLineOnNextWrite();
if (this.getLength() > 0 && !this.isLastNewLine()) {
this.spaceIfLastNot();
}
this.inlineBlock(block);
this._newLineOnNextWrite = true;
return this;
}
/**
* Writes an inline block with braces.
* @param block - Write using the writer within this block.
*/
inlineBlock(block) {
this._newLineIfNewLineOnNextWrite();
this.write("{");
this._indentBlockInternal(block);
this.newLineIfLastNot().write("}");
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;
}
}
/** @internal */
_indentBlockInternal(block) {
if (this.getLastChar() != null) {
this.newLineIfLastNot();
}
this._currentIndentation++;
this._isOnFirstLineOfBlock = true;
if (block != null) {
block();
}
this._isOnFirstLineOfBlock = false;
this._currentIndentation = Math.max(0, this._currentIndentation - 1);
}
conditionalWriteLine(condition, strOrFunc) {
if (condition) {
this.writeLine(getStringFromStrOrFunc(strOrFunc));
}
return this;
}
/**
* Writes a line of text.
* @param text - String to write.
*/
writeLine(text) {
this._newLineIfNewLineOnNextWrite();
if (this.getLastChar() != null) {
this.newLineIfLastNot();
}
this._writeIndentingNewLines(text);
this.newLine();
return this;
}
/**
* Writes a newline if the last line was not a newline.
*/
newLineIfLastNot() {
this._newLineIfNewLineOnNextWrite();
if (!this.isLastNewLine()) {
this.newLine();
}
return this;
}
/**
* Writes a blank line if the last written text was not a blank line.
*/
blankLineIfLastNot() {
if (!this.isLastBlankLine()) {
this.blankLine();
}
return this;
}
/**
* Writes a blank line if the condition is true.
* @param condition - Condition to evaluate.
*/
conditionalBlankLine(condition) {
if (condition) {
this.blankLine();
}
return this;
}
/**
* Writes a blank line.
*/
blankLine() {
return this.newLineIfLastNot().newLine();
}
/**
* Writes a newline if the condition is true.
* @param condition - Condition to evaluate.
*/
conditionalNewLine(condition) {
if (condition) {
this.newLine();
}
return this;
}
/**
* Writes a newline.
*/
newLine() {
this._newLineOnNextWrite = false;
this._baseWriteNewline();
return this;
}
quote(text) {
this._newLineIfNewLineOnNextWrite();
this._writeIndentingNewLines(text == null ? this._quoteChar : this._quoteChar + escapeForWithinString(text, this._quoteChar) + this._quoteChar);
return this;
}
/**
* Writes a space if the last character was not a space.
*/
spaceIfLastNot() {
this._newLineIfNewLineOnNextWrite();
if (!this.isLastSpace()) {
this._writeIndentingNewLines(" ");
}
return this;
}
/**
* Writes a space.
* @param times - Number of times to write a space.
*/
space(times = 1) {
this._newLineIfNewLineOnNextWrite();
this._writeIndentingNewLines(" ".repeat(times));
return this;
}
/**
* Writes a tab if the last character was not a tab.
*/
tabIfLastNot() {
this._newLineIfNewLineOnNextWrite();
if (!this.isLastTab()) {
this._writeIndentingNewLines("\t");
}
return this;
}
/**
* Writes a tab.
* @param times - Number of times to write a tab.
*/
tab(times = 1) {
this._newLineIfNewLineOnNextWrite();
this._writeIndentingNewLines("\t".repeat(times));
return this;
}
conditionalWrite(condition, textOrFunc) {
if (condition) {
this.write(getStringFromStrOrFunc(textOrFunc));
}
return this;
}
/**
* Writes the provided text.
* @param text - Text to write.
*/
write(text) {
this._newLineIfNewLineOnNextWrite();
this._writeIndentingNewLines(text);
return this;
}
/**
* Writes text to exit a comment if in a comment.
*/
closeComment() {
const commentChar = this._currentCommentChar;
switch (commentChar) {
case CommentChar.Line:
this.newLine();
break;
case CommentChar.Star:
if (!this.isLastNewLine()) {
this.spaceIfLastNot();
}
this.write("*/");
break;
default: {
const _assertUndefined = commentChar;
break;
}
}
return this;
}
/**
* Inserts text at the provided position.
*
* This method is "unsafe" because it won't update the state of the writer unless
* inserting at the end position. It is biased towards being fast at inserting closer
* to the start or end, but slower to insert in the middle. Only use this if
* absolutely necessary.
* @param pos - Position to insert at.
* @param text - Text to insert.
*/
unsafeInsert(pos, text) {
const textLength = this._length;
const texts = this._texts;
verifyInput();
if (pos === textLength) {
return this.write(text);
}
updateInternalArray();
this._length += text.length;
return this;
function verifyInput() {
if (pos < 0) {
throw new Error(`Provided position of '${pos}' was less than zero.`);
}
if (pos > textLength) {
throw new Error(`Provided position of '${pos}' was greater than the text length of '${textLength}'.`);
}
}
function updateInternalArray() {
const { index, localIndex } = getArrayIndexAndLocalIndex();
if (localIndex === 0) {
texts.splice(index, 0, text);
}
else if (localIndex === texts[index].length) {
texts.splice(index + 1, 0, text);
}
else {
const textItem = texts[index];
const startText = textItem.substring(0, localIndex);
const endText = textItem.substring(localIndex);
texts.splice(index, 1, startText, text, endText);
}
}
function getArrayIndexAndLocalIndex() {
if (pos < textLength / 2) {
// start searching from the front
let endPos = 0;
for (let i = 0; i < texts.length; i++) {
const textItem = texts[i];
const startPos = endPos;
endPos += textItem.length;
if (endPos >= pos) {
return { index: i, localIndex: pos - startPos };
}
}
}
else {
// start searching from the back
let startPos = textLength;
for (let i = texts.length - 1; i >= 0; i--) {
const textItem = texts[i];
startPos -= textItem.length;
if (startPos <= pos) {
return { index: i, localIndex: pos - startPos };
}
}
}
throw new Error("Unhandled situation inserting. This should never happen.");
}
}
/**
* Gets the length of the string in the writer.
*/
getLength() {
return this._length;
}
/**
* Gets if the writer is currently in a comment.
*/
isInComment() {
return this._currentCommentChar !== undefined;
}
/**
* Gets if the writer is currently at the start of the first line of the text, block, or indentation block.
*/
isAtStartOfFirstLineOfBlock() {
return this.isOnFirstLineOfBlock() && (this.isLastNewLine() || this.getLastChar() == null);
}
/**
* 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.
*/
isInString() {
return this._stringCharStack.length > 0 && this._stringCharStack[this._stringCharStack.length - 1] !== CHARS.OPEN_BRACE;
}
/**
* Gets if the last chars written were for a newline.
*/
isLastNewLine() {
const lastChar = this.getLastChar();
return lastChar === "\n" || lastChar === "\r";
}
/**
* Gets if the last chars written were for a blank line.
*/
isLastBlankLine() {
let foundCount = 0;
// todo: consider extracting out iterating over past characters, but don't use
// an iterator because it will be slow.
for (let i = this._texts.length - 1; i >= 0; i--) {
const currentText = this._texts[i];
for (let j = currentText.length - 1; j >= 0; j--) {
const currentChar = currentText.charCodeAt(j);
if (currentChar === CHARS.NEW_LINE) {
foundCount++;
if (foundCount === 2) {
return true;
}
}
else if (currentChar !== CHARS.CARRIAGE_RETURN) {
return false;
}
}
}
return false;
}
/**
* Gets if the last char written was a space.
*/
isLastSpace() {
return this.getLastChar() === " ";
}
/**
* Gets if the last char written was a tab.
*/
isLastTab() {
return this.getLastChar() === "\t";
}
/**
* Gets the last char written.
*/
getLastChar() {
const charCode = this._getLastCharCodeWithOffset(0);
return charCode == null ? undefined : String.fromCharCode(charCode);
}
/**
* Gets if the writer ends with the provided text.
* @param text - Text to check if the writer ends with the provided text.
*/
endsWith(text) {
const length = this._length;
return this.iterateLastCharCodes((charCode, index) => {
const offset = length - index;
const textIndex = text.length - offset;
if (text.charCodeAt(textIndex) !== charCode) {
return false;
}
return textIndex === 0 ? true : undefined;
}) || false;
}
/**
* Iterates over the writer characters in reverse order. The iteration stops when a non-null or
* undefined value is returned from the action. The returned value is then returned by the method.
*
* @remarks It is much more efficient to use this method rather than `#toString()` since `#toString()`
* will combine the internal array into a string.
*/
iterateLastChars(action) {
return this.iterateLastCharCodes((charCode, index) => action(String.fromCharCode(charCode), index));
}
/**
* Iterates over the writer character char codes in reverse order. The iteration stops when a non-null or
* undefined value is returned from the action. The returned value is then returned by the method.
*
* @remarks It is much more efficient to use this method rather than `#toString()` since `#toString()`
* will combine the internal array into a string. Additionally, this is slightly more efficient that
* `iterateLastChars` as this won't allocate a string per character.
*/
iterateLastCharCodes(action) {
let index = this._length;
for (let i = this._texts.length - 1; i >= 0; i--) {
const currentText = this._texts[i];
for (let j = currentText.length - 1; j >= 0; j--) {
index--;
const result = action(currentText.charCodeAt(j), index);
if (result != null) {
return result;
}
}
}
return undefined;
}
/**
* Gets the writer's text.
*/
toString() {
if (this._texts.length > 1) {
const text = this._texts.join("");
this._texts.length = 0;
this._texts.push(text);
}
return this._texts[0] || "";
}
/** @internal */
_writeIndentingNewLines(text) {
text = text || "";
if (text.length === 0) {
writeIndividual(this, "");
return;
}
const items = text.split(CodeBlockWriter._newLineRegEx);
items.forEach((s, i) => {
if (i > 0) {
this._baseWriteNewline();
}
if (s.length === 0) {
return;
}
writeIndividual(this, s);
});
function writeIndividual(writer, s) {
if (!writer.isInString()) {
const isAtStartOfLine = writer.isLastNewLine() || writer.getLastChar() == null;
if (isAtStartOfLine) {
writer._writeIndentation();
}
}
writer._updateInternalState(s);
writer._internalWrite(s);
}
}
/** @internal */
_baseWriteNewline() {
if (this._currentCommentChar === CommentChar.Line) {
this._currentCommentChar = undefined;
}
const lastStringCharOnStack = this._stringCharStack[this._stringCharStack.length - 1];
if ((lastStringCharOnStack === CHARS.DOUBLE_QUOTE || lastStringCharOnStack === CHARS.SINGLE_QUOTE) && this._getLastCharCodeWithOffset(0) !== CHARS.BACK_SLASH) {
this._stringCharStack.pop();
}
this._internalWrite(this._newLine);
this._isOnFirstLineOfBlock = false;
this._dequeueQueuedIndentation();
}
/** @internal */
_dequeueQueuedIndentation() {
if (this._queuedIndentation == null) {
return;
}
if (this._queuedOnlyIfNotBlock && wasLastBlock(this)) {
this._queuedIndentation = undefined;
this._queuedOnlyIfNotBlock = undefined;
}
else {
this._currentIndentation = this._queuedIndentation;
this._queuedIndentation = undefined;
}
function wasLastBlock(writer) {
let foundNewLine = false;
return writer.iterateLastCharCodes(charCode => {
switch (charCode) {
case CHARS.NEW_LINE:
if (foundNewLine) {
return false;
}
else {
foundNewLine = true;
}
break;
case CHARS.CARRIAGE_RETURN:
return undefined;
case CHARS.OPEN_BRACE:
return true;
default:
return false;
}
});
}
}
/** @internal */
_updateInternalState(str) {
for (let i = 0; i < str.length; i++) {
const currentChar = str.charCodeAt(i);
// This is a performance optimization to short circuit all the checks below. If the current char
// is not in this set then it won't change any internal state so no need to continue and do
// so many other checks (this made it 3x faster in one scenario I tested).
if (!isCharToHandle.has(currentChar)) {
continue;
}
const pastChar = i === 0 ? this._getLastCharCodeWithOffset(0) : str.charCodeAt(i - 1);
const pastPastChar = i === 0 ? this._getLastCharCodeWithOffset(1) : i === 1 ? this._getLastCharCodeWithOffset(0) : str.charCodeAt(i - 2);
// handle regex
if (this._isInRegEx) {
if (pastChar === CHARS.FORWARD_SLASH && pastPastChar !== CHARS.BACK_SLASH || pastChar === CHARS.NEW_LINE) {
this._isInRegEx = false;
}
else {
continue;
}
}
else if (!this.isInString() && !this.isInComment() && isRegExStart(currentChar, pastChar, pastPastChar)) {
this._isInRegEx = true;
continue;
}
// handle comments
if (!this.isInString()) {
if (this._currentCommentChar == null && pastChar === CHARS.FORWARD_SLASH && currentChar === CHARS.FORWARD_SLASH) {
this._currentCommentChar = CommentChar.Line;
}
else if (this._currentCommentChar == null && pastChar === CHARS.FORWARD_SLASH && currentChar === CHARS.ASTERISK) {
this._currentCommentChar = CommentChar.Star;
}
else if (this._currentCommentChar === CommentChar.Star && pastChar === CHARS.ASTERISK && currentChar === CHARS.FORWARD_SLASH) {
this._currentCommentChar = undefined;
}
}
if (this.isInComment()) {
continue;
}
// handle strings
const lastStringCharOnStack = this._stringCharStack.length === 0 ? undefined : this._stringCharStack[this._stringCharStack.length - 1];
if (pastChar !== CHARS.BACK_SLASH && (currentChar === CHARS.DOUBLE_QUOTE || currentChar === CHARS.SINGLE_QUOTE || currentChar === CHARS.BACK_TICK)) {
if (lastStringCharOnStack === currentChar) {
this._stringCharStack.pop();
}
else if (lastStringCharOnStack === CHARS.OPEN_BRACE || lastStringCharOnStack === undefined) {
this._stringCharStack.push(currentChar);
}
}
else if (pastPastChar !== CHARS.BACK_SLASH && pastChar === CHARS.DOLLAR_SIGN && currentChar === CHARS.OPEN_BRACE && lastStringCharOnStack === CHARS.BACK_TICK) {
this._stringCharStack.push(currentChar);
}
else if (currentChar === CHARS.CLOSE_BRACE && lastStringCharOnStack === CHARS.OPEN_BRACE) {
this._stringCharStack.pop();
}
}
}
/** @internal - This is private, but exposed for testing. */
_getLastCharCodeWithOffset(offset) {
if (offset >= this._length || offset < 0) {
return undefined;
}
for (let i = this._texts.length - 1; i >= 0; i--) {
const currentText = this._texts[i];
if (offset >= currentText.length) {
offset -= currentText.length;
}
else {
return currentText.charCodeAt(currentText.length - 1 - offset);
}
}
return undefined;
}
/** @internal */
_writeIndentation() {
const flooredIndentation = Math.floor(this._currentIndentation);
this._internalWrite(this._indentationText.repeat(flooredIndentation));
const overflow = this._currentIndentation - flooredIndentation;
if (this._useTabs) {
if (overflow > 0.5) {
this._internalWrite(this._indentationText);
}
}
else {
const portion = Math.round(this._indentationText.length * overflow);
// build up the string first, then append it for performance reasons
let text = "";
for (let i = 0; i < portion; i++) {
text += this._indentationText[i];
}
this._internalWrite(text);
}
}
/** @internal */
_newLineIfNewLineOnNextWrite() {
if (!this._newLineOnNextWrite) {
return;
}
this._newLineOnNextWrite = false;
this.newLine();
}
/** @internal */
_internalWrite(text) {
if (text.length === 0) {
return;
}
this._texts.push(text);
this._length += text.length;
}
/** @internal */
_getIndentationLevelFromArg(countOrText) {
if (typeof countOrText === "number") {
if (countOrText < 0) {
throw new Error("Passed in indentation level should be greater than or equal to 0.");
}
return countOrText;
}
else if (typeof countOrText === "string") {
if (!CodeBlockWriter._spacesOrTabsRegEx.test(countOrText)) {
throw new Error("Provided string must be empty or only contain spaces or tabs.");
}
const { spacesCount, tabsCount } = getSpacesAndTabsCount(countOrText);
return tabsCount + spacesCount / this._indentNumberOfSpaces;
}
else {
throw new Error("Argument provided must be a string or number.");
}
}
/** @internal */
_setIndentationState(state) {
this._currentIndentation = state.current;
this._queuedIndentation = state.queued;
this._queuedOnlyIfNotBlock = state.queuedOnlyIfNotBlock;
}
/** @internal */
_getIndentationState() {
return {
current: this._currentIndentation,
queued: this._queuedIndentation,
queuedOnlyIfNotBlock: this._queuedOnlyIfNotBlock,
};
}
}
/** @internal */
Object.defineProperty(CodeBlockWriter, "_newLineRegEx", {
enumerable: true,
configurable: true,
writable: true,
value: /\r?\n/
});
/** @internal */
Object.defineProperty(CodeBlockWriter, "_spacesOrTabsRegEx", {
enumerable: true,
configurable: true,
writable: true,
value: /^[ \t]*$/
});
export default CodeBlockWriter;
function isRegExStart(currentChar, pastChar, pastPastChar) {
return pastChar === CHARS.FORWARD_SLASH
&& currentChar !== CHARS.FORWARD_SLASH
&& currentChar !== CHARS.ASTERISK
&& pastPastChar !== CHARS.ASTERISK
&& pastPastChar !== CHARS.FORWARD_SLASH;
}
function getIndentationText(useTabs, numberSpaces) {
if (useTabs) {
return "\t";
}
return Array(numberSpaces + 1).join(" ");
}
function getSpacesAndTabsCount(str) {
let spacesCount = 0;
let tabsCount = 0;
for (let i = 0; i < str.length; i++) {
const charCode = str.charCodeAt(i);
if (charCode === CHARS.SPACE) {
spacesCount++;
}
else if (charCode === CHARS.TAB) {
tabsCount++;
}
}
return { spacesCount, tabsCount };
}

1
node_modules/code-block-writer/esm/mod.test.d.ts.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"mod.test.d.ts","sourceRoot":"","sources":["../src/mod.test.ts"],"names":[],"mappings":""}

3
node_modules/code-block-writer/esm/package.json generated vendored Normal file
View File

@@ -0,0 +1,3 @@
{
"type": "module"
}

View File

@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=string_utils.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"string_utils.d.ts","sourceRoot":"","sources":["../../src/utils/string_utils.ts"],"names":[],"mappings":""}

View File

@@ -0,0 +1,26 @@
/** @internal */
export function escapeForWithinString(str, quoteKind) {
let result = "";
// todo: reduce appends (don't go char by char)
for (let i = 0; i < str.length; i++) {
if (str[i] === quoteKind) {
result += "\\";
}
else if (str[i] === "\r" && str[i + 1] === "\n") {
result += "\\r\\n\\";
i++; // skip the \r
}
else if (str[i] === "\n") {
result += "\\n\\";
}
else if (str[i] === "\\") {
result += "\\";
}
result += str[i];
}
return result;
}
/** @internal */
export function getStringFromStrOrFunc(strOrFunc) {
return strOrFunc instanceof Function ? strOrFunc() : strOrFunc;
}

View File

@@ -0,0 +1 @@
{"version":3,"file":"string_utils.test.d.ts","sourceRoot":"","sources":["../../src/utils/string_utils.test.ts"],"names":[],"mappings":""}

40
node_modules/code-block-writer/package.json generated vendored Normal file
View File

@@ -0,0 +1,40 @@
{
"name": "code-block-writer",
"version": "13.0.3",
"description": "A simple code writer that assists with formatting and visualizing blocks of code.",
"keywords": [
"code generation",
"typescript",
"writer",
"printer"
],
"author": "David Sherret",
"homepage": "https://github.com/dsherret/code-block-writer#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/dsherret/code-block-writer.git"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/dsherret/code-block-writer/issues"
},
"main": "./script/mod.js",
"module": "./esm/mod.js",
"exports": {
".": {
"import": "./esm/mod.js",
"require": "./script/mod.js"
}
},
"scripts": {
"test": "node test_runner.js"
},
"devDependencies": {
"@types/node": "^20.9.0",
"picocolors": "^1.0.0",
"@types/chai": "4.3",
"chai": "4.3.7",
"@deno/shim-deno": "~0.18.0"
},
"_generatedBy": "dnt@dev"
}

View File

@@ -0,0 +1 @@
{"version":3,"file":"_dnt.test_shims.d.ts","sourceRoot":"","sources":["../src/_dnt.test_shims.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAKvC,eAAO,MAAM,aAAa;;CAA2C,CAAC"}

View File

@@ -0,0 +1 @@
{"version":3,"file":"_test.deps.d.ts","sourceRoot":"","sources":["../src/_test.deps.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,6CAA6C,CAAC;AAE3E,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC"}

View File

@@ -0,0 +1 @@
{"version":3,"file":"_test_suite.d.ts","sourceRoot":"","sources":["../../../../../src/deps/deno.land/std@0.193.0/testing/_test_suite.ts"],"names":[],"mappings":"AACA,wEAAwE;AACxE,OAAO,KAAK,OAAO,MAAM,gCAAgC,CAAC;AAE1D,MAAM,WAAW,kBAAkB,CAAC,CAAC,CAAE,SAAQ,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,cAAc,EAAE,IAAI,CAAC;IACpF,EAAE,CAAC,EAAE,MAAM,IAAI,CAAC;IAChB;;;;OAIG;IACH,KAAK,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;IACrB,kEAAkE;IAClE,SAAS,CAAC,EACN,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAA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,SAAS,EACf,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAcvC,iEAAiE;WACpD,GAAG,CAAC,CAAC,EAChB,KAAK,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAC3B,OAAO,EAAE,CAAC,EACV,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,WAAW;WAqEhB,OAAO,CAAC,CAAC,EACpB,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,WAAW,EAC3B,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,WAAW,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,EAClE,OAAO,EAAE,CAAC,EACV,WAAW,SAAI;CA8BlB"}

File diff suppressed because one or more lines are too long

276
node_modules/code-block-writer/script/mod.d.ts generated vendored Normal file
View File

@@ -0,0 +1,276 @@
/**
* Options for the writer.
*/
export interface Options {
/**
* Newline character.
* @remarks Defaults to \n.
*/
newLine: "\n" | "\r\n";
/**
* Number of spaces to indent when `useTabs` is false.
* @remarks Defaults to 4.
*/
indentNumberOfSpaces: number;
/**
* Whether to use tabs (true) or spaces (false).
* @remarks Defaults to false.
*/
useTabs: boolean;
/**
* Whether to use a single quote (true) or double quote (false).
* @remarks Defaults to false.
*/
useSingleQuote: boolean;
}
/**
* Code writer that assists with formatting and visualizing blocks of JavaScript or TypeScript code.
*/
export default class CodeBlockWriter {
/**
* Constructor.
* @param opts - Options for the writer.
*/
constructor(opts?: Partial<Options>);
/**
* Gets the options.
*/
getOptions(): Options;
/**
* Queues the indentation level for the next lines written.
* @param indentationLevel - Indentation level to queue.
*/
queueIndentationLevel(indentationLevel: number): this;
/**
* Queues the indentation level for the next lines written using the provided indentation text.
* @param whitespaceText - Gets the indentation level from the indentation text.
*/
queueIndentationLevel(whitespaceText: string): this;
/**
* Writes the text within the provided action with hanging indentation.
* @param action - Action to perform with hanging indentation.
*/
hangingIndent(action: () => void): this;
/**
* Writes the text within the provided action with hanging indentation unless writing a block.
* @param action - Action to perform with hanging indentation unless a block is written.
*/
hangingIndentUnlessBlock(action: () => void): this;
/**
* Sets the current indentation level.
* @param indentationLevel - Indentation level to be at.
*/
setIndentationLevel(indentationLevel: number): this;
/**
* Sets the current indentation using the provided indentation text.
* @param whitespaceText - Gets the indentation level from the indentation text.
*/
setIndentationLevel(whitespaceText: string): this;
/**
* Sets the indentation level within the provided action and restores the writer's indentation
* state afterwards.
* @remarks Restores the writer's state after the action.
* @param indentationLevel - Indentation level to set.
* @param action - Action to perform with the indentation.
*/
withIndentationLevel(indentationLevel: number, action: () => void): this;
/**
* Sets the indentation level with the provided indentation text within the provided action
* and restores the writer's indentation state afterwards.
* @param whitespaceText - Gets the indentation level from the indentation text.
* @param action - Action to perform with the indentation.
*/
withIndentationLevel(whitespaceText: string, action: () => void): this;
/**
* Gets the current indentation level.
*/
getIndentationLevel(): number;
/**
* Writes a block using braces.
* @param block - Write using the writer within this block.
*/
block(block?: () => void): this;
/**
* Writes an inline block with braces.
* @param block - Write using the writer within this block.
*/
inlineBlock(block?: () => void): this;
/**
* Indents the code one level for the current line.
*/
indent(times?: number): this;
/**
* Indents a block of code.
* @param block - Block to indent.
*/
indent(block: () => void): this;
/**
* Conditionally writes a line of text.
* @param condition - Condition to evaluate.
* @param textFunc - A function that returns a string to write if the condition is true.
*/
conditionalWriteLine(condition: boolean | undefined, textFunc: () => string): this;
/**
* Conditionally writes a line of text.
* @param condition - Condition to evaluate.
* @param text - Text to write if the condition is true.
*/
conditionalWriteLine(condition: boolean | undefined, text: string): this;
/**
* Writes a line of text.
* @param text - String to write.
*/
writeLine(text: string): this;
/**
* Writes a newline if the last line was not a newline.
*/
newLineIfLastNot(): this;
/**
* Writes a blank line if the last written text was not a blank line.
*/
blankLineIfLastNot(): this;
/**
* Writes a blank line if the condition is true.
* @param condition - Condition to evaluate.
*/
conditionalBlankLine(condition: boolean | undefined): this;
/**
* Writes a blank line.
*/
blankLine(): this;
/**
* Writes a newline if the condition is true.
* @param condition - Condition to evaluate.
*/
conditionalNewLine(condition: boolean | undefined): this;
/**
* Writes a newline.
*/
newLine(): this;
/**
* Writes a quote character.
*/
quote(): this;
/**
* Writes text surrounded in quotes.
* @param text - Text to write.
*/
quote(text: string): this;
/**
* Writes a space if the last character was not a space.
*/
spaceIfLastNot(): this;
/**
* Writes a space.
* @param times - Number of times to write a space.
*/
space(times?: number): this;
/**
* Writes a tab if the last character was not a tab.
*/
tabIfLastNot(): this;
/**
* Writes a tab.
* @param times - Number of times to write a tab.
*/
tab(times?: number): this;
/**
* Conditionally writes text.
* @param condition - Condition to evaluate.
* @param textFunc - A function that returns a string to write if the condition is true.
*/
conditionalWrite(condition: boolean | undefined, textFunc: () => string): this;
/**
* Conditionally writes text.
* @param condition - Condition to evaluate.
* @param text - Text to write if the condition is true.
*/
conditionalWrite(condition: boolean | undefined, text: string): this;
/**
* Writes the provided text.
* @param text - Text to write.
*/
write(text: string): this;
/**
* Writes text to exit a comment if in a comment.
*/
closeComment(): this;
/**
* Inserts text at the provided position.
*
* This method is "unsafe" because it won't update the state of the writer unless
* inserting at the end position. It is biased towards being fast at inserting closer
* to the start or end, but slower to insert in the middle. Only use this if
* absolutely necessary.
* @param pos - Position to insert at.
* @param text - Text to insert.
*/
unsafeInsert(pos: number, text: string): this;
/**
* Gets the length of the string in the writer.
*/
getLength(): number;
/**
* Gets if the writer is currently in a comment.
*/
isInComment(): boolean;
/**
* Gets if the writer is currently at the start of the first line of the text, block, or indentation block.
*/
isAtStartOfFirstLineOfBlock(): boolean;
/**
* 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.
*/
isInString(): boolean;
/**
* Gets if the last chars written were for a newline.
*/
isLastNewLine(): boolean;
/**
* Gets if the last chars written were for a blank line.
*/
isLastBlankLine(): boolean;
/**
* Gets if the last char written was a space.
*/
isLastSpace(): boolean;
/**
* Gets if the last char written was a tab.
*/
isLastTab(): boolean;
/**
* Gets the last char written.
*/
getLastChar(): string | undefined;
/**
* Gets if the writer ends with the provided text.
* @param text - Text to check if the writer ends with the provided text.
*/
endsWith(text: string): boolean;
/**
* Iterates over the writer characters in reverse order. The iteration stops when a non-null or
* undefined value is returned from the action. The returned value is then returned by the method.
*
* @remarks It is much more efficient to use this method rather than `#toString()` since `#toString()`
* will combine the internal array into a string.
*/
iterateLastChars<T>(action: (char: string, index: number) => T | undefined): T | undefined;
/**
* Iterates over the writer character char codes in reverse order. The iteration stops when a non-null or
* undefined value is returned from the action. The returned value is then returned by the method.
*
* @remarks It is much more efficient to use this method rather than `#toString()` since `#toString()`
* will combine the internal array into a string. Additionally, this is slightly more efficient that
* `iterateLastChars` as this won't allocate a string per character.
*/
iterateLastCharCodes<T>(action: (charCode: number, index: number) => T | undefined): T | undefined;
/**
* Gets the writer's text.
*/
toString(): string;
}
//# sourceMappingURL=mod.d.ts.map

1
node_modules/code-block-writer/script/mod.d.ts.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAQA;;GAEG;AACH,MAAM,WAAW,OAAO;IACtB;;;OAGG;IACH,OAAO,EAAE,IAAI,GAAG,MAAM,CAAC;IACvB;;;OAGG;IACH,oBAAoB,EAAE,MAAM,CAAC;IAC7B;;;OAGG;IACH,OAAO,EAAE,OAAO,CAAC;IACjB;;;OAGG;IACH,cAAc,EAAE,OAAO,CAAC;CACzB;AA+BD;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,eAAe;IAkClC;;;OAGG;gBACS,IAAI,GAAE,OAAO,CAAC,OAAO,CAAM;IAQvC;;OAEG;IACH,UAAU,IAAI,OAAO;IASrB;;;OAGG;IACH,qBAAqB,CAAC,gBAAgB,EAAE,MAAM,GAAG,IAAI;IACrD;;;OAGG;IACH,qBAAqB,CAAC,cAAc,EAAE,MAAM,GAA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;;OAGG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAY/B;;;;;;OAMG;IACH,gBAAgB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,CAAC,GAAG,SAAS,GAAG,CAAC,GAAG,SAAS;IAI1F;;;;;;;OAOG;IACH,oBAAoB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,CAAC,GAAG,SAAS,GAAG,CAAC,GAAG,SAAS;IAelG;;OAEG;IACH,QAAQ,IAAI,MAAM;CAyPnB"}

889
node_modules/code-block-writer/script/mod.js generated vendored Normal file
View File

@@ -0,0 +1,889 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const string_utils_js_1 = require("./utils/string_utils.js");
/** @internal */
var CommentChar;
(function (CommentChar) {
CommentChar[CommentChar["Line"] = 0] = "Line";
CommentChar[CommentChar["Star"] = 1] = "Star";
})(CommentChar || (CommentChar = {}));
// Using the char codes is a performance improvement (about 5.5% faster when writing because it eliminates additional string allocations).
const CHARS = {
BACK_SLASH: "\\".charCodeAt(0),
FORWARD_SLASH: "/".charCodeAt(0),
NEW_LINE: "\n".charCodeAt(0),
CARRIAGE_RETURN: "\r".charCodeAt(0),
ASTERISK: "*".charCodeAt(0),
DOUBLE_QUOTE: "\"".charCodeAt(0),
SINGLE_QUOTE: "'".charCodeAt(0),
BACK_TICK: "`".charCodeAt(0),
OPEN_BRACE: "{".charCodeAt(0),
CLOSE_BRACE: "}".charCodeAt(0),
DOLLAR_SIGN: "$".charCodeAt(0),
SPACE: " ".charCodeAt(0),
TAB: "\t".charCodeAt(0),
};
const isCharToHandle = new Set([
CHARS.BACK_SLASH,
CHARS.FORWARD_SLASH,
CHARS.NEW_LINE,
CHARS.CARRIAGE_RETURN,
CHARS.ASTERISK,
CHARS.DOUBLE_QUOTE,
CHARS.SINGLE_QUOTE,
CHARS.BACK_TICK,
CHARS.OPEN_BRACE,
CHARS.CLOSE_BRACE,
]);
/**
* Code writer that assists with formatting and visualizing blocks of JavaScript or TypeScript code.
*/
class CodeBlockWriter {
/**
* Constructor.
* @param opts - Options for the writer.
*/
constructor(opts = {}) {
/** @internal */
Object.defineProperty(this, "_indentationText", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
/** @internal */
Object.defineProperty(this, "_newLine", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
/** @internal */
Object.defineProperty(this, "_useTabs", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
/** @internal */
Object.defineProperty(this, "_quoteChar", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
/** @internal */
Object.defineProperty(this, "_indentNumberOfSpaces", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
/** @internal */
Object.defineProperty(this, "_currentIndentation", {
enumerable: true,
configurable: true,
writable: true,
value: 0
});
/** @internal */
Object.defineProperty(this, "_queuedIndentation", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
/** @internal */
Object.defineProperty(this, "_queuedOnlyIfNotBlock", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
/** @internal */
Object.defineProperty(this, "_length", {
enumerable: true,
configurable: true,
writable: true,
value: 0
});
/** @internal */
Object.defineProperty(this, "_newLineOnNextWrite", {
enumerable: true,
configurable: true,
writable: true,
value: false
});
/** @internal */
Object.defineProperty(this, "_currentCommentChar", {
enumerable: true,
configurable: true,
writable: true,
value: undefined
});
/** @internal */
Object.defineProperty(this, "_stringCharStack", {
enumerable: true,
configurable: true,
writable: true,
value: []
});
/** @internal */
Object.defineProperty(this, "_isInRegEx", {
enumerable: true,
configurable: true,
writable: true,
value: false
});
/** @internal */
Object.defineProperty(this, "_isOnFirstLineOfBlock", {
enumerable: true,
configurable: true,
writable: true,
value: true
});
// An array of strings is used rather than a single string because it was
// found to be ~11x faster when printing a 10K line file (~11s to ~1s).
/** @internal */
Object.defineProperty(this, "_texts", {
enumerable: true,
configurable: true,
writable: true,
value: []
});
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.useSingleQuote ? "'" : `"`;
}
/**
* Gets the options.
*/
getOptions() {
return {
indentNumberOfSpaces: this._indentNumberOfSpaces,
newLine: this._newLine,
useTabs: this._useTabs,
useSingleQuote: this._quoteChar === "'",
};
}
queueIndentationLevel(countOrText) {
this._queuedIndentation = this._getIndentationLevelFromArg(countOrText);
this._queuedOnlyIfNotBlock = undefined;
return this;
}
/**
* Writes the text within the provided action with hanging indentation.
* @param action - Action to perform with hanging indentation.
*/
hangingIndent(action) {
return this._withResetIndentation(() => this.queueIndentationLevel(this.getIndentationLevel() + 1), action);
}
/**
* Writes the text within the provided action with hanging indentation unless writing a block.
* @param action - Action to perform with hanging indentation unless a block is written.
*/
hangingIndentUnlessBlock(action) {
return this._withResetIndentation(() => {
this.queueIndentationLevel(this.getIndentationLevel() + 1);
this._queuedOnlyIfNotBlock = true;
}, action);
}
setIndentationLevel(countOrText) {
this._currentIndentation = this._getIndentationLevelFromArg(countOrText);
return this;
}
withIndentationLevel(countOrText, action) {
return this._withResetIndentation(() => this.setIndentationLevel(countOrText), action);
}
/** @internal */
_withResetIndentation(setStateAction, writeAction) {
const previousState = this._getIndentationState();
setStateAction();
try {
writeAction();
}
finally {
this._setIndentationState(previousState);
}
return this;
}
/**
* Gets the current indentation level.
*/
getIndentationLevel() {
return this._currentIndentation;
}
/**
* Writes a block using braces.
* @param block - Write using the writer within this block.
*/
block(block) {
this._newLineIfNewLineOnNextWrite();
if (this.getLength() > 0 && !this.isLastNewLine()) {
this.spaceIfLastNot();
}
this.inlineBlock(block);
this._newLineOnNextWrite = true;
return this;
}
/**
* Writes an inline block with braces.
* @param block - Write using the writer within this block.
*/
inlineBlock(block) {
this._newLineIfNewLineOnNextWrite();
this.write("{");
this._indentBlockInternal(block);
this.newLineIfLastNot().write("}");
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;
}
}
/** @internal */
_indentBlockInternal(block) {
if (this.getLastChar() != null) {
this.newLineIfLastNot();
}
this._currentIndentation++;
this._isOnFirstLineOfBlock = true;
if (block != null) {
block();
}
this._isOnFirstLineOfBlock = false;
this._currentIndentation = Math.max(0, this._currentIndentation - 1);
}
conditionalWriteLine(condition, strOrFunc) {
if (condition) {
this.writeLine((0, string_utils_js_1.getStringFromStrOrFunc)(strOrFunc));
}
return this;
}
/**
* Writes a line of text.
* @param text - String to write.
*/
writeLine(text) {
this._newLineIfNewLineOnNextWrite();
if (this.getLastChar() != null) {
this.newLineIfLastNot();
}
this._writeIndentingNewLines(text);
this.newLine();
return this;
}
/**
* Writes a newline if the last line was not a newline.
*/
newLineIfLastNot() {
this._newLineIfNewLineOnNextWrite();
if (!this.isLastNewLine()) {
this.newLine();
}
return this;
}
/**
* Writes a blank line if the last written text was not a blank line.
*/
blankLineIfLastNot() {
if (!this.isLastBlankLine()) {
this.blankLine();
}
return this;
}
/**
* Writes a blank line if the condition is true.
* @param condition - Condition to evaluate.
*/
conditionalBlankLine(condition) {
if (condition) {
this.blankLine();
}
return this;
}
/**
* Writes a blank line.
*/
blankLine() {
return this.newLineIfLastNot().newLine();
}
/**
* Writes a newline if the condition is true.
* @param condition - Condition to evaluate.
*/
conditionalNewLine(condition) {
if (condition) {
this.newLine();
}
return this;
}
/**
* Writes a newline.
*/
newLine() {
this._newLineOnNextWrite = false;
this._baseWriteNewline();
return this;
}
quote(text) {
this._newLineIfNewLineOnNextWrite();
this._writeIndentingNewLines(text == null ? this._quoteChar : this._quoteChar + (0, string_utils_js_1.escapeForWithinString)(text, this._quoteChar) + this._quoteChar);
return this;
}
/**
* Writes a space if the last character was not a space.
*/
spaceIfLastNot() {
this._newLineIfNewLineOnNextWrite();
if (!this.isLastSpace()) {
this._writeIndentingNewLines(" ");
}
return this;
}
/**
* Writes a space.
* @param times - Number of times to write a space.
*/
space(times = 1) {
this._newLineIfNewLineOnNextWrite();
this._writeIndentingNewLines(" ".repeat(times));
return this;
}
/**
* Writes a tab if the last character was not a tab.
*/
tabIfLastNot() {
this._newLineIfNewLineOnNextWrite();
if (!this.isLastTab()) {
this._writeIndentingNewLines("\t");
}
return this;
}
/**
* Writes a tab.
* @param times - Number of times to write a tab.
*/
tab(times = 1) {
this._newLineIfNewLineOnNextWrite();
this._writeIndentingNewLines("\t".repeat(times));
return this;
}
conditionalWrite(condition, textOrFunc) {
if (condition) {
this.write((0, string_utils_js_1.getStringFromStrOrFunc)(textOrFunc));
}
return this;
}
/**
* Writes the provided text.
* @param text - Text to write.
*/
write(text) {
this._newLineIfNewLineOnNextWrite();
this._writeIndentingNewLines(text);
return this;
}
/**
* Writes text to exit a comment if in a comment.
*/
closeComment() {
const commentChar = this._currentCommentChar;
switch (commentChar) {
case CommentChar.Line:
this.newLine();
break;
case CommentChar.Star:
if (!this.isLastNewLine()) {
this.spaceIfLastNot();
}
this.write("*/");
break;
default: {
const _assertUndefined = commentChar;
break;
}
}
return this;
}
/**
* Inserts text at the provided position.
*
* This method is "unsafe" because it won't update the state of the writer unless
* inserting at the end position. It is biased towards being fast at inserting closer
* to the start or end, but slower to insert in the middle. Only use this if
* absolutely necessary.
* @param pos - Position to insert at.
* @param text - Text to insert.
*/
unsafeInsert(pos, text) {
const textLength = this._length;
const texts = this._texts;
verifyInput();
if (pos === textLength) {
return this.write(text);
}
updateInternalArray();
this._length += text.length;
return this;
function verifyInput() {
if (pos < 0) {
throw new Error(`Provided position of '${pos}' was less than zero.`);
}
if (pos > textLength) {
throw new Error(`Provided position of '${pos}' was greater than the text length of '${textLength}'.`);
}
}
function updateInternalArray() {
const { index, localIndex } = getArrayIndexAndLocalIndex();
if (localIndex === 0) {
texts.splice(index, 0, text);
}
else if (localIndex === texts[index].length) {
texts.splice(index + 1, 0, text);
}
else {
const textItem = texts[index];
const startText = textItem.substring(0, localIndex);
const endText = textItem.substring(localIndex);
texts.splice(index, 1, startText, text, endText);
}
}
function getArrayIndexAndLocalIndex() {
if (pos < textLength / 2) {
// start searching from the front
let endPos = 0;
for (let i = 0; i < texts.length; i++) {
const textItem = texts[i];
const startPos = endPos;
endPos += textItem.length;
if (endPos >= pos) {
return { index: i, localIndex: pos - startPos };
}
}
}
else {
// start searching from the back
let startPos = textLength;
for (let i = texts.length - 1; i >= 0; i--) {
const textItem = texts[i];
startPos -= textItem.length;
if (startPos <= pos) {
return { index: i, localIndex: pos - startPos };
}
}
}
throw new Error("Unhandled situation inserting. This should never happen.");
}
}
/**
* Gets the length of the string in the writer.
*/
getLength() {
return this._length;
}
/**
* Gets if the writer is currently in a comment.
*/
isInComment() {
return this._currentCommentChar !== undefined;
}
/**
* Gets if the writer is currently at the start of the first line of the text, block, or indentation block.
*/
isAtStartOfFirstLineOfBlock() {
return this.isOnFirstLineOfBlock() && (this.isLastNewLine() || this.getLastChar() == null);
}
/**
* 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.
*/
isInString() {
return this._stringCharStack.length > 0 && this._stringCharStack[this._stringCharStack.length - 1] !== CHARS.OPEN_BRACE;
}
/**
* Gets if the last chars written were for a newline.
*/
isLastNewLine() {
const lastChar = this.getLastChar();
return lastChar === "\n" || lastChar === "\r";
}
/**
* Gets if the last chars written were for a blank line.
*/
isLastBlankLine() {
let foundCount = 0;
// todo: consider extracting out iterating over past characters, but don't use
// an iterator because it will be slow.
for (let i = this._texts.length - 1; i >= 0; i--) {
const currentText = this._texts[i];
for (let j = currentText.length - 1; j >= 0; j--) {
const currentChar = currentText.charCodeAt(j);
if (currentChar === CHARS.NEW_LINE) {
foundCount++;
if (foundCount === 2) {
return true;
}
}
else if (currentChar !== CHARS.CARRIAGE_RETURN) {
return false;
}
}
}
return false;
}
/**
* Gets if the last char written was a space.
*/
isLastSpace() {
return this.getLastChar() === " ";
}
/**
* Gets if the last char written was a tab.
*/
isLastTab() {
return this.getLastChar() === "\t";
}
/**
* Gets the last char written.
*/
getLastChar() {
const charCode = this._getLastCharCodeWithOffset(0);
return charCode == null ? undefined : String.fromCharCode(charCode);
}
/**
* Gets if the writer ends with the provided text.
* @param text - Text to check if the writer ends with the provided text.
*/
endsWith(text) {
const length = this._length;
return this.iterateLastCharCodes((charCode, index) => {
const offset = length - index;
const textIndex = text.length - offset;
if (text.charCodeAt(textIndex) !== charCode) {
return false;
}
return textIndex === 0 ? true : undefined;
}) || false;
}
/**
* Iterates over the writer characters in reverse order. The iteration stops when a non-null or
* undefined value is returned from the action. The returned value is then returned by the method.
*
* @remarks It is much more efficient to use this method rather than `#toString()` since `#toString()`
* will combine the internal array into a string.
*/
iterateLastChars(action) {
return this.iterateLastCharCodes((charCode, index) => action(String.fromCharCode(charCode), index));
}
/**
* Iterates over the writer character char codes in reverse order. The iteration stops when a non-null or
* undefined value is returned from the action. The returned value is then returned by the method.
*
* @remarks It is much more efficient to use this method rather than `#toString()` since `#toString()`
* will combine the internal array into a string. Additionally, this is slightly more efficient that
* `iterateLastChars` as this won't allocate a string per character.
*/
iterateLastCharCodes(action) {
let index = this._length;
for (let i = this._texts.length - 1; i >= 0; i--) {
const currentText = this._texts[i];
for (let j = currentText.length - 1; j >= 0; j--) {
index--;
const result = action(currentText.charCodeAt(j), index);
if (result != null) {
return result;
}
}
}
return undefined;
}
/**
* Gets the writer's text.
*/
toString() {
if (this._texts.length > 1) {
const text = this._texts.join("");
this._texts.length = 0;
this._texts.push(text);
}
return this._texts[0] || "";
}
/** @internal */
_writeIndentingNewLines(text) {
text = text || "";
if (text.length === 0) {
writeIndividual(this, "");
return;
}
const items = text.split(CodeBlockWriter._newLineRegEx);
items.forEach((s, i) => {
if (i > 0) {
this._baseWriteNewline();
}
if (s.length === 0) {
return;
}
writeIndividual(this, s);
});
function writeIndividual(writer, s) {
if (!writer.isInString()) {
const isAtStartOfLine = writer.isLastNewLine() || writer.getLastChar() == null;
if (isAtStartOfLine) {
writer._writeIndentation();
}
}
writer._updateInternalState(s);
writer._internalWrite(s);
}
}
/** @internal */
_baseWriteNewline() {
if (this._currentCommentChar === CommentChar.Line) {
this._currentCommentChar = undefined;
}
const lastStringCharOnStack = this._stringCharStack[this._stringCharStack.length - 1];
if ((lastStringCharOnStack === CHARS.DOUBLE_QUOTE || lastStringCharOnStack === CHARS.SINGLE_QUOTE) && this._getLastCharCodeWithOffset(0) !== CHARS.BACK_SLASH) {
this._stringCharStack.pop();
}
this._internalWrite(this._newLine);
this._isOnFirstLineOfBlock = false;
this._dequeueQueuedIndentation();
}
/** @internal */
_dequeueQueuedIndentation() {
if (this._queuedIndentation == null) {
return;
}
if (this._queuedOnlyIfNotBlock && wasLastBlock(this)) {
this._queuedIndentation = undefined;
this._queuedOnlyIfNotBlock = undefined;
}
else {
this._currentIndentation = this._queuedIndentation;
this._queuedIndentation = undefined;
}
function wasLastBlock(writer) {
let foundNewLine = false;
return writer.iterateLastCharCodes(charCode => {
switch (charCode) {
case CHARS.NEW_LINE:
if (foundNewLine) {
return false;
}
else {
foundNewLine = true;
}
break;
case CHARS.CARRIAGE_RETURN:
return undefined;
case CHARS.OPEN_BRACE:
return true;
default:
return false;
}
});
}
}
/** @internal */
_updateInternalState(str) {
for (let i = 0; i < str.length; i++) {
const currentChar = str.charCodeAt(i);
// This is a performance optimization to short circuit all the checks below. If the current char
// is not in this set then it won't change any internal state so no need to continue and do
// so many other checks (this made it 3x faster in one scenario I tested).
if (!isCharToHandle.has(currentChar)) {
continue;
}
const pastChar = i === 0 ? this._getLastCharCodeWithOffset(0) : str.charCodeAt(i - 1);
const pastPastChar = i === 0 ? this._getLastCharCodeWithOffset(1) : i === 1 ? this._getLastCharCodeWithOffset(0) : str.charCodeAt(i - 2);
// handle regex
if (this._isInRegEx) {
if (pastChar === CHARS.FORWARD_SLASH && pastPastChar !== CHARS.BACK_SLASH || pastChar === CHARS.NEW_LINE) {
this._isInRegEx = false;
}
else {
continue;
}
}
else if (!this.isInString() && !this.isInComment() && isRegExStart(currentChar, pastChar, pastPastChar)) {
this._isInRegEx = true;
continue;
}
// handle comments
if (!this.isInString()) {
if (this._currentCommentChar == null && pastChar === CHARS.FORWARD_SLASH && currentChar === CHARS.FORWARD_SLASH) {
this._currentCommentChar = CommentChar.Line;
}
else if (this._currentCommentChar == null && pastChar === CHARS.FORWARD_SLASH && currentChar === CHARS.ASTERISK) {
this._currentCommentChar = CommentChar.Star;
}
else if (this._currentCommentChar === CommentChar.Star && pastChar === CHARS.ASTERISK && currentChar === CHARS.FORWARD_SLASH) {
this._currentCommentChar = undefined;
}
}
if (this.isInComment()) {
continue;
}
// handle strings
const lastStringCharOnStack = this._stringCharStack.length === 0 ? undefined : this._stringCharStack[this._stringCharStack.length - 1];
if (pastChar !== CHARS.BACK_SLASH && (currentChar === CHARS.DOUBLE_QUOTE || currentChar === CHARS.SINGLE_QUOTE || currentChar === CHARS.BACK_TICK)) {
if (lastStringCharOnStack === currentChar) {
this._stringCharStack.pop();
}
else if (lastStringCharOnStack === CHARS.OPEN_BRACE || lastStringCharOnStack === undefined) {
this._stringCharStack.push(currentChar);
}
}
else if (pastPastChar !== CHARS.BACK_SLASH && pastChar === CHARS.DOLLAR_SIGN && currentChar === CHARS.OPEN_BRACE && lastStringCharOnStack === CHARS.BACK_TICK) {
this._stringCharStack.push(currentChar);
}
else if (currentChar === CHARS.CLOSE_BRACE && lastStringCharOnStack === CHARS.OPEN_BRACE) {
this._stringCharStack.pop();
}
}
}
/** @internal - This is private, but exposed for testing. */
_getLastCharCodeWithOffset(offset) {
if (offset >= this._length || offset < 0) {
return undefined;
}
for (let i = this._texts.length - 1; i >= 0; i--) {
const currentText = this._texts[i];
if (offset >= currentText.length) {
offset -= currentText.length;
}
else {
return currentText.charCodeAt(currentText.length - 1 - offset);
}
}
return undefined;
}
/** @internal */
_writeIndentation() {
const flooredIndentation = Math.floor(this._currentIndentation);
this._internalWrite(this._indentationText.repeat(flooredIndentation));
const overflow = this._currentIndentation - flooredIndentation;
if (this._useTabs) {
if (overflow > 0.5) {
this._internalWrite(this._indentationText);
}
}
else {
const portion = Math.round(this._indentationText.length * overflow);
// build up the string first, then append it for performance reasons
let text = "";
for (let i = 0; i < portion; i++) {
text += this._indentationText[i];
}
this._internalWrite(text);
}
}
/** @internal */
_newLineIfNewLineOnNextWrite() {
if (!this._newLineOnNextWrite) {
return;
}
this._newLineOnNextWrite = false;
this.newLine();
}
/** @internal */
_internalWrite(text) {
if (text.length === 0) {
return;
}
this._texts.push(text);
this._length += text.length;
}
/** @internal */
_getIndentationLevelFromArg(countOrText) {
if (typeof countOrText === "number") {
if (countOrText < 0) {
throw new Error("Passed in indentation level should be greater than or equal to 0.");
}
return countOrText;
}
else if (typeof countOrText === "string") {
if (!CodeBlockWriter._spacesOrTabsRegEx.test(countOrText)) {
throw new Error("Provided string must be empty or only contain spaces or tabs.");
}
const { spacesCount, tabsCount } = getSpacesAndTabsCount(countOrText);
return tabsCount + spacesCount / this._indentNumberOfSpaces;
}
else {
throw new Error("Argument provided must be a string or number.");
}
}
/** @internal */
_setIndentationState(state) {
this._currentIndentation = state.current;
this._queuedIndentation = state.queued;
this._queuedOnlyIfNotBlock = state.queuedOnlyIfNotBlock;
}
/** @internal */
_getIndentationState() {
return {
current: this._currentIndentation,
queued: this._queuedIndentation,
queuedOnlyIfNotBlock: this._queuedOnlyIfNotBlock,
};
}
}
/** @internal */
Object.defineProperty(CodeBlockWriter, "_newLineRegEx", {
enumerable: true,
configurable: true,
writable: true,
value: /\r?\n/
});
/** @internal */
Object.defineProperty(CodeBlockWriter, "_spacesOrTabsRegEx", {
enumerable: true,
configurable: true,
writable: true,
value: /^[ \t]*$/
});
exports.default = CodeBlockWriter;
function isRegExStart(currentChar, pastChar, pastPastChar) {
return pastChar === CHARS.FORWARD_SLASH
&& currentChar !== CHARS.FORWARD_SLASH
&& currentChar !== CHARS.ASTERISK
&& pastPastChar !== CHARS.ASTERISK
&& pastPastChar !== CHARS.FORWARD_SLASH;
}
function getIndentationText(useTabs, numberSpaces) {
if (useTabs) {
return "\t";
}
return Array(numberSpaces + 1).join(" ");
}
function getSpacesAndTabsCount(str) {
let spacesCount = 0;
let tabsCount = 0;
for (let i = 0; i < str.length; i++) {
const charCode = str.charCodeAt(i);
if (charCode === CHARS.SPACE) {
spacesCount++;
}
else if (charCode === CHARS.TAB) {
tabsCount++;
}
}
return { spacesCount, tabsCount };
}

View File

@@ -0,0 +1 @@
{"version":3,"file":"mod.test.d.ts","sourceRoot":"","sources":["../src/mod.test.ts"],"names":[],"mappings":""}

3
node_modules/code-block-writer/script/package.json generated vendored Normal file
View File

@@ -0,0 +1,3 @@
{
"type": "commonjs"
}

View File

@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=string_utils.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"string_utils.d.ts","sourceRoot":"","sources":["../../src/utils/string_utils.ts"],"names":[],"mappings":""}

View File

@@ -0,0 +1,31 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getStringFromStrOrFunc = exports.escapeForWithinString = void 0;
/** @internal */
function escapeForWithinString(str, quoteKind) {
let result = "";
// todo: reduce appends (don't go char by char)
for (let i = 0; i < str.length; i++) {
if (str[i] === quoteKind) {
result += "\\";
}
else if (str[i] === "\r" && str[i + 1] === "\n") {
result += "\\r\\n\\";
i++; // skip the \r
}
else if (str[i] === "\n") {
result += "\\n\\";
}
else if (str[i] === "\\") {
result += "\\";
}
result += str[i];
}
return result;
}
exports.escapeForWithinString = escapeForWithinString;
/** @internal */
function getStringFromStrOrFunc(strOrFunc) {
return strOrFunc instanceof Function ? strOrFunc() : strOrFunc;
}
exports.getStringFromStrOrFunc = getStringFromStrOrFunc;

View File

@@ -0,0 +1 @@
{"version":3,"file":"string_utils.test.d.ts","sourceRoot":"","sources":["../../src/utils/string_utils.test.ts"],"names":[],"mappings":""}