Function centerPad

Pads the string with the padWith so that it appears in the center of a new string with the provided length.

  • Parameters

    • str: string
    • length: number
    • padWith: string = ' '

    Returns string

    const str = "Hello, World!";

    const padded = centerPad(str, str.length + 4);

    console.log(padded); // ' Hello, World! '