This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

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

1.0.2 • Public • Published

term-align

Align text based on terminal's width.

Example

NOTE: This does not use methods such as writeStream#cursorTo. Instead, it returns a string that can be then used in the console, using, e.g. console#log or writeStream#write.

API

align(input, options) or align(input, alignment, options)

Aligns given input.

  • input {String} - Text to be aligned.
  • options - Alignment options to configure how the string should be displayed:
    • align - Alignment of the text ('left, 'center', 'right'). Default is 'left'.
    • offset {Number} - Offset to adjust the alignment. Can be a number or a percentage string. Default is 0.
    • textAlign - Text alignment within the alignment width ('left', 'center', 'right'). Should be used only if your input has multiple lines. Default is the same as align.
  • alignment - Alignment of the text ('left, 'center', 'right'). Default is 'left'.
  • Returns an aligned string.

Usage

const align = require('term-align');

console.log(align('Hello, world!', 'center')); // <= centered: '      Hello, world!      '
console.log(align('Another example.', { align: 'right', offset: 1 })); // <= '        Another example. '
console.log(align('Multiple lines\nWorks', { align: 'center', textAlign: 'right' }));
// Results:
// '      Multiple lines      '
// '               Works      '

Check out more examples.

License

Released under the MIT License.

Readme

Keywords

Package Sidebar

Install

npm i term-align

Weekly Downloads

0

Version

1.0.2

License

MIT

Unpacked Size

8.3 kB

Total Files

5

Last publish

Collaborators

  • mrozio