trim es-toolkit
Removes whitespace or specified characters from the beginning and end of a string.
Usage
trim(str, chars?)
Use trim when you want to remove unnecessary characters from the start and end of a string. If no specific characters are specified, it removes whitespace characters.
When you specify multiple characters as an array, all characters that match any of them are removed.
Parameters
The string to remove characters from the beginning and end.
The characters to remove. Can use a string or character array. Defaults to whitespace characters.
Returns
Returns a new string with the specified characters removed from the beginning and end.
Errors
Throws an error if chars is a string with a length other than 1.
Source: es-toolkit
Re-exported verbatim from es-toolkit. Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.