padEnd

Pads the str from the end to the specified length with the padChar.

Usage Scenarios

  • Text Alignment: In text formatting, align strings to a specific width.
  • Data Formatting: In data output, ensure strings have a consistent length.

Example

import { padEnd } from 'funtool/string'

padEnd('hello', 10, '*'); // 'hello*****'

Signature

function padEnd(str: string, length: number, padChar: string = ' '): string

Parameters

  • str ( string ): The input string.
  • length ( number ): The target length of the string.
  • padChar ( string ): The character to pad with. Defaults to a space.

Returns

  • ( string ): The padded string.