code-block-writer
code-block-writer copied to clipboard
Suggestion: writer.pairedWrite(startToken, endToken, newLine, indent, block: () => void)
I like block(), quote(), etc. But there are other pairings of tokens which are important: parentheses, square brackets, backticks for template strings, etc.
Suggested code:
pairedWrite(
startToken: string,
endToken: string,
newLine: boolean,
indent: boolean,
block: () => void
) : void
{
this.write(startToken);
if (newLine) this.newLine();
indent ? this.indent(block) : block();
if (newLine) this.newLine();
this.write(endToken);
}
Paired writes could also be useful for (// #region ..., // #endregion ...) cases.
Actually, I'm not too sure about this. It seems too specific and there's a lot of parameters.
You might be right, it's a little unwieldly. The real point I was trying to make was about startToken and endToken (and of course block). The rest is nice-to-have.