Answers for "node log centered"

0

node log centered

// Center text horizontally
function logXCentered(s) {
  console.log(' '.repeat(process.stdout.columns / 2 - s.length / 2) + s);
}
logXCentered('This text is centered horizontally.');

// Center text both, horizontally and vertically
function logCentered(s) {
  console.log(
    '\n'.repeat(process.stdout.rows / 2) +
      ' '.repeat(process.stdout.columns / 2 - s.length / 2) +
      s +
      '\n'.repeat(process.stdout.rows / 2 - 1)
  );
}
logCentered('This text is centered.');
Posted by: Guest on September-07-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language