pads
v1.1.1
Published
Simple function that adds padding to a given string.
Downloads
9
Maintainers
Readme
pads
Simple function that adds padding to a given string.
Install
npm i pads
Usage
const pads = require('pads');
pads('test!', 7, 'left');
pads('test!', 4, 'right');
pads('test!', 4, 'right', { reverseAlignment: true });
pads('test!', 6, 'center');
pads('test!', 8, 'center', '-');
pads('test!', 3, 'left', '+', { reverseAlignment: true });
// <= ' test!'
// <= 'test! '
// <= ' test!'
// <= ' test! '
// <= '----test!----'
// <= 'test!+++'
pads (str, length, align?, char? | options?, options?)
Adds padding to the string.
str
Type: string
The string to add padding to.
length
Type: number
Amount of padding.
align
Type: string
Padding alignment. Default is left
.
Alignments:
left
center
right
char
Type: string
String to fill the gap. Default is ' '
(empty space).
options
Type: object
reverseAlignment
Type: boolean
Default: false
Inverts the alignment, e.g., left
-> right
.
License
MIT