Introduction to wide-align
The wide-align
library is a powerful tool for handling layout alignments with ease in your applications. It simplifies the development process by providing a suite of robust APIs designed to manage various alignment needs efficiently.
Installation
npm install wide-align
API Overview
alignLeft(text, width)
Aligns the text to the left within the specified width.
const align = require('wide-align'); console.log(align.alignLeft('Hello, world!', 20)); // Output: 'Hello, world! '
alignCenter(text, width)
Centers the text within the specified width.
const align = require('wide-align'); console.log(align.alignCenter('Hello, world!', 20)); // Output: ' Hello, world! '
alignRight(text, width)
Aligns the text to the right within the specified width.
const align = require('wide-align'); console.log(align.alignRight('Hello, world!', 20)); // Output: ' Hello, world!'
Advanced Usage
justifyText(text, width)
Justifies the text within the specified width.
const align = require('wide-align'); console.log(align.justifyText('Hello, world!', 20)); // Output: 'Hello, world!'
breakText(text, width)
Breaks the text into multiple lines to fit within the specified width.
const align = require('wide-align'); console.log(align.breakText('Hello, world! This is a long text.', 10)); // Output: 'Hello, // world! // This is // a long // text.'
App Example Using wide-align
Here is a simple application demonstrating the use of the wide-align
library.
const align = require('wide-align'); const text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'; function displayAlignedText() { console.log('--- Center Aligned ---'); console.log(align.alignCenter(text, 50)); console.log('--- Left Aligned ---'); console.log(align.alignLeft(text, 50)); console.log('--- Right Aligned ---'); console.log(align.alignRight(text, 50)); } displayAlignedText(); // Output: // --- Center Aligned --- // Lorem ipsum dolor sit amet, consectetur adipiscing elit. // --- Left Aligned --- // Lorem ipsum dolor sit amet, consectetur adipiscing elit. // --- Right Aligned --- // Lorem ipsum dolor sit amet, consectetur adipiscing elit.
This example demonstrates how to align text to the left, center, and right using the wide-align
library.
Hash: 98889d01465024d4132e9e32f48f779d3caf8db6304ea28b8f781c135a012a8c