Package: convert-case
Convert CaseConvert between string cases with built-in case inference.StatusSourceShieldsProjectHealthPublishersRepositoryActivityInstallingInstall the package from pypi:pipinstallconvert-caseTo experiment with the source code locally, clone the repository:gitclonehttps://github.com/joellefkowitz/convert-caseTo install linters, formatters and test runners:pipinstall.[all]npminstallUsagefromconvert_caseimportcamel_casecamel_case('camel case')# Inferred: lower -> camel'camelCase'camel_case('Camel Case')# Inferred: title -> camel'camelCase'camel_case('CamelCase')# Inferred: pascal -> camel'camelCase'Exportsdefpascal_case(string:str)->str:...defis_pascal_case(string:str)->bool:...defcamel_case(string:str)->str:...defis_camel_case(string:str)->bool:...defkebab_case(string:str)->str:...defis_kebab_case(string:str)->bool:...defsentence_case(string:str)->str:...defis_sentence_case(string:str)->bool:...defsnake_case(string:str)->str:...defis_snake_case(string:str)->bool:...deftitle_case(string:str)->str:...defis_title_case(string:str)->bool:...defupper_case(string:str)->str:...defis_upper_case(string:str)->bool:...DefinitionsLOWER=re.compile(r"^[a-z0-9\s]*$")UPPER=re.compile(r"^[A-Z0-9\s]*$")TITLE=re.compile(r"^(([A-Z0-9][a-z0-9]*)(\s[A-Z0-9][a-z0-9]*)*)?$")SENTENCE=re.compile(r"^(([A-Z0-9][a-z0-9]*)(\s[a-z0-9]*)*)?$")CAMEL=re.compile(r"^([a-z0-9][a-zA-Z0-9]*)?$")PASCAL=re.compile(r"^([A-Z0-9]|([A-Z0-9][a-z0-9]+)*)?$")SNAKE=re.compile(r"^([a-z0-9]+(_[a-z0-9]+)*)?$")KEBAB=re.compile(r"^([a-z0-9]+(-[a-z0-9]+)*)?$")TestsTo run unit tests:grunttestTest casestestloweruppersentencetitlecamelsnakekebabpascalaaAAAaaaAAaAAAaaaAabcabcABCAbcAbcabcabcabcAbcab cdab cdAB CDAb cdAb CdabCdab_cdab-cdAbCdAb cdab cdAB CDAb cdAb CdabCdab_cdab-cdAbCdAb Cdab cdAB CDAb cdAb CdabCdab_cdab-cdAbCdab_cdab cdAB CDAb cdAb CdabCdab_cdab-cdAbCdab-cdab cdAB CDAb cdAb CdabCdab_cdab-cdAbCdabCdab cdAB CDAb cdAb CdabCdab_cdab-cdAbCdABCDabcdABCDAbcdAbcdabcdabcdabcdAbcdAbCdab cdAB CDAb cdAb CdabCdab_cdab-cdAbCdab cd efab cd efAB CD EFAb cd efAb Cd EfabCdEfab_cd_efab-cd-efAbCdEfAbCdEfab cd efAB CD EFAb cd efAb Cd EfabCdEfab_cd_efab-cd-efAbCdEfab-cd-efab cd efAB CD EFAb cd efAb Cd EfabCdEfab_cd_efab-cd-efAbCdEfAb cd efab cd efAB CD EFAb cd efAb Cd EfabCdEfab_cd_efab-cd-efAbCdEfNumbersNumbers are treated as letters with no specific case.testloweruppersentencetitlecamelsnakekebabpascal1111111111bc1bc1BC1bc1bc1bc1bc1bc1bca1ca1cA1CA1cA1ca1ca1ca1cA1cab1ab1AB1Ab1Ab1ab1ab1ab1Ab1a1 ca1 cA1 CA1 cA1 Ca1Ca1_ca1-cA1Ca1-ca1 cA1 CA1 cA1 Ca1Ca1_ca1-cA1CAdvancedA goal of this converter is that it is deterministic. If we consider the following examples we can see that this is not simple to achieve. How should we interpret the string 'ABC', is it in upper case or pascal case?testupperpascalabcABCAbca b cA B CABCOur options are:To consider strings with consecutive capitals like 'ABC' not to be pascal case. If in this case 'a b c' is parsed to 'Abc' it would clash with parsing 'abc' into pascal case.To store some state that remembers the string's case before parsing. This would introduce too much complexity.To prioritize parsing the string as one case unless told otherwise. We choose to pick upper case as the inferred case. The caveat here is that we will no longer be performing 'round trip' conversion.Round trip conversion:kebab_case('a b c')'a-b-c'lower_case('a-b-c')'a b c'Not round trip conversion:pascal_case('a b c')'ABC'lower_case('ABC')'abc'DocumentationThis repository's documentation is hosted onreadthedocs.ToolingTo run linters:gruntlintTo run formatters:gruntformatContinuous integrationThis repository uses github actions to lint and test each commit. Formatting tasks and writing/generating documentation must be done before committing new code.VersioningThis repository adheres to semantic versioning standards.
For more information on semantic versioning visitSemVer.Bump2version is used to version and tag changes.
For example:bump2versionpatchChangelogPlease read this repository'schangelogfor details on changes that have been made.ContributingPlease read this repository's guidelines oncontributingfor details on the process for submitting pull requests. Moreover, ourcode of conductdeclares our collaboration standards.Contributorsjoellefkowitz-Initial work-joellefkowitzRemarksLots of love to the open source community!