• Add padding to string

    Parameters

    • text: any

      Text that will be padded

    • length: number

      Target length

    • char: string = ' '

      Character to use as padding, defaults to space

    • start: boolean = true

      Will pad start of text if true, or the end if false

    Returns any

    Padded string

    const now = new Date();
    const padded = now.getHours() + ':' + pad(now.getMinutes(), 2, '0');
    console.log(padded); // Output: "2:05"

    Please use String.padStart & String.padEnd