tab-align
Align text with whitespaces + position
!Build Statustravis-badgetravis-url !Versionversion-badgeversion-url !Downloadsdownloads-badgedownloads-url !MIT Licensemit-license-badgemit-license-url !Dependency Statusdaviddm-badgedaviddm-url !NSP Statusnsp-badgensp-url
!Code of Conductcoc-badgecoc-url
This package helps aligning rows of texts with ease. Texts can be aligned according to your preferences such as the position of the text, how many whitespaces between columns, replacing whitespaces with other symbols, et al.
Pre-requisite
- Node.jsnode-js-url >= 8.6.0
- NPMnpm-url >= 5.3.0 (NPMnpm-url comes Node.jsnode-js-url so there is no need to install separately.)
How to use
Install
# Install package with NPM
$ npm install --save tab-align
How to use
The following is a simple code snippet:/** Import the package */
const tabAlign = require('tab-align');
/** Setting up with the position and whitespaces for alignment */
const pos = 'end';
const whitespaces = 4;
const allPossibleTitles = [
'really really long title',
'random title',
'short title',
'how\'s your day',
];
const fillWith = '.';
const alignText = tabAlign(allPossibleTitles, pos, whitespaces, fillWith);
console.log(alignText('Today\'s title'));
// This logs `........................Today's title`
tabAlign(stringArrays, alignTo, whitespaces, fillWith)
stringArrays
<stringstring-mdn-url> An array of strings to determine the length of the longest title.alignTo
<stringstring-mdn-url> Position to align text to. Possible values:start
,center
, orend
.whitespaces
<numbernumber-mdn-url> Number of whitespaces to fill in.fillWith
<stringstring-mdn-url> Symbol to replace whitespaces during the filling in.- returns <Functionfunction-mdn-url>
text
<stringstring-mdn-url> Text for alignment.