LuckyCase version to add methods directly to string by monkey patching
- String
- .letterCase(allow_prefixed_underscores) →
string|null - .letterCases(allow_prefixed_underscores) →
Array.<string>|null - .convertCase(case_type, preserve_prefixed_underscores) →
string - .isValidCaseString() →
boolean - .toUpperCase() →
string - .isUpperCase() →
boolean - .toLowerCase() →
string - .isLowerCase() →
boolean - .toSnakeCase(preserve_prefixed_underscores) →
string - .isSnakeCase(allow_prefixed_underscores) →
boolean - .toUpperSnakeCase(preserve_prefixed_underscores) →
string - .isUpperSnakeCase(allow_prefixed_underscores) →
boolean - .toPascalCase(preserve_prefixed_underscores) →
string - .isPascalCase(allow_prefixed_underscores) →
boolean - .toCamelCase(preserve_prefixed_underscores) →
string - .isCamelCase(allow_prefixed_underscores) →
boolean - .toDashCase(preserve_prefixed_underscores) →
string - .isDashCase(allow_prefixed_underscores) →
boolean - .toUpperDashCase(preserve_prefixed_underscores) →
string - .isUpperDashCase(allow_prefixed_underscores) →
boolean - .toTrainCase(preserve_prefixed_underscores) →
string - .isTrainCase(allow_prefixed_underscores) →
boolean - .toWordCase(preserve_prefixed_underscores) →
string - .isWordCase(allow_prefixed_underscores) →
boolean - .toUpperWordCase(preserve_prefixed_underscores) →
string - .isUpperWordCase(allow_prefixed_underscores) →
boolean - .toCapitalWordCase(preserve_prefixed_underscores) →
string - .isCapitalWordCase(allow_prefixed_underscores) →
boolean - .toSentenceCase(preserve_prefixed_underscores) →
string - .isSentenceCase(allow_prefixed_underscores) →
boolean - .toCapital(skip_prefixed_underscores) →
string - .capitalize(skip_prefixed_underscores) →
string - .isCapital(skip_prefixed_underscores) →
boolean - .isCapitalized(skip_prefixed_underscores) →
boolean - .decapitalize(skip_prefixed_underscores) →
string - .isNotCapital(skip_prefixed_underscores) →
boolean - .isDecapitalized(skip_prefixed_underscores) →
boolean - .toMixedCase(preserve_prefixed_underscores) →
string - .isMixedCase(allow_prefixed_underscores) →
boolean - .swapCase(preserve_prefixed_underscores) →
string - .constantize() →
any
- .letterCase(allow_prefixed_underscores) →
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 - string of caseType, null if no match
| Param | Type | Default |
|---|---|---|
| allow_prefixed_underscores | boolean |
true |
Get types of cases of string (keys of LuckyCase.CASES)
| Param | Type | Default |
|---|---|---|
| allow_prefixed_underscores | boolean |
true |
Convert a string into the given case type
| Param | Type | Default | Description |
|---|---|---|---|
| case_type | string |
can be UPPER_CASE or lower_case, e.g. 'SNAKE_CASE' or 'snake_case' | |
| preserve_prefixed_underscores | boolean |
true |
Check if the string matches any of the available cases
Convert all characters inside the string into upper case Example
conversion
'this-isAnExample_string' => 'THIS-ISANEXAMPLE_STRING'Check if all characters inside the string are upper case
Convert all characters inside the string into lower case Example
conversion
'this-isAnExample_string' => 'this-isanexample_string'Check if all characters inside the string are lower case
Convert the string from any case into snake case
| Param | Type | Default |
|---|---|---|
| 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 |
|---|---|---|
| allow_prefixed_underscores | boolean |
true |
Convert the string from any case into upper snake case
| Param | Type | Default |
|---|---|---|
| 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 |
|---|---|---|
| allow_prefixed_underscores | boolean |
true |
Convert the string from any case into pascal case
| Param | Default |
|---|---|
| preserve_prefixed_underscores | true |
Example
conversion
'this-isAnExample_string' => 'ThisIsAnExampleString'Check if the string is upper pascal case
| Param | Type | Default |
|---|---|---|
| allow_prefixed_underscores | boolean |
true |
Convert the string from any case into camel case
| Param | Type | Default |
|---|---|---|
| preserve_prefixed_underscores | boolean |
true |
Example
conversion
'this-isAnExample_string' => 'thisIsAnExampleString'Check if the string is camel case
| Param | Type | Default |
|---|---|---|
| allow_prefixed_underscores | boolean |
true |
Convert the string from any case into dash case
| Param | Type | Default |
|---|---|---|
| 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 |
|---|---|---|
| allow_prefixed_underscores | boolean |
true |
Convert the string from any case into upper dash case
| Param | Type | Default |
|---|---|---|
| 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 |
|---|---|---|
| allow_prefixed_underscores | boolean |
true |
Convert the string from any case into train case
| Param | Type | Default |
|---|---|---|
| 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 |
|---|---|---|
| allow_prefixed_underscores | boolean |
true |
Convert the string from any case into word case
| Param | Type | Default |
|---|---|---|
| preserve_prefixed_underscores | boolean |
true |
Example
conversion
'this-isAnExample_string' => 'this is an example string'Check if the string is word case
| Param | Default |
|---|---|
| allow_prefixed_underscores | true |
Convert the string from any case into upper word case
| Param | Type | Default |
|---|---|---|
| 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 |
|---|---|
| allow_prefixed_underscores | true |
Convert the string from any case into capital word case
| Param | Type | Default |
|---|---|---|
| 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 |
|---|---|---|
| allow_prefixed_underscores | boolean |
true |
Convert the string from any case into sentence case
| Param | Type | Default |
|---|---|---|
| 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 |
|---|---|---|
| allow_prefixed_underscores | boolean |
true |
Convert the first character to capital
| Param | Type | Default |
|---|---|---|
| skip_prefixed_underscores | boolean |
false |
Convert the first character to capital
| Param | Type | Default |
|---|---|---|
| skip_prefixed_underscores | boolean |
false |
Check if the strings first character is a capital letter
| Param | Type | Default |
|---|---|---|
| skip_prefixed_underscores | boolean |
false |
Check if the strings first character is a capital letter
| Param | Type | Default |
|---|---|---|
| skip_prefixed_underscores | boolean |
false |
Convert the first character to lower case
| Param | Type | Default |
|---|---|---|
| skip_prefixed_underscores | boolean |
false |
Check if the strings first character is a lower letter
| Param | Type | Default |
|---|---|---|
| skip_prefixed_underscores | boolean |
false |
Check if the strings first character is a lower letter
| Param | Type | Default |
|---|---|---|
| skip_prefixed_underscores | boolean |
false |
Convert the string from any case into mixed case.
The new string is ensured to be different from the input.
| Param | Type | Default |
|---|---|---|
| preserve_prefixed_underscores | boolean |
false |
Example
conversion
'this-isAnExample_string' => 'This-Is_anExample-string'Check if the string is a valid mixed case (without special characters!)
| Param | Type | Default |
|---|---|---|
| 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 |
|---|---|---|
| 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 Example
conversion
'this-isAnExample_string' => ThisIsAnExampleString
'this/is_an/example_path' => ThisIsAnExamplePath