Case convert and verify for Python: snake_case, camelCase, kebab-case, and more.
Project description
caseutil ⇄ 🐍🐫🍢
Case convert and verify for Python: snake_case, camelCase, kebab-case, and more.
Features
- Verify and convert between most popular cases
- Custom separators:
'my.variable.name'
,'my/variable/name'
- Command line mode:
caseutil
- Pure Python 2.7 to 3.13+
- No dependencies
- 100% test coverage
Supported Cases
Case | Example | Functions |
---|---|---|
snake_case | my_variable_name | is_snake , to_snake |
CONST_CASE | MY_VARIABLE_NAME | is_const , to_const |
camelCase | myVariableName | is_camel , to_camel |
PascalCase | MyVariableName | is_pascal , to_pascal |
kebab-case | my-variable-name | is_kebab , to_kebab |
lower space | my variable name | is_lower , to_lower |
UPPER SPACE | MY VARIABLE NAME | is_upper , to_upper |
Title Space | My Variable Name | is_title , to_title |
Installation
$ pip install caseutil
Quick Start
>>> from caseutil import *
Verify case format:
>>> is_snake('My variable-name')
False
Convert to case:
>>> to_snake('My variable-name')
'my_variable_name'
Use as command line tool, supports multiple values in argument or stdin:
$ caseutil -c const "hi there"
HI_THERE
$ echo "hi_there\nsee you" | python -m caseutil -c camel
hiThere
seeYou
Universal Functions
Use functions is_case()
and to_case()
to deal with arbitrary case:
>>> is_case('camel', 'myVariableName')
True
>>> to_case(Case.CONST, 'myVariableName')
'MY_VARIABLE_NAME'
All supported cases are gathered in Case
enum:
class Case(StrEnum):
CAMEL = 'camel'
CONST = 'const'
KEBAB = 'kebab'
LOWER = 'lower'
PASCAL = 'pascal'
SNAKE = 'snake'
TITLE = 'title'
UPPER = 'upper'
Tokenization
Word separators are non-word characters including underscore, and places where text case is changed from lower to upper. Digits are not treated as separators. For more details, see this example and unit tests.
>>> words('!some_reallyMESsy text--wit4Digits.3VeryWh3re--')
['some', 'really', 'ME', 'Ssy', 'text', 'wit4', 'Digits', '3Very', 'Wh3re']
Custom Separators
For custom separators, use words()
function:
>>> '/'.join(words(to_lower('myVariableName')))
'my/variable/name'
>>> '.'.join(words('myVariableName'))
'my.Variable.Name'
Unicode
Only ASCII names are supported. Unicode support is planned.
Developer Notes
Mac OS X
This project requires Homebrew. Other tools like PDM, Tox, and even Alacritty, will be installed automatically.
git clone https://github.com/makukha/caseutil.git
cd caseutil
brew bundle
task init install
Operations
Command | Description |
---|---|
task init |
Initialize system environment |
task install |
Install Python environment |
task test |
Run tests |
task version |
Bump project version |
task publish |
Publish package on PyPi |
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 Distribution
Built Distribution
File details
Details for the file caseutil-0.6.1.tar.gz
.
File metadata
- Download URL: caseutil-0.6.1.tar.gz
- Upload date:
- Size: 7.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.17.3 CPython/3.12.4 Darwin/21.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f8091a2dca8b879425284d5cdc8bf0934ef6c973f26ad67ed16c4da20cb67540 |
|
MD5 | ca20aaa53281bfdce6c08767589042f9 |
|
BLAKE2b-256 | 6a4c6667f0e52da5a5d12096d186390fcf3e387838bd2d3397fa93dafc30123e |
File details
Details for the file caseutil-0.6.1-py2.py3-none-any.whl
.
File metadata
- Download URL: caseutil-0.6.1-py2.py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.17.3 CPython/3.12.4 Darwin/21.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 501e8a0016d1a783a20715c45d9a84ff62f4a831cb06054c5319d39abb4493d9 |
|
MD5 | 37521de0721ed0a1ed113d9cd4c1bdc2 |
|
BLAKE2b-256 | 06027383ad366254109a6d03c1c23cf5dbc13376304d5c68d9e67342d0e6e902 |