ansi-center-align
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i ansi-center-align

Weekly Downloads

1

Version

1.0.3

License

MIT

Unpacked Size

13.1 kB

Total Files

8

Last publish

Collaborators

  • leondreamed