Socket
Socket
Sign inDemoInstall

ansi-align

Package Overview
Dependencies
5
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Protect your apps from supply chain attacks

Install

ansi-align

align-text with ANSI support for CLIs

    3.0.1latest
    GitHub
    npm

Version published
Maintainers
1
Weekly downloads
8,815,192
decreased by-14.51%

Weekly downloads

Package description

What is ansi-align?

The ansi-align npm package is used to align text within the terminal using ANSI escape codes. It allows for centering, right-aligning, or left-aligning strings within a given width, which is useful for creating visually appealing command-line interfaces.

What are ansi-align's main functionalities?

Center alignment

This feature centers the text within a specified width. The code sample demonstrates how to center the text 'Centered Text' within a width of 20 characters.

const ansiAlign = require('ansi-align');
console.log(ansiAlign.center('Centered Text', {width: 20}));

Right alignment

This feature right-aligns the text within a specified width. The code sample demonstrates how to right-align the text 'Right Aligned' within a width of 20 characters.

const ansiAlign = require('ansi-align');
console.log(ansiAlign.right('Right Aligned', {width: 20}));

Left alignment

This feature left-aligns the text within a specified width. The code sample demonstrates how to left-align the text 'Left Aligned' within a width of 20 characters.

const ansiAlign = require('ansi-align');
console.log(ansiAlign.left('Left Aligned', {width: 20}));

Other packages similar to ansi-align

Changelog

Source

3.0.1 (2021-09-27)

Bug Fixes

  • package: update string-width to version 4.1.0 (#52) (ab5b733)

<a name="3.0.0"></a>

Readme

Source

ansi-align

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!

Install

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

API

ansiAlign(text, [opts])

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

Arguments
  • 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.

Options
  • 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.

ansiAlign.center(text)

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

ansiAlign.right(text)

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

ansiAlign.left(text)

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

License

ISC © Contributors

Keywords

FAQs

Last updated on 27 Sep 2021

Did you know?

Socket installs a GitHub app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc