Skip to content

Class: Stringable ​

Defined in: src/str.ts:6

Fluent string manipulation class inspired by Laravel's Str and Stringable

Constructors ​

Constructor ​

new Stringable(value): Stringable

Defined in: src/str.ts:9

Parameters ​

value ​

unknown

Returns ​

Stringable

Methods ​

toString() ​

toString(): string

Defined in: src/str.ts:18

Get the raw string value

Returns ​

string

The raw string


get() ​

get(): string

Defined in: src/str.ts:27

Alias for toString()

Returns ​

string

The raw string


title() ​

title(): this

Defined in: src/str.ts:36

Convert to title case

Returns ​

this

The Stringable instance


slug() ​

slug(): this

Defined in: src/str.ts:46

Convert to slug

Returns ​

this

The Stringable instance


snake() ​

snake(): this

Defined in: src/str.ts:56

Convert to snake_case

Returns ​

this

The Stringable instance


kebab() ​

kebab(): this

Defined in: src/str.ts:66

Convert to kebab-case

Returns ​

this

The Stringable instance


camel() ​

camel(): this

Defined in: src/str.ts:76

Convert to camelCase

Returns ​

this

The Stringable instance


studly() ​

studly(): this

Defined in: src/str.ts:86

Convert to StudlyCase

Returns ​

this

The Stringable instance


limit() ​

limit(size, end?): this

Defined in: src/str.ts:98

Limit the string length

Parameters ​

size ​

number

The maximum length

end? ​

string = '…'

The string to append if limited

Returns ​

this

The Stringable instance


append() ​

append(...values): this

Defined in: src/str.ts:112

Append a value to the string

Parameters ​

values ​

...unknown[]

The values to append

Returns ​

this

The Stringable instance


prepend() ​

prepend(...values): this

Defined in: src/str.ts:123

Prepend a value to the string

Parameters ​

values ​

...unknown[]

The values to prepend

Returns ​

this

The Stringable instance


finish() ​

finish(cap): this

Defined in: src/str.ts:134

Cap the string with a value if it doesn't already end with it

Parameters ​

cap ​

string

The string to end with

Returns ​

this

The Stringable instance


start() ​

start(prefix): this

Defined in: src/str.ts:145

Start the string with a value if it doesn't already start with it

Parameters ​

prefix ​

string

The string to start with

Returns ​

this

The Stringable instance


replace() ​

replace(search, replace): this

Defined in: src/str.ts:157

Replace the first occurrence of a value

Parameters ​

string | RegExp

The value to search for

replace ​

string

The value to replace with

Returns ​

this

The Stringable instance


replaceAll() ​

replaceAll(search, replace): this

Defined in: src/str.ts:169

Replace all occurrences of a value

Parameters ​

search ​

string | RegExp

The value to search for

replace ​

string

The value to replace with

Returns ​

this

The Stringable instance


reverse() ​

reverse(): this

Defined in: src/str.ts:184

Reverse the string

Returns ​

this

The Stringable instance


mask() ​

mask(character, index, length?): this

Defined in: src/str.ts:197

Mask a portion of the string

Parameters ​

character ​

string

The masking character

index ​

number

The starting index

length? ​

number

The number of characters to mask

Returns ​

this

The Stringable instance


trim() ​

trim(chars?): this

Defined in: src/str.ts:208

Trim the string

Parameters ​

chars? ​

string

The characters to trim (defaults to whitespace)

Returns ​

this

The Stringable instance


lower() ​

lower(): this

Defined in: src/str.ts:223

Convert to lower case

Returns ​

this

The Stringable instance


upper() ​

upper(): this

Defined in: src/str.ts:233

Convert to upper case

Returns ​

this

The Stringable instance


capitalize() ​

capitalize(): this

Defined in: src/str.ts:243

Capitalize the first letter

Returns ​

this

The Stringable instance


contains() ​

contains(needles): boolean

Defined in: src/str.ts:254

Check if string contains a value

Parameters ​

needles ​

string | string[]

The values to search for

Returns ​

boolean

True if the string contains any of the values


containsAll() ​

containsAll(needles): boolean

Defined in: src/str.ts:267

Check if string contains all values

Parameters ​

needles ​

string[]

The values to search for

Returns ​

boolean

True if the string contains all values


startsWith() ​

startsWith(needles): boolean

Defined in: src/str.ts:277

Check if string starts with a value

Parameters ​

needles ​

string | string[]

The values to check

Returns ​

boolean

True if the string starts with any of the values


endsWith() ​

endsWith(needles): boolean

Defined in: src/str.ts:290

Check if string ends with a value

Parameters ​

needles ​

string | string[]

The values to check

Returns ​

boolean

True if the string ends with any of the values


pipe() ​

pipe<U>(callback): U

Defined in: src/str.ts:303

Execute a callback with the stringable and return the result

Type Parameters ​

U ​

U

Parameters ​

callback ​

(str) => U

The callback to execute

Returns ​

U

The result of the callback


when() ​

when(condition, callback): this

Defined in: src/str.ts:314

Conditionally execute a callback

Parameters ​

condition ​

boolean | (() => boolean)

The condition to check

callback ​

(str) => void

The callback to execute

Returns ​

this

The Stringable instance


tap() ​

tap(callback): this

Defined in: src/str.ts:328

Execute a callback and return the stringable (for side effects)

Parameters ​

callback ​

(str) => void

The callback to execute

Returns ​

this

The Stringable instance

Documentation of 1.0.13 , built from cf61d3b on 1.0.13 by pipeline #2985011498 on 2026-10-21.