Files
renovate/lib/util/json-writer/json-writer.ts
Sergei Zharinov 930cf6633c refactor: Rewrite imports with .ts extensions (#40700)
fix: Additional vi.mock path corrections and prettier formatting
2026-01-26 22:48:17 +00:00

32 lines
796 B
TypeScript

import type { CodeFormat } from './code-format.ts';
import type { IndentationType } from './indentation-type.ts';
export class JSONWriter {
private readonly indentationType: IndentationType;
private readonly indentationSize: number;
constructor(codeFormat: CodeFormat = {}) {
this.indentationSize = codeFormat.indentationSize ?? 2;
this.indentationType = codeFormat.indentationType ?? 'space';
}
public write(json: unknown, newLineAtTheEnd = true): string {
let content = JSON.stringify(json, null, this.indentation);
if (newLineAtTheEnd) {
content = content.concat('\n');
}
return content;
}
private get indentation(): string | number {
if (this.indentationType === 'tab') {
return '\t';
}
return this.indentationSize;
}
}