LuckyCase
Convert and detect various letter cases in strings
- LuckyCase
- .getVersion() →
string
- .case(string, allow_prefixed_underscores) →
string
|null
- .cases(string, allow_prefixed_underscores) →
Array.<string>
|null
- .convertCase(string, case_type, preserve_prefixed_underscores) →
string
- .isValidCaseType(case_type) →
boolean
- .isValidCaseString(string) →
boolean
- .toUpperCase(string) →
string
- .isUpperCase(string) →
boolean
- .toLowerCase(string) →
string
- .isLowerCase(string) →
boolean
- .toSnakeCase(string, preserve_prefixed_underscores) →
string
- .isSnakeCase(string, allow_prefixed_underscores) →
boolean
- .toUpperSnakeCase(string, preserve_prefixed_underscores) →
string
- .isUpperSnakeCase(string, allow_prefixed_underscores) →
boolean
- .toPascalCase(string, preserve_prefixed_underscores) →
string
- .isPascalCase(string, allow_prefixed_underscores) →
boolean
- .toCamelCase(string, preserve_prefixed_underscores) →
string
- .isCamelCase(string, allow_prefixed_underscores) →
boolean
- .toDashCase(string, preserve_prefixed_underscores) →
string
- .isDashCase(string, allow_prefixed_underscores) →
boolean
- .toUpperDashCase(string, preserve_prefixed_underscores) →
string
- .isUpperDashCase(string, allow_prefixed_underscores) →
boolean
- .toTrainCase(string, preserve_prefixed_underscores) →
string
- .isTrainCase(string, allow_prefixed_underscores) →
boolean
- .toWordCase(string, preserve_prefixed_underscores) →
string
- .isWordCase(string, allow_prefixed_underscores) →
boolean
- .toUpperWordCase(string, preserve_prefixed_underscores) →
string
- .isUpperWordCase(string, allow_prefixed_underscores) →
boolean
- .toCapitalWordCase(string, preserve_prefixed_underscores) →
string
- .isCapitalWordCase(string, allow_prefixed_underscores) →
boolean
- .toSentenceCase(string, preserve_prefixed_underscores) →
string
- .isSentenceCase(string, allow_prefixed_underscores) →
boolean
- .toCapital(string, skip_prefixed_underscores) →
string
- .capitalize(string, skip_prefixed_underscores) →
string
- .isCapital(string, skip_prefixed_underscores) →
boolean
- .isCapitalized(string, skip_prefixed_underscores) →
boolean
- .decapitalize(string, skip_prefixed_underscores) →
string
- .isNotCapital(string, skip_prefixed_underscores) →
boolean
- .isDecapitalized(string, skip_prefixed_underscores) →
boolean
- .toMixedCase(string, preserve_prefixed_underscores) →
string
- .isMixedCase(string, allow_prefixed_underscores) →
boolean
- .swapCase(string, preserve_prefixed_underscores) →
string
- .constantize(string) →
any
- .deconstantize(constant, case_type) →
string
- .cutUnderscoresAtStart(string) →
string
- .getUnderscoresAtStart(string) →
string
- .splitCaseString(string) →
Array.<string>
- .getVersion() →
Get the version of the used library
Get type of case of string (one key of LuckyCase.CASES)
If more than one case matches, the first match wins. Match prio is the order of the regex in LuckyCase.CASES
If you want or need to know all cases, use plural version of this method
If you want to check explicitly for one case, use its check method,
e.g. isSnakeCase() for SNAKE_CASE, etc...
Returns: string
| null
- symbol of type, null if no match
Param | Type | Default |
---|---|---|
string | string |
|
allow_prefixed_underscores | boolean |
true |
Get types of cases of string (keys of LuckyCase.CASES)
Returns: Array.<string>
| null
- symbols of types, null if no one matches
Param | Type | Default |
---|---|---|
string | string |
|
allow_prefixed_underscores | boolean |
true |
Convert a string into the given case type
Param | Type | Default | Description |
---|---|---|---|
string | string |
to convert | |
case_type | string |
can be UPPER_CASE or lower_case, e.g. 'SNAKE_CASE' or 'snake_case' | |
preserve_prefixed_underscores | boolean |
true |
Check if given case type is a valid case type
Param | Type | Description |
---|---|---|
case_type | string |
to check |
Check if the string matches any of the available cases
Param | Type | Description |
---|---|---|
string | string |
to check |
Convert all characters inside the string into upper case
Param | Type | Description |
---|---|---|
string | string |
to convert |
Example
conversion
'this-isAnExample_string' => 'THIS-ISANEXAMPLE_STRING'
Check if all characters inside the string are upper case
Param | Type | Description |
---|---|---|
string | string |
to check |
Convert all characters inside the string into lower case
Param | Type | Description |
---|---|---|
string | string |
to convert |
Example
conversion
'this-isAnExample_string' => 'this-isanexample_string'
Check if all characters inside the string are lower case
Param | Type | Description |
---|---|---|
string | string |
to check |
Convert the given string from any case into snake case
Param | Type | Default | Description |
---|---|---|---|
string | string |
to convert | |
preserve_prefixed_underscores | boolean |
true |
Example
conversion
'this-isAnExample_string' => 'this_is_an_example_string'
Check if the string is snake case
Param | Type | Default | Description |
---|---|---|---|
string | string |
to check | |
allow_prefixed_underscores | boolean |
true |
Convert the given string from any case into upper snake case
Param | Type | Default | Description |
---|---|---|---|
string | string |
to convert | |
preserve_prefixed_underscores | boolean |
true |
Example
conversion
'this-isAnExample_string' => 'THIS_IS_AN_EXAMPLE_STRING'
Check if the string is upper snake case
Param | Type | Default | Description |
---|---|---|---|
string | string |
to check | |
allow_prefixed_underscores | boolean |
true |
Convert the given string from any case into pascal case
Param | Default | Description |
---|---|---|
string | to convert | |
preserve_prefixed_underscores | true |
Example
conversion
'this-isAnExample_string' => 'ThisIsAnExampleString'
Check if the string is upper pascal case
Param | Type | Default | Description |
---|---|---|---|
string | string |
to check | |
allow_prefixed_underscores | boolean |
true |
Convert the given string from any case into camel case
Param | Type | Default | Description |
---|---|---|---|
string | string |
to convert | |
preserve_prefixed_underscores | boolean |
true |
Example
conversion
'this-isAnExample_string' => 'thisIsAnExampleString'
Check if the string is camel case
Param | Type | Default | Description |
---|---|---|---|
string | string |
to check | |
allow_prefixed_underscores | boolean |
true |
Convert the given string from any case into dash case
Param | Type | Default | Description |
---|---|---|---|
string | string |
to convert | |
preserve_prefixed_underscores | boolean |
true |
Example
conversion
'this-isAnExample_string' => 'this-is-an-example-string'
Check if the string is dash case
Param | Type | Default | Description |
---|---|---|---|
string | string |
to check | |
allow_prefixed_underscores | boolean |
true |
Convert the given string from any case into upper dash case
Param | Type | Default | Description |
---|---|---|---|
string | string |
to convert | |
preserve_prefixed_underscores | boolean |
true |
Example
conversion
'this-isAnExample_string' => 'THIS-IS-AN-EXAMPLE-STRING'
Check if the string is upper dash case
Param | Type | Default | Description |
---|---|---|---|
string | string |
to check | |
allow_prefixed_underscores | boolean |
true |
Convert the given string from any case into train case
Param | Type | Default | Description |
---|---|---|---|
string | string |
to convert | |
preserve_prefixed_underscores | boolean |
true |
Example
conversion
'this-isAnExample_string' => 'This-Is-An-Example-String'
Check if the string is train case
Param | Type | Default | Description |
---|---|---|---|
string | string |
to check | |
allow_prefixed_underscores | boolean |
true |
Convert the given string from any case into word case
Param | Type | Default | Description |
---|---|---|---|
string | string |
to convert | |
preserve_prefixed_underscores | boolean |
true |
Example
conversion
'this-isAnExample_string' => 'this is an example string'
Check if the string is word case
Param | Type | Default | Description |
---|---|---|---|
string | string |
to check | |
allow_prefixed_underscores | true |
Convert the given string from any case into upper word case
Param | Type | Default | Description |
---|---|---|---|
string | string |
to convert | |
preserve_prefixed_underscores | boolean |
true |
Example
conversion
'this-isAnExample_string' => 'THIS IS AN EXAMPLE STRING'
Check if the string is upper word case
Param | Default | Description |
---|---|---|
string | to check | |
allow_prefixed_underscores | true |
Convert the given string from any case into capital word case
Param | Type | Default | Description |
---|---|---|---|
string | string |
to convert | |
preserve_prefixed_underscores | boolean |
true |
Example
conversion
'this-isAnExample_string' => 'This Is An Example String'
Check if the string is capital word case
Param | Type | Default | Description |
---|---|---|---|
string | string |
to check | |
allow_prefixed_underscores | boolean |
true |
Convert the given string from any case into sentence case
Param | Type | Default | Description |
---|---|---|---|
string | string |
to convert | |
preserve_prefixed_underscores | boolean |
true |
Example
conversion
'this-isAnExample_string' => 'This is an example string'
Check if the string is sentence case
Param | Type | Default | Description |
---|---|---|---|
string | string |
to check | |
allow_prefixed_underscores | boolean |
true |
Convert the first character to capital
Param | Type | Default | Description |
---|---|---|---|
string | string |
to convert | |
skip_prefixed_underscores | boolean |
false |
Convert the first character to capital
Param | Type | Default | Description |
---|---|---|---|
string | string |
to convert | |
skip_prefixed_underscores | boolean |
false |
Check if the strings first character is a capital letter
Param | Type | Default |
---|---|---|
string | string |
|
skip_prefixed_underscores | boolean |
false |
Check if the strings first character is a capital letter
Param | Type | Default |
---|---|---|
string | string |
|
skip_prefixed_underscores | boolean |
false |
Convert the first character to lower case
Param | Type | Default | Description |
---|---|---|---|
string | string |
to convert | |
skip_prefixed_underscores | boolean |
false |
Check if the strings first character is a lower case letter
Param | Type | Default |
---|---|---|
string | string |
|
skip_prefixed_underscores | boolean |
false |
Check if the strings first character is a lower case letter
Param | Type | Default |
---|---|---|
string | string |
|
skip_prefixed_underscores | boolean |
false |
Convert the given string from any case into mixed case.
The new string is ensured to be different from the input.
Param | Type | Default |
---|---|---|
string | string |
|
preserve_prefixed_underscores | boolean |
true |
Example
conversion
'this-isAnExample_string' => 'This-Is_anExample-string'
Check if the string is a valid mixed case (without special characters!)
Param | Type | Default |
---|---|---|
string | string |
|
allow_prefixed_underscores | boolean |
true |
Swaps character cases in string
lower case to upper case upper case to lower case dash to underscore underscore to dash
Param | Type | Default |
---|---|---|
string | string |
|
preserve_prefixed_underscores | boolean |
false |
Example
conversion
'this-isAnExample_string' => 'THIS_ISaNeXAMPLE-STRING'
Convert the string from any case into pascal case and casts it into a constant
Does not work in all node js contexts because of scopes, where the constant is not available here. Then you might use eval(LuckyCase.toPascalCase) instead. Or you may use it with global defined variables, global.<variable_name>
Param | Type |
---|---|
string | string |
Example
conversion
'this-isAnExample_string' => ThisIsAnExampleString
'this/is_an/example_path' => ThisIsAnExamplePath
Deconverts the constant back into specified target type
Does not work in special scopes in node js
Param | Type |
---|---|
constant | function |
case_type | string |
Example
deconversion
ThisAweSomeConstant => 'thisAweSomeConstant'
function myFunction() {} => 'myFunction'
Return string without underscores at the start
Returns: string
- string without prefixed underscores
Param | Type |
---|---|
string | string |
Return the underscores at the start of the string
Returns: string
- string of underscores or empty if none found
Param | Type |
---|---|
string | string |
Split the string into parts It is splitted by all (different) case separators
Param | Type |
---|---|
string | string |