showing results for - "node log centered"
Ben
09 Jul 2020
1// Center text horizontally
2function logXCentered(s) {
3  console.log(' '.repeat(process.stdout.columns / 2 - s.length / 2) + s);
4}
5logXCentered('This text is centered horizontally.');
6
7// Center text both, horizontally and vertically
8function logCentered(s) {
9  console.log(
10    '\n'.repeat(process.stdout.rows / 2) +
11      ' '.repeat(process.stdout.columns / 2 - s.length / 2) +
12      s +
13      '\n'.repeat(process.stdout.rows / 2 - 1)
14  );
15}
16logCentered('This text is centered.');