All files / generators/_collections spec-emission.util.ts

97.18% Statements 69/71
90.9% Branches 20/22
100% Functions 4/4
97.18% Lines 69/71

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 721x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 549x 549x 549x 549x 549x 549x 1x 1x 1x 835x 835x 835x 835x 835x 835x 835x 1x 1x 1x 473x 1x 1x 473x 1x 1x 473x 438x 438x 473x 27x 27x 473x 1x 1x 5x 5x 5x 5x 5x 5x     1x 1x 1x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 1x  
/**
 * Egyszerű string-builder a spec.ts emission-hez. NEM eval-alapú template-engine —
 * csak `indent`, `block`, és `escape` util-ok.
 *
 * Az indent szóköz-szám (default `2`). A kiadott string-et úgy formálódik, hogy
 * a fogyasztó projekt prettier-je tudja, de már önmagában is olvasható.
 */
export class DyE2E_SpecEmission_Util {
  /**
   * Egy `string`-ben minden newline elé pontosan annyi szóköz kerül, amennyi
   * `level * indentSize`. Az első sor is indent-elődik.
   */
  static indent(text: string, level: number = 1, indentSize: number = 2): string {
    const prefix: string = ' '.repeat(level * indentSize);
    return text
      .split('\n')
      .map((line: string): string => (line.length === 0 ? line : prefix + line))
      .join('\n');
  }
 
  /** TypeScript string-literal-ra escape-eli az inputot (single-quoted). */
  static escapeString(s: string): string {
    return s
      .replace(/\\/g, '\\\\')
      .replace(/'/g, "\\'")
      .replace(/\n/g, '\\n')
      .replace(/\r/g, '\\r')
      .replace(/\t/g, '\\t');
  }
 
  /** TypeScript értékreprezentáció — string, number, boolean, null, array, object. */
  static valueLiteral(v: unknown): string {
    if (v === null) {
      return 'null';
    }
    if (v === undefined) {
      return 'undefined';
    }
    if (typeof v === 'string') {
      return `'${DyE2E_SpecEmission_Util.escapeString(v)}'`;
    }
    if (typeof v === 'number' || typeof v === 'boolean') {
      return String(v);
    }
    if (Array.isArray(v)) {
      return `[${v.map((item: unknown): string => DyE2E_SpecEmission_Util.valueLiteral(item)).join(', ')}]`;
    }
    if (typeof v === 'object') {
      const entries: string[] = Object.entries(v as Record<string, unknown>).map(
        ([k, val]: [string, unknown]): string => `${k}: ${DyE2E_SpecEmission_Util.valueLiteral(val)}`,
      );
      return `{ ${entries.join(', ')} }`;
    }
    return 'undefined';
  }
 
  /** Header-comment block az emit-elt spec.ts tetejéhez. */
  static headerComment(formKey: string, route: string, generatedAt: string, extra?: string): string {
    const extraLine: string = extra ? `\n * ${extra}` : '';
    return `/**
 * Auto-generated by @futdevpro/dynamo-e2e — FormSuite Generator
 * Form key: ${formKey}
 * Route:    ${route}
 * Built at: ${generatedAt}${extraLine}
 *
 * DO NOT EDIT BY HAND. Re-emit via \`dc e2e generate-form-suite\` or
 * \`DyE2E_FormSuite_Generator.emit({...})\` consumer-script.
 */
`;
  }
}