Skip to content

xdash API Reference v0.5.14


xdash API Reference / detectCase

Function: detectCase()

detectCase(str): "camel" | "kebab" | "screaming-kebab" | "snake" | "screaming-snake" | "pascal" | "lower" | "upper" | "mixed" | "none"

Defined in: src/string.ts:149

Detects the case of a string

Parameters

str

string

string to detect the case of

Returns

"camel" | "kebab" | "screaming-kebab" | "snake" | "screaming-snake" | "pascal" | "lower" | "upper" | "mixed" | "none"

the detected case of the string

Example

ts
detectCase('fooBar') // returns 'camel'
detectCase('foo-bar') // returns 'kebab'
detectCase('FOO-BAR') // returns 'screaming-kebab'
detectCase('foo_bar') // returns 'snake'
detectCase('FOO_BAR') // returns 'screaming-snake'
detectCase('FooBar') // returns 'pascal'
detectCase('FOO BAR') // returns 'upper'
detectCase('foo bar') // returns 'lower'
detectCase('fooBar-baz') // returns 'mixed
detectCase('foo BAR') // returns 'mixed
detectCase('') // returns 'none'

Released under the MIT License.