Str Case Util
A lightweight utility library for working with various string casing.
Supported Cases
| Example | Case Names |
|---|---|
| HelloWorld | Pascal Case Capital Camel Case |
| helloWorld | Camel Case |
| helloworld | Flat Case Mumble Case |
| HELLOWORLD | Upper Flat Case |
| Hello World | Title Case |
| Hello world | Sentence Case |
| hello world | Lower Case |
| HELLO WORLD | Upper Case |
| hello_world | Snake Case C Case |
| HELLO_WORLD | Screaming Snake Case Constant Case Macro Case |
| Hello-World | Train Case |
| hello-world | Kebab Case Caterpillar Case CSS Case Lisp Case |
| HELLO-WORLD | COBOL Case |
Features
Each of the above may be accessed within the Case Enum
from case_util import Case
The Case Enum contains functions to format a str
Case.SNAKE_CASE.format("Hello World") # output = hello_world
and also to determine if a str is said format
Case.CAMEL_CASE.is_formatted("MyClassName") # output = False
Case.PASCAL_CASE.is_formatted("MyClassName") # output = True
In addition, a class method is available to detect the format of a str
Case.detect_format("my-test-string") # output = Case.KEBAB_CASE
Additional Functionality
While not intended to be used externally, the following functions are available if they are of use.
Split String Into Words
import case_util
words = case_util.words_of("MyFormattedClassName")
# output = ["My", "Formatted", "Class", "Name"]
Word List Manipulation
If you already have a list of words, you may preform the following actions on each
case_util.capitalize(words)case_util.camel(words)- Capitalizes all but the 1st wordcase_util.sentence(words)- Capitalizes only the 1st wordcase_util.lower(words)case_util.upper(words)
Caveats
Due to the nature of the various string formats, the correct case cannot always be detected.
Flat Case Trumps All
A single word such as name will be detected as Flat Case. Similarly, NAME will be Upper Flat Case.
While this functionality may seem obvious, it gets more nuanced.
Perhaps the author wrote it in Camel Case or Snake Case which becomes clear when expanded: nameClass or var_name.
Without input from the original author, it is impossible to know for certain.
Acronyms
Acronyms/abbreviations are treated as a single word. So MyAPIClass converted to snake case would be my_api_class.
Related, acronym case is not preserved which means MyAPIClass converted to camel case would result in myApiClass.
This unfortunately means that the format of such strings will not be properly detected.
Multiple Cases Detected
Some strings, such as the quick_brown-fox could be one of many formats depending on the intended delimiter.
In these scenarios, None is returned
Special Characters
This library was created with class/variable names in mind. Therefore, extensive test has not been conducted using special characters. When it comes to Camel Case and Pascal Case, numbers are designed to be seen as uppercase. This may result in unwanted behavior if placing numbers within the middle of words. All other special characters are intended to be treated as lowercase.
Additional Language Support
No design/testing has been conducted for characters outside of ASCII.
Metadata
Release files for Str-Case-Util 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| str_case_util-1.0.0.tar.gz | 5.3 kB | Without provenance | Details for str_case_util-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| str_case_util-1.0.0-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for str_case_util-1.0.0-py2.py3-none-any.whl |
Total release size: 10.0 kB
Release files / str_case_util-1.0.0.tar.gz
| Download URL | str_case_util-1.0.0.tar.gz |
|---|---|
| Size | 5.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
16c5149764434eda39bb0c9dcd3d1a3b3fdfadcd7741cf4496ff1aa60acc989e
|
|
BLAKE2b-256 checksum How to use checksums |
f4e27698c6756cdd04daf7406fcf017ef14e8a47194f7fdfc5222472b63c1a1d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
pdm/2.24.1 CPython/3.13.3 Linux/6.11.0-1012-azure
|
Release files / str_case_util-1.0.0-py2.py3-none-any.whl
| Download URL | str_case_util-1.0.0-py2.py3-none-any.whl |
|---|---|
| Size | 4.7 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
788286a9551d58bb068e412d849701518eba5fcd4267a5f109eaf014faf642dd
|
|
BLAKE2b-256 checksum How to use checksums |
b09f11c4650f4859999fedf3f7c0cb068ae763f978195419ca913c3b20e0998d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
pdm/2.24.1 CPython/3.13.3 Linux/6.11.0-1012-azure
|
Security for Str-Case-Util 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.