Convert between string cases with built-in case inference.
Project description
Convert Case
Convert between string cases with built-in case inference.
Status
Source | Shields |
---|---|
Project | |
Health | |
Publishers | |
Repository | |
Activity |
Installing
pip install convert_case
Usage
from convert_case import camel_case
camel_case('camel case') # Inferred: lower -> camel
'camelCase'
camel_case('Camel Case') # Inferred: title -> camel
'camelCase'
camel_case('CamelCase') # Inferred: pascal -> camel
'camelCase'
Exports
def pascal_case(string: str) -> str:
...
def is_pascal_case(string: str) -> bool:
...
def camel_case(string: str) -> str:
...
def is_camel_case(string: str) -> bool:
...
def kebab_case(string: str) -> str:
...
def is_kebab_case(string: str) -> bool:
...
def sentence_case(string: str) -> str:
...
def is_sentence_case(string: str) -> bool:
...
def snake_case(string: str) -> str:
...
def is_snake_case(string: str) -> bool:
...
def title_case(string: str) -> str:
...
def is_title_case(string: str) -> bool:
...
def upper_case(string: str) -> str:
...
def is_upper_case(string: str) -> bool:
...
Definitions
LOWER = re.compile(r"^[a-z\s]*$")
UPPER = re.compile(r"^[A-Z\s]*$")
TITLE = re.compile(r"^(([A-Z][a-z]*)(\s[A-Z][a-z]*)*)?$")
SENTENCE = re.compile(r"^(([A-Z][a-z]*)(\s[a-z]*)*)?$")
CAMEL = re.compile(r"^([a-z][a-zA-Z]*)?$")
PASCAL = re.compile(r"^([A-Z]|([A-Z][a-z]+)*)?$")
SNAKE = re.compile(r"^([a-z]+(_[a-z]+)*)?$")
KEBAB = re.compile(r"^([a-z]+(-[a-z]+)*)?$")
Tests
To run unit tests:
grunt test
Test cases
test | lower | upper | sentence | title | camel | snake | kebab | pascal |
---|---|---|---|---|---|---|---|---|
a | a | A | A | A | a | a | a | A |
A | a | A | A | A | a | a | a | A |
abc | abc | ABC | Abc | Abc | abc | abc | abc | Abc |
ab cd | ab cd | AB CD | Ab cd | Ab Cd | abCd | ab_cd | ab-cd | AbCd |
Ab cd | ab cd | AB CD | Ab cd | Ab Cd | abCd | ab_cd | ab-cd | AbCd |
Ab Cd | ab cd | AB CD | Ab cd | Ab Cd | abCd | ab_cd | ab-cd | AbCd |
ab_cd | ab cd | AB CD | Ab cd | Ab Cd | abCd | ab_cd | ab-cd | AbCd |
ab-cd | ab cd | AB CD | Ab cd | Ab Cd | abCd | ab_cd | ab-cd | AbCd |
abCd | ab cd | AB CD | Ab cd | Ab Cd | abCd | ab_cd | ab-cd | AbCd |
ABCD | abcd | ABCD | Abcd | Abcd | abcd | abcd | abcd | Abcd |
AbCd | ab cd | AB CD | Ab cd | Ab Cd | abCd | ab_cd | ab-cd | AbCd |
ab cd ef | ab cd ef | AB CD EF | Ab cd ef | Ab Cd Ef | abCdEf | ab_cd_ef | ab-cd-ef | AbCdEf |
AbCdEf | ab cd ef | AB CD EF | Ab cd ef | Ab Cd Ef | abCdEf | ab_cd_ef | ab-cd-ef | AbCdEf |
ab-cd-ef | ab cd ef | AB CD EF | Ab cd ef | Ab Cd Ef | abCdEf | ab_cd_ef | ab-cd-ef | AbCdEf |
Ab cd ef | ab cd ef | AB CD EF | Ab cd ef | Ab Cd Ef | abCdEf | ab_cd_ef | ab-cd-ef | AbCdEf |
Documentation
This repository's documentation is hosted on readthedocs.
Tooling
To run linters:
grunt lint
To run formatters:
grunt format
Continuous integration
This repository uses github actions to lint and test each commit. Formatting tasks and writing/generating documentation must be done before committing new code.
Versioning
This repository adheres to semantic versioning standards. For more information on semantic versioning visit SemVer.
Bump2version is used to version and tag changes. For example:
bump2version patch
Changelog
Please read this repository's CHANGELOG for details on changes that have been made.
Contributing
Please read this repository's guidelines on contributing for details on the process for submitting pull requests. Moreover, our code of conduct declares our collaboration standards.
Contributors
- Joel Lefkowitz - Initial work - Joel Lefkowitz
Remarks
Lots of love to the open source community!
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for convert_case-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c91cdb92d1562fbe6ab772e3923f9148c6fa640bc739d0515f0332fbe59ed45b |
|
MD5 | ca3e7665fcac5b6425503bd6732e62b2 |
|
BLAKE2b-256 | d7146e88b2524514ea66f588e6c782459e67217173ba716cefb5adb0048db24b |