-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprinterHelper.ts
More file actions
20 lines (20 loc) · 762 Bytes
/
printerHelper.ts
File metadata and controls
20 lines (20 loc) · 762 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
export class PrinterHelper {
public static printFieldsMultiline(fields: string[], lineLength: number): string {
const FIELD_SPLIT = ', ';
const LINE_SPLIT = '\n';
const lines = new Array<string>();
let fieldsInLine = new Array<string>();
for (const field of fields) {
const currentLineLength = fieldsInLine.reduce((count, x) => count + x.length, 0) + field.length;
if (currentLineLength + field.length + FIELD_SPLIT.length * fieldsInLine.length > lineLength) {
lines.push(fieldsInLine.join(', '));
fieldsInLine = new Array<string>();
}
fieldsInLine.push(field);
}
if (fieldsInLine.length > 0) {
lines.push(fieldsInLine.join(FIELD_SPLIT));
}
return lines.join(LINE_SPLIT);
}
}