Introduction
Casefy (/keɪsfaɪ/) is a lightweight Python package to convert the casing of
strings. It has no third-party dependencies and supports Unicode.
Installation
The latest release can be installed using
pip:
pip install -U casefy
Casefy is also available as
an Arch Linux AUR package.
Examples
Note: for more details, you can check the API
Reference.
import casefy
string = casefy.alphanumcase("foo - 123 ; bar!")
print(string)
string = casefy.camelcase("foo_bar")
print(string)
string = casefy.camelcase("FooBar")
print(string)
string = casefy.camelcase("FOO BAR")
print(string)
string = casefy.capitalcase("fooBar")
print(string)
string = casefy.constcase("fooBar")
print(string)
string = casefy.kebabcase("fooBar")
print(string)
string = casefy.lowercase("fooBar")
print(string)
string = casefy.pascalcase("foo_bar")
print(string)
string = casefy.pascalcase("fooBar")
print(string)
string = casefy.sentencecase("fooBar")
print(string)
string = casefy.separatorcase("fooBar", separator="/")
print(string)
string = casefy.separatorcase("fooBARbaz", separator="%", keep_together=["bar"])
print(string)
string = casefy.snakecase("fooBar")
print(string)
string = casefy.snakecase("fooBARbaz", keep_together=["bar"])
print(string)
string = casefy.snakecase("FOO BAR")
print(string)
string = casefy.titlecase("fooBarBaz")
print(string)
string = casefy.uppercase("fooBar")
print(string)
string = casefy.upperkebabcase("fooBar")
print(string)
Contribute
If you find a bug, please open an issue. Pull Requests are also welcome!
Acknowledgements
This project started when I saw that the package
python-stringcase
was
flagged-out-of-date in the Arch AUR Repository. The project
stringcase seems not to be
actively maintained anymore, so I decided to address its issues and pull
requests and solve them in this new package. I kept the API as similar as
possible, in order to facilitate any possible migration. I thank Taka
Okunishi (author of stringcase) and its
contributors for their work.
Related projects
-
case-conversion
offers
a very similar functionality as this project. I probably wouldn't have written
this package if I had known of it before. However, the code of Casefy is more
lightweight and just enough for most cases. If you need more functionality,
e.g., detecting the case of a string, go with case-conversion
.
-
Inflection presents some overlap
with this project as well, allowing the transformation of strings from
CamelCase to underscored_string, but also singularizing and pluralizing
English words.
License
Casefy is distributed under the
MIT license.