trim
Import from @varavel/vdl-plugin-sdk/utils/strings.
function trim(str, chars?): string;
Removes matching characters from both ends of a string.
By default, the function trims leading and trailing whitespace using the platform's built-in whitespace semantics.
When chars is provided, only those characters are trimmed from the start
and end of the string. A string value is interpreted as a set of individual
characters, and an array combines all characters from all entries.
For example, trim("__value--", "_-") and
trim("__value--", ["_", "-"]) both return "value".
Characters are removed only at the outer edges; matching characters inside 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 and trailing characters.
Examples
trim(" hello ")
// "hello"
trim("__hello--", ["_", "-"])
// "hello"