1.0.3 • Published 1 year ago

ansi-center-align v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

ansi-center-align NPM version NPM monthly downloads NPM total downloads

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 align
  • width {number} (optional): the total width of each line in the expected result, after it's centered.

Examples

console.log(centerAlign('foo')); //=> 'foo' (does nothing)
console.log(centerAlign('foo', 12)); //=> '    foo    '
console.log(centerAlign('foo', 10)); //=> '   foo   '
console.log(centerAlign('foo', 8));  //=> '  foo  '

Multiple lines

If expected width is not provided, the length of the longest line will be used.

Example

If used on the following:

// value can be a string, or an array of strings
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