paddery
v1.1.1
Published
Pads text left or right, using user selected characters and user selected amount of times to pad.
Downloads
58
Maintainers
Readme
🛡️ paddery
the left-pad killer that actually pads right (and both ways).
📦 installation
npm install paddery🚀 usage
import it, instantiate it, pad it. it's that simple.
// commonjs
const Paddery = require('paddery');
const paddery = new Paddery();
// or esm
import Paddery from 'paddery';
// 🡸 pad left
paddery.pad("left", "+", 4, "cat");
// returns: "++++cat"
// 🡺 pad right
paddery.pad("right", "*", 3, "dog");
// returns: "dog***"
// 🡸🡺 pad both ways
paddery.pad("lr", "=", 2, "bird");
// returns: "==bird=="
// 🛡️ built-in error handling
paddery.pad("up", "+", 2, "cat");
// returns: "The direction set is invalid! ('left', 'right' or 'lr')"
paddery.pad("left", "+", -5, "cat");
// returns: "Invalid timesToPad!"
// custom padding in both directions! including rounding for timeToPad!
paddery.pad_c({
"left": {
"char": "%",
"timesToPad": 3
},
"right": {
"char" "("
"timeToPad": 4.5
}}, "cat")
// returns: "%%%cat((((("🧠 API Reference
| Parameter | Type | Description |
|---------------|----------|-------------|
| direction | string | Must be "left", "right", or "lr". |
| charToPad | string | The character(s) to repeat (e.g. " ", "0", "+"). |
| timesToPad | number | Number of times to repeat the character. Must be >= 0. |
| stringToAdd | string | The original string to pad. |
| config | string | JSON including the config for pad_c |
📜 license
mit. do whatever you want with it, just don't blame me if you pad too hard.
