Skip to content

Instantly share code, notes, and snippets.

@talitaoliveira
Last active November 14, 2018 03:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save talitaoliveira/4fba10b9454d88697541e347debfa7cb to your computer and use it in GitHub Desktop.
Save talitaoliveira/4fba10b9454d88697541e347debfa7cb to your computer and use it in GitHub Desktop.
Using String padding - ES8 (padStart and padEnd) by length of previous line.
const firstLine = '=======================================================';
const lastLine = firstLine;
const lenghtLines = firstLine.length;
let welcomeText = '⭐️ Hello World! Webpack + Babel! ⭐️';
const lengthText = welcomeText.length;
const leftToComplete = lenghtLines - lengthText;
const halfComplete = leftToComplete/2;
welcomeText = welcomeText.padStart(lenghtLines-halfComplete, '~');
welcomeText = welcomeText.padEnd(lenghtLines, '~');
console.log(`
${firstLine}
${welcomeText}
${lastLine}
`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment