Repeat Pad
utilcn/repeat-padFreeUtility
Repeat a string until it reaches the desired length.
Install it
npx shadcn@latest add https://utilcn.dev/r/repeat-pad.jsonSource
1/**2 * Pads a string evenly on both sides until it reaches the desired length.3 *4 * @param str - The input string.5 * @param length - Desired total length.6 * @param pad - The character/string used as padding (default: space).7 * @returns The padded string centered with the given padding.8 *9 * @example10 * repeatPad("TS", 6, "-"); // "--TS--"11 */12export function repeatPad(str: string, length: number, pad = ' '): string {13 const total = Math.max(length - str.length, 0);14 const left = Math.floor(total / 2);15 const right = total - left;16 return pad.repeat(left) + str + pad.repeat(right);17}
Files it writes
More from utilcn
All 17 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Capitalizecapitalize | utilcn | Utilities | Free | no deps | |
| Capitalize Allcapitalize-all | utilcn | Utilities | Free | no deps | |
| Environment Server Configurationenv-server | utilcn | Utilities | Free | 1 dep | |
| Generate Presigned Download URLgenerate-presigned-download-url | utilcn | Utilities | Free | 2 deps · 2 files | |
| Generate Presigned Upload URLgenerate-presigned-upload-url | utilcn | Utilities | Free | 2 deps · 2 files | |
| Reverse Stringreverse-string | utilcn | Utilities | Free | no deps | |
| To Camel Caseto-camel-case | utilcn | Utilities | Free | no deps | |
| To Kebab Caseto-kebab-case | utilcn | Utilities | Free | no deps |
