dt-utils / trim
Function: trim()
trim(
str
):string
Defined in: trim/index.ts:27
Removes leading and trailing whitespace characters from a string.
Parameters
str
string
The string to trim
Returns
string
The trimmed string, or the original value if input is not a string
Description
Handles various Unicode whitespace characters including spaces, tabs, and no-break spaces.
Example
typescript
import { trim } from 'dt-utils';
// Removes leading and trailing whitespace characters
trim(' hello world '); // => 'hello world'
trim('\t\nhello\r '); // => 'hello'
// handles full-width spaces
trim(' hello '); // => 'hello'
// returns original value for non-strings
trim(123); // => 123