Skip to content

Latest commit

 

History

History
639 lines (489 loc) · 23.1 KB

lucky-case.jsdoc.md

File metadata and controls

639 lines (489 loc) · 23.1 KB

LuckyCase

LuckyCase

Convert and detect various letter cases in strings

LuckyCase.getVersion() → string

Get the version of the used library

LuckyCase.case(string, 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 - symbol of type, null if no match

Param Type Default
string string
allow_prefixed_underscores boolean true

LuckyCase.cases(string, allow_prefixed_underscores) → Array.<string> | null

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

LuckyCase.convertCase(string, case_type, preserve_prefixed_underscores) → string

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

LuckyCase.isValidCaseType(case_type) → boolean

Check if given case type is a valid case type

Param Type Description
case_type string to check

LuckyCase.isValidCaseString(string) → boolean

Check if the string matches any of the available cases

Param Type Description
string string to check

LuckyCase.toUpperCase(string) → string

Convert all characters inside the string into upper case

Param Type Description
string string to convert

Example

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

LuckyCase.isUpperCase(string) → boolean

Check if all characters inside the string are upper case

Param Type Description
string string to check

LuckyCase.toLowerCase(string) → string

Convert all characters inside the string into lower case

Param Type Description
string string to convert

Example

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

LuckyCase.isLowerCase(string) → boolean

Check if all characters inside the string are lower case

Param Type Description
string string to check

LuckyCase.toSnakeCase(string, preserve_prefixed_underscores) → string

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'

LuckyCase.isSnakeCase(string, allow_prefixed_underscores) → boolean

Check if the string is snake case

Param Type Default Description
string string to check
allow_prefixed_underscores boolean true

LuckyCase.toUpperSnakeCase(string, preserve_prefixed_underscores) → string

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'

LuckyCase.isUpperSnakeCase(string, allow_prefixed_underscores) → boolean

Check if the string is upper snake case

Param Type Default Description
string string to check
allow_prefixed_underscores boolean true

LuckyCase.toPascalCase(string, preserve_prefixed_underscores) → string

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'

LuckyCase.isPascalCase(string, allow_prefixed_underscores) → boolean

Check if the string is upper pascal case

Param Type Default Description
string string to check
allow_prefixed_underscores boolean true

LuckyCase.toCamelCase(string, preserve_prefixed_underscores) → string

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'

LuckyCase.isCamelCase(string, allow_prefixed_underscores) → boolean

Check if the string is camel case

Param Type Default Description
string string to check
allow_prefixed_underscores boolean true

LuckyCase.toDashCase(string, preserve_prefixed_underscores) → string

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'

LuckyCase.isDashCase(string, allow_prefixed_underscores) → boolean

Check if the string is dash case

Param Type Default Description
string string to check
allow_prefixed_underscores boolean true

LuckyCase.toUpperDashCase(string, preserve_prefixed_underscores) → string

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'

LuckyCase.isUpperDashCase(string, allow_prefixed_underscores) → boolean

Check if the string is upper dash case

Param Type Default Description
string string to check
allow_prefixed_underscores boolean true

LuckyCase.toTrainCase(string, preserve_prefixed_underscores) → string

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'

LuckyCase.isTrainCase(string, allow_prefixed_underscores) → boolean

Check if the string is train case

Param Type Default Description
string string to check
allow_prefixed_underscores boolean true

LuckyCase.toWordCase(string, preserve_prefixed_underscores) → string

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'

LuckyCase.isWordCase(string, allow_prefixed_underscores) → boolean

Check if the string is word case

Param Type Default Description
string string to check
allow_prefixed_underscores true

LuckyCase.toUpperWordCase(string, preserve_prefixed_underscores) → string

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'

LuckyCase.isUpperWordCase(string, allow_prefixed_underscores) → boolean

Check if the string is upper word case

Param Default Description
string to check
allow_prefixed_underscores true

LuckyCase.toCapitalWordCase(string, preserve_prefixed_underscores) → string

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'

LuckyCase.isCapitalWordCase(string, allow_prefixed_underscores) → boolean

Check if the string is capital word case

Param Type Default Description
string string to check
allow_prefixed_underscores boolean true

LuckyCase.toSentenceCase(string, preserve_prefixed_underscores) → string

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'

LuckyCase.isSentenceCase(string, allow_prefixed_underscores) → boolean

Check if the string is sentence case

Param Type Default Description
string string to check
allow_prefixed_underscores boolean true

LuckyCase.toCapital(string, skip_prefixed_underscores) → string

Convert the first character to capital

Param Type Default Description
string string to convert
skip_prefixed_underscores boolean false

LuckyCase.capitalize(string, skip_prefixed_underscores) → string

Convert the first character to capital

Param Type Default Description
string string to convert
skip_prefixed_underscores boolean false

LuckyCase.isCapital(string, skip_prefixed_underscores) → boolean

Check if the strings first character is a capital letter

Param Type Default
string string
skip_prefixed_underscores boolean false

LuckyCase.isCapitalized(string, skip_prefixed_underscores) → boolean

Check if the strings first character is a capital letter

Param Type Default
string string
skip_prefixed_underscores boolean false

LuckyCase.decapitalize(string, skip_prefixed_underscores) → string

Convert the first character to lower case

Param Type Default Description
string string to convert
skip_prefixed_underscores boolean false

LuckyCase.isNotCapital(string, skip_prefixed_underscores) → boolean

Check if the strings first character is a lower case letter

Param Type Default
string string
skip_prefixed_underscores boolean false

LuckyCase.isDecapitalized(string, skip_prefixed_underscores) → boolean

Check if the strings first character is a lower case letter

Param Type Default
string string
skip_prefixed_underscores boolean false

LuckyCase.toMixedCase(string, preserve_prefixed_underscores) → string

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'

LuckyCase.isMixedCase(string, allow_prefixed_underscores) → boolean

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

Param Type Default
string string
allow_prefixed_underscores boolean true

LuckyCase.swapCase(string, 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
string string
preserve_prefixed_underscores boolean false

Example

conversion
     'this-isAnExample_string' => 'THIS_ISaNeXAMPLE-STRING'

LuckyCase.constantize(string) → any

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

LuckyCase.deconstantize(constant, case_type) → string

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'

LuckyCase.cutUnderscoresAtStart(string) → string

Return string without underscores at the start Returns: string - string without prefixed underscores

Param Type
string string

LuckyCase.getUnderscoresAtStart(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

LuckyCase.splitCaseString(string) → Array.<string>

Split the string into parts It is splitted by all (different) case separators

Param Type
string string