3 > align-text with ANSI support for CLIs
5 [![Build Status](https://travis-ci.org/nexdrew/ansi-align.svg?branch=master)](https://travis-ci.org/nexdrew/ansi-align)
6 [![Coverage Status](https://coveralls.io/repos/github/nexdrew/ansi-align/badge.svg?branch=master)](https://coveralls.io/github/nexdrew/ansi-align?branch=master)
7 [![Standard Version](https://img.shields.io/badge/release-standard%20version-brightgreen.svg)](https://github.com/conventional-changelog/standard-version)
9 Easily center- or right- align a block of text, carefully ignoring ANSI escape codes.
13 <img width="281" alt="ansi text block no alignment :(" src="https://cloud.githubusercontent.com/assets/1929625/14937509/7c3076dc-0ed7-11e6-8c16-4f6a4ccc8346.png">
17 <img width="278" alt="ansi text block center aligned!" src="https://cloud.githubusercontent.com/assets/1929625/14937510/7c3ca0b0-0ed7-11e6-8f0a-541ca39b6e0a.png">
22 npm install --save ansi-align
26 var ansiAlign = require('ansi-align')
31 ### `ansiAlign(text, [opts])`
33 Align the given text per the line with the greatest [`string-width`](https://github.com/sindresorhus/string-width), returning a new string (or array).
37 - `text`: required, string or array
39 The text to align. If a string is given, it will be split using either the `opts.split` value or `'\n'` by default. If an array is given, a different array of modified strings will be returned.
41 - `opts`: optional, object
43 Options to change behavior, see below.
47 - `opts.align`: string, default `'center'`
49 The alignment mode. Use `'center'` for center-alignment, `'right'` for right-alignment, or `'left'` for left-alignment. Note that the given `text` is assumed to be left-aligned already, so specifying `align: 'left'` just returns the `text` as is (no-op).
51 - `opts.split`: string or RegExp, default `'\n'`
53 The separator to use when splitting the text. Only used if text is given as a string.
55 - `opts.pad`: string, default `' '`
57 The value used to left-pad (prepend to) lines of lesser width. Will be repeated as necessary to adjust alignment to the line with the greatest width.
59 ### `ansiAlign.center(text)`
61 Alias for `ansiAlign(text, { align: 'center' })`.
63 ### `ansiAlign.right(text)`
65 Alias for `ansiAlign(text, { align: 'right' })`.
67 ### `ansiAlign.left(text)`
69 Alias for `ansiAlign(text, { align: 'left' })`, which is a no-op.
73 - [`center-align`](https://github.com/jonschlinkert/center-align): Very close to this package, except it doesn't support ANSI codes.
74 - [`left-pad`](https://github.com/camwest/left-pad): Great for left-padding but does not support center alignment or ANSI codes.
75 - Pretty much anything by the [chalk](https://github.com/chalk) team