mirror of
https://github.com/toss/es-toolkit.git
synced 2024-12-02 12:52:23 +03:00
1.1 KiB
1.1 KiB
padEnd
::: info
This function is only available in es-toolkit/compat
for compatibility reasons. It either has alternative native JavaScript APIs or isn’t fully optimized yet.
When imported from es-toolkit/compat
, it behaves exactly like lodash and provides the same functionalities, as detailed here.
:::
Pads the end of a string with a given character until it reaches the specified length.
If the length is less than or equal to the original string's length, or if the padding character is an empty string, the original string is returned unchanged.
Signature
function padEnd(str: string, length = 0, chars = ' '): string;
Parameters
str
(string
): The string to pad.length
(number
): The length of the resulting string. Defaults to0
.char
(string
): The character to pad the string with. Defaults to' '
.
Returns
Returns a new string padded with the specified character until it reaches the specified length.
Examples
padEnd('hello', 10, 'a'); // 'helloaaaaa'
padEnd('hello', 3, 'a'); // 'hello'
padEnd('hello', 5, ''); // 'hello'