declare global {
  interface String {
    // Renders literal newlines as the two-character sequence \n instead of an actual line break,
    // so multi-line question labels (matching a <br> in the real question text) stay on one
    // line when interpolated into console logs and error messages.
    toLogString(): string;
  }

  interface RegExp {
    // Same as String.prototype.toLogString, so callers can format a RegExp | string questionLabel
    // without branching on which one it is.
    toLogString(): string;
  }
}

String.prototype.toLogString = function (this: string): string {
  return this.replace(/\n/g, "\\n");
};

RegExp.prototype.toLogString = function (this: RegExp): string {
  return this.toString().toLogString();
};

export {};
