advanced-pad
Version:
Left and right string padding with advanced features.
55 lines (38 loc) • 1.89 kB
Markdown
[](https://travis-ci.com/tylerdevs/advanced-pad) [](https://david-dm.org/tylerdevs/advanced-pad) [](https://david-dm.org/tylerdevs/advanced-pad?type=dev) [](https://opensource.org/licenses/MIT)
**Super lightweight and advanced padding module.**
advanced-pad is a super light string padding function with advanced truncation and character padding support.
* **Directional** - One module for padding both left and right.
* **Multi Character Padding** - Pad strings with multiple characters without going over set length.
* **Advanced Truncation** - Easily toggle string truncation based on length of padding.
```
$ npm install advanced-pad
```
```
// include advanced-pad
var pad = require('advanced-pad');
// call a padding function
pad.padLeft(string, len, chr = ' ', trunc = false);
pad.padRight(string, len, chr = ' ', trunc = false);
- string = input string to pad
- len = iteger length to pad string to
- chr = string to use as padding character, can be multi
- trunc = true / false. Setting to true will retun the input string truncated from the left or right if it is longer than len.
// pad with '0' to left with length of 10
pad.padLeft('67454', 10, '0');
Output: 0000067454
// pad with '01' to left with legnth of 15
pad.padLeft('67454, 15, '01');
Output: 010101010167454
// pad with 'x' to right with length of 10
pad.padRight('test', 10, 'x');
Output: testxxxxxx
// pad to with 'x' to right, length of 5, with truncate
pad.padRight('testing', 4, 'x', true);
Output: test
```
MIT © Tyler Colwell