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

1.1.1 • Public • Published

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

Package Sidebar

Install

npm i pads

Weekly Downloads

0

Version

1.1.1

License

MIT

Unpacked Size

5.11 kB

Total Files

5

Last publish

Collaborators

  • mrozio