padStart

Pads the str from the start 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 { padStart } from 'funtool';

padStart('hello', 10, '*'); // ✅ '*****hello'

Signature

function padStart(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.