mrozio13pl / pads

Simple function that adds padding to a given string.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

About

Simple function that adds padding to a given string.

License:MIT License


Languages

Language:JavaScript 87.8%Language:TypeScript 12.2%