Skip to content
🔡 align-text with ANSI support for CLIs
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
test chore(package): update standard to version 13.0.1 (#57) Jul 12, 2019
.npmrc chore: drop Node 6 from CI testing (#56) Jun 3, 2019
.travis.yml chore(release): 3.0.0 Dec 17, 2018
LICENSE feat: initial commit Apr 30, 2016 chore(package): update dependencies to enable Greenkeeper (#32) Jun 6, 2017
index.js feat: ES2015ify, dropping support for Node <4 (#30) May 1, 2017
package.json chore(package): update standard to version 14.0.0 (#59) Aug 20, 2019


align-text with ANSI support for CLIs

Build Status Coverage Status Standard Version Greenkeeper badge

Easily center- or right- align a block of text, carefully ignoring ANSI escape codes.

E.g. turn this:

ansi text block no alignment :(

Into this:

ansi text block center aligned!


npm install --save ansi-align
var ansiAlign = require('ansi-align')


ansiAlign(text, [opts])

Align the given text per the line with the greatest string-width, returning a new string (or array).


  • text: required, string or array

    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.

  • opts: optional, object

    Options to change behavior, see below.


  • opts.align: string, default 'center'

    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).

  • opts.split: string or RegExp, default '\n'

    The separator to use when splitting the text. Only used if text is given as a string.

  • opts.pad: string, default ' '

    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.

Alias for ansiAlign(text, { align: 'center' }).


Alias for ansiAlign(text, { align: 'right' }).


Alias for ansiAlign(text, { align: 'left' }), which is a no-op.

Similar Packages

  • center-align: Very close to this package, except it doesn't support ANSI codes.
  • left-pad: Great for left-padding but does not support center alignment or ANSI codes.
  • Pretty much anything by the chalk team


ISC © Contributors

You can’t perform that action at this time.