ansi-center-align
Center-align the text in a string. Handles ANSI styles.
This package was based on the wonderful center-align package created by Jon Schlinkert
Install
Install with your favorite package manager:
npm install --save ansi-center-align
Usage
import { centerAlign } from 'ansi-center-align';
centerAlign(val, width);
Params
val
{string | string[]}: the string or array of strings to center alignwidth
{number} (optional): the total width of each line in the expected result, after it's centered.
Examples
console.log(centerAlign('foo'));
console.log(centerAlign('foo', 12));
console.log(centerAlign('foo', 10));
console.log(centerAlign('foo', 8));
Multiple lines
If expected width
is not provided, the length of the longest line will be used.
Example
If used on the following:
centerAlign([
'Lorem ipsum dolor sit amet,',
'consectetur adipiscing',
'elit, sed do eiusmod tempor incididunt',
'ut labore et dolore',
'magna aliqua. Ut enim ad minim',
'veniam, quis'
]);
The result would be:
Lorem ipsum dolor sit amet,
consectetur adipiscing
elit, sed do eiusmod tempor incididunt
ut labore et dolore
magna aliqua. Ut enim ad minim
veniam, quis
About
Related projects