21 lines
527 B
TypeScript
21 lines
527 B
TypeScript
export type lineAppender = (ind: number, line: string | string[]) => void;
|
|
|
|
export function LineAppender(indentSize = 3): {
|
|
a: lineAppender;
|
|
getResult: () => string;
|
|
} {
|
|
const lines: string[] = [];
|
|
|
|
return {
|
|
a: (indentation: number, line: string | string[]) => {
|
|
if (!Array.isArray(line)) {
|
|
line = [line];
|
|
}
|
|
line.forEach((l) =>
|
|
lines.push(" ".repeat(indentation * indentSize) + l.trim())
|
|
);
|
|
},
|
|
getResult: () => lines.join("\n"),
|
|
};
|
|
}
|