Naming case conventions parsing and converting tool.
Project description
caseutil
Naming case conventions parsing and converting tool.
Small and clean, fully typed, zero dependency pure Python 2.7 to 3.13 and probably above.
The package supports detection and conversion between cases:
- snake_case
- camelCase
- PascalCase
- kebab-case
- ALL_CAPS_CASE (aka SCREAMING_SNAKE_CASE)
- Title Case
and more to be added.
Usage
>>> from caseutil import is_snake, to_snake
>>> text = 'Some-Title phrase'
>>> is_snake(text)
False
>>> to_snake(text)
'some_title_phrase'
Command line tool
$ caseutil --case allcaps "hi there"
HI_THERE
$ echo "hi_there\nsee you" | python -m caseutil -c camel
hiThere
seeYou
Supported cases
>>> text = 'Some-Title phrase'
snake_case
>>> from caseutil import is_snake, to_snake
>>> to_snake(text)
'some_title_phrase'
>>> is_snake(to_snake(text))
True
camelCase
>>> from caseutil import is_camel, to_camel
>>> to_camel(text)
'someTitlePhrase'
>>> is_camel(to_camel(text))
True
PascalCase
>>> from caseutil import is_pascal, to_pascal
>>> to_pascal(text)
'SomeTitlePhrase'
>>> is_pascal(to_pascal(text))
True
kebab-case
>>> from caseutil import is_kebab, to_kebab
>>> to_kebab(text)
'some-title-phrase'
>>> is_kebab(to_kebab(text))
True
ALL_CAPS_CASE
>>> from caseutil import is_allcaps, to_allcaps
>>> to_allcaps(text)
'SOME_TITLE_PHRASE'
>>> is_allcaps(to_allcaps(text))
True
Title Case
>>> from caseutil import is_title, to_title
>>> to_title(text)
'Some Title Phrase'
>>> is_title(to_title(text))
True
Separators
Phrase separators are non-word characters including underscore, and places where text case is changed from lower to upper. Digits are not treated as separators.
>>> from caseutil import words
>>> words('!some_reallyMESsy text--wit4Digits.3VeryWh3re--')
'some,really,ME,Ssy,text,wit4,Digits,3Very,Wh3re'
Unicode
Only ASCII names are supported. Unicode support is planned.
Development
Mac OS X
Requires Docker and Homebrew.
git clone https://github.com/makukha/caseutil.git
brew install go-task
task init
Testing:
task test
Plans
- Add more test, explore edge cases
- Add Unicode support (write tests)
- Add more cases
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
File details
Details for the file caseutil-0.4.0-py2.py3-none-any.whl
.
File metadata
- Download URL: caseutil-0.4.0-py2.py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.4 Darwin/21.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b8bd40aa9bfc51ec3abee9c4ee4dc0a30b42254b5b4360b21d6fb8ab473a1ea |
|
MD5 | 4fb5d7466cc93fd8152794dc63156da8 |
|
BLAKE2b-256 | 1ebcdbd861a25e48e0ce009684da3013537bc3516153ad807aa47eff9b7effd3 |