Skip to main content

Naming case conventions parsing and converting tool.

Project description

caseutil

license Coverage Status pypi versions

Case conversion and verification Python library for 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 name example func
Snake case my_variable_name to_snake
All caps, screaming snake MY_VARIABLE_NAME to_allcaps
Camel case myVariableName to_camel
Pascal case MyVariableName to_pascal
Kebab case, spinal case my-variable-name to_kebab
Lower space-separated my variable name to_lower
Upper space-separated MY VARIABLE NAME to_upper
Title space-separated My Variable Name to_title

Installation

$ pip install caseutil

Quick Start

Call is_* to verify case format, and to_* to convert to specific case:

>>> from caseutil import *
>>> is_snake('My variable-name')
False
>>> to_snake('My variable-name')
'my_variable_name'

Use as command line tool, pass multiple values in argument or stdin:

$ caseutil -c allcaps "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.ALLCAPS, 'myVariableName')
'MY_VARIABLE_NAME'

All supported cases are gathered in Case string enum:

enum value
Case.ALLCAPS 'allcaps'
Case.CAMEL 'camel'
Case.KEBAB 'kebab'
Case.LOWER lower
Case.PASCAL 'pascal'
Case.SNAKE 'snake'
Case.TITLE 'title'
Case.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's Corner

Develop on 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


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

caseutil-0.5.0-py2.py3-none-any.whl (5.3 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

  • Download URL: caseutil-0.5.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 5.3 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

Hashes for caseutil-0.5.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 4ecea6920bd12f58a2bc97f0332ef96d876f7aee681d597958dc68c4469a2222
MD5 2db7f17c9ee1a97a60215c864ed4ee64
BLAKE2b-256 bd9d18e031840bf125c80e45ff9400c207656611f4e3efb35a097e1bfa7c6074

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