code-block-writer icon indicating copy to clipboard operation
code-block-writer copied to clipboard

Suggestion: writer.pairedWrite(startToken, endToken, newLine, indent, block: () => void)

Open ajvincent opened this issue 2 years ago • 2 comments

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.

ajvincent avatar Mar 24 '23 22:03 ajvincent

Actually, I'm not too sure about this. It seems too specific and there's a lot of parameters.

dsherret avatar Sep 27 '24 00:09 dsherret

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.

ajvincent avatar Oct 03 '24 14:10 ajvincent