Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ansi-center-align

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ansi-center-align

Center-align the text in a string. Supports ANSI styles.

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
13
Maintainers
1
Weekly downloads
 
Created
Source

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

FAQs

Package last updated on 10 Jan 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc