Skip to content

trim

Remove characters from the ends of a string

131 bytes
since v12.1.0

Usage

Trim specific characters from the start and end of a given string. Like the built-in String.prototype.trim method, but it accepts alternate (other than space) characters you would like to trim.

import * as
import _
_
from 'radashi'
import _
_
.
function trim(str: string, charsToTrim: string): string

Trims all prefix and suffix characters from the given string. Like the builtin trim function but accepts other characters you would like to trim and trims multiple characters.

@see ― https://radashi.js.org/reference/string/trim

@example

trim(' hello ') // => 'hello'
trim('__hello__', '_') // => 'hello'
trim('/repos/:owner/:repo/', '/') // => 'repos/:owner/:repo'
trim('222222__hello__1111111', '12_') // => 'hello'

@version ― 12.1.0

trim
(' hello ', ' ') // => hello
import _
_
.
function trim(str: string, charsToTrim: string): string

Trims all prefix and suffix characters from the given string. Like the builtin trim function but accepts other characters you would like to trim and trims multiple characters.

@see ― https://radashi.js.org/reference/string/trim

@example

trim(' hello ') // => 'hello'
trim('__hello__', '_') // => 'hello'
trim('/repos/:owner/:repo/', '/') // => 'repos/:owner/:repo'
trim('222222__hello__1111111', '12_') // => 'hello'

@version ― 12.1.0

trim
('__hello__', '_') // => hello
import _
_
.
function trim(str: string, charsToTrim: string): string

Trims all prefix and suffix characters from the given string. Like the builtin trim function but accepts other characters you would like to trim and trims multiple characters.

@see ― https://radashi.js.org/reference/string/trim

@example

trim(' hello ') // => 'hello'
trim('__hello__', '_') // => 'hello'
trim('/repos/:owner/:repo/', '/') // => 'repos/:owner/:repo'
trim('222222__hello__1111111', '12_') // => 'hello'

@version ― 12.1.0

trim
('/repos/:owner/', '/') // => repos/:owner

It also handles more than one character to trim.

import _
_
.
function trim(str: string, charsToTrim: string): string

Trims all prefix and suffix characters from the given string. Like the builtin trim function but accepts other characters you would like to trim and trims multiple characters.

@see ― https://radashi.js.org/reference/string/trim

@example

trim(' hello ') // => 'hello'
trim('__hello__', '_') // => 'hello'
trim('/repos/:owner/:repo/', '/') // => 'repos/:owner/:repo'
trim('222222__hello__1111111', '12_') // => 'hello'

@version ― 12.1.0

trim
('222__hello__111', '12_') // => hello