Skip to content

Latest commit

 

History

History
500 lines (381 loc) · 17 KB

lucky-case-string.jsdoc.md

File metadata and controls

500 lines (381 loc) · 17 KB

String

LuckyCase version to add methods directly to string by monkey patching

string.letterCase(allow_prefixed_underscores) → string | null

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

string.letterCases(allow_prefixed_underscores) → Array.<string> | null

Get types of cases of string (keys of LuckyCase.CASES)

Param Type Default
allow_prefixed_underscores boolean true

string.convertCase(case_type, preserve_prefixed_underscores) → string

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

string.isValidCaseString() → boolean

Check if the string matches any of the available cases

string.toUpperCase() → string

Convert all characters inside the string into upper case Example

conversion
     'this-isAnExample_string' => 'THIS-ISANEXAMPLE_STRING'

string.isUpperCase() → boolean

Check if all characters inside the string are upper case

string.toLowerCase() → string

Convert all characters inside the string into lower case Example

conversion
     'this-isAnExample_string' => 'this-isanexample_string'

string.isLowerCase() → boolean

Check if all characters inside the string are lower case

string.toSnakeCase(preserve_prefixed_underscores) → string

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'

string.isSnakeCase(allow_prefixed_underscores) → boolean

Check if the string is snake case

Param Type Default
allow_prefixed_underscores boolean true

string.toUpperSnakeCase(preserve_prefixed_underscores) → string

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'

string.isUpperSnakeCase(allow_prefixed_underscores) → boolean

Check if the string is upper snake case

Param Type Default
allow_prefixed_underscores boolean true

string.toPascalCase(preserve_prefixed_underscores) → string

Convert the string from any case into pascal case

Param Default
preserve_prefixed_underscores true

Example

conversion
     'this-isAnExample_string' => 'ThisIsAnExampleString'

string.isPascalCase(allow_prefixed_underscores) → boolean

Check if the string is upper pascal case

Param Type Default
allow_prefixed_underscores boolean true

string.toCamelCase(preserve_prefixed_underscores) → string

Convert the string from any case into camel case

Param Type Default
preserve_prefixed_underscores boolean true

Example

conversion
     'this-isAnExample_string' => 'thisIsAnExampleString'

string.isCamelCase(allow_prefixed_underscores) → boolean

Check if the string is camel case

Param Type Default
allow_prefixed_underscores boolean true

string.toDashCase(preserve_prefixed_underscores) → string

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'

string.isDashCase(allow_prefixed_underscores) → boolean

Check if the string is dash case

Param Type Default
allow_prefixed_underscores boolean true

string.toUpperDashCase(preserve_prefixed_underscores) → string

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'

string.isUpperDashCase(allow_prefixed_underscores) → boolean

Check if the string is upper dash case

Param Type Default
allow_prefixed_underscores boolean true

string.toTrainCase(preserve_prefixed_underscores) → string

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'

string.isTrainCase(allow_prefixed_underscores) → boolean

Check if the string is train case

Param Type Default
allow_prefixed_underscores boolean true

string.toWordCase(preserve_prefixed_underscores) → string

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'

string.isWordCase(allow_prefixed_underscores) → boolean

Check if the string is word case

Param Default
allow_prefixed_underscores true

string.toUpperWordCase(preserve_prefixed_underscores) → string

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'

string.isUpperWordCase(allow_prefixed_underscores) → boolean

Check if the string is upper word case

Param Default
allow_prefixed_underscores true

string.toCapitalWordCase(preserve_prefixed_underscores) → string

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'

string.isCapitalWordCase(allow_prefixed_underscores) → boolean

Check if the string is capital word case

Param Type Default
allow_prefixed_underscores boolean true

string.toSentenceCase(preserve_prefixed_underscores) → string

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'

string.isSentenceCase(allow_prefixed_underscores) → boolean

Check if the string is sentence case

Param Type Default
allow_prefixed_underscores boolean true

string.toCapital(skip_prefixed_underscores) → string

Convert the first character to capital

Param Type Default
skip_prefixed_underscores boolean false

string.capitalize(skip_prefixed_underscores) → string

Convert the first character to capital

Param Type Default
skip_prefixed_underscores boolean false

string.isCapital(skip_prefixed_underscores) → boolean

Check if the strings first character is a capital letter

Param Type Default
skip_prefixed_underscores boolean false

string.isCapitalized(skip_prefixed_underscores) → boolean

Check if the strings first character is a capital letter

Param Type Default
skip_prefixed_underscores boolean false

string.decapitalize(skip_prefixed_underscores) → string

Convert the first character to lower case

Param Type Default
skip_prefixed_underscores boolean false

string.isNotCapital(skip_prefixed_underscores) → boolean

Check if the strings first character is a lower letter

Param Type Default
skip_prefixed_underscores boolean false

string.isDecapitalized(skip_prefixed_underscores) → boolean

Check if the strings first character is a lower letter

Param Type Default
skip_prefixed_underscores boolean false

string.toMixedCase(preserve_prefixed_underscores) → string

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'

string.isMixedCase(allow_prefixed_underscores) → boolean

Check if the string is a valid mixed case (without special characters!)

Param Type Default
allow_prefixed_underscores boolean true

string.swapCase(preserve_prefixed_underscores) → string

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'

string.constantize() → any

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