Skip to content

trimStart

Import from @varavel/vdl-plugin-sdk/utils/strings.

function trimStart(str, chars?): string;

Removes matching characters from the start of a string.

By default, the function trims leading whitespace using the platform's built-in whitespace semantics.

When chars is provided, only those characters are removed from the start. A string value is interpreted as a set of individual characters, and an array combines all characters from all entries.

Matching characters that appear later in the string are preserved.

Parameters

Parameter Type Description
str string String to trim.
chars? string | readonly string[] Optional characters to remove instead of whitespace.

Returns

string

A copy of str without the matching leading characters.

Examples

trimStart("  hello  ")
// "hello  "
trimStart("__hello__", "_")
// "hello__"