1.0.2 • Published 2 years ago
term-align v1.0.2
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 is0.textAlign- Text alignment within the alignment width ('left','center','right'). Should be used only if your input has multiple lines. Default is the same asalign.
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.