Skip to main content

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, etc.

license Tests Coverage OpenSSF Best Practices
pypi versions
PyPI - Downloads

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

Getting Started

Installing

$ pip install caseutil

Use as a library

>>> 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 a CLI command

Note the support of 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

Advanced

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'

Case enum

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 support

Only ASCII names are supported. Unicode support is planned.

Developing

Development environment

OS X

This project requires Homebrew. Other tools like PDM and Tox will be installed automatically.

git clone https://github.com/makukha/caseutil.git
cd caseutil
brew install go-task
task init install

Testing

task test

Contributing

See Contributing guidelines.

Roadmap

  • Add more test, explore edge cases
  • Add Unicode support (write tests)
  • Add more cases

Authors

License

MIT License

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

caseutil-0.6.5.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

caseutil-0.6.5-py2.py3-none-any.whl (6.3 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file caseutil-0.6.5.tar.gz.

File metadata

  • Download URL: caseutil-0.6.5.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.18.1 CPython/3.12.5 Darwin/21.6.0

File hashes

Hashes for caseutil-0.6.5.tar.gz
Algorithm Hash digest
SHA256 fab1ba83fec2b13e8d3d5af165a3d99e8ea217c2230b123e85ed35c2ba816c7d
MD5 ba2b3aa33c936c28c3bebae71f587453
BLAKE2b-256 2c3a8a1a9e514abd5908d8dbb0a3de7bef557909177c2e6613509b437e18ae83

See more details on using hashes here.

File details

Details for the file caseutil-0.6.5-py2.py3-none-any.whl.

File metadata

  • Download URL: caseutil-0.6.5-py2.py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.18.1 CPython/3.12.5 Darwin/21.6.0

File hashes

Hashes for caseutil-0.6.5-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 a99b3bb38da7e3cde844e466d876b6b953a51fa0d8c2b3a8037cd49c5cbd614e
MD5 366cf63d2a835c928b551d89dcd9ab15
BLAKE2b-256 d29471d4983594b5c51c9edf9d6ec55f87000bb0a9c66e113af184729343f395

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page