Skip to main content

Utilities for string case conversion.

Project description

Active Issues

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

# camelCase
string = casefy.camelcase("foo_bar")
print(string)  # fooBar

string = casefy.camelcase("FooBar")
print(string)  # fooBar

string = casefy.camelcase("FOO BAR")
print(string)  # fooBar


# PascalCase
string = casefy.pascalcase("foo_bar")
print(string)  # FooBar

string = casefy.pascalcase("fooBar")
print(string)  # FooBar


# snake_case
string = casefy.snakecase("fooBar")
print(string)  # foo_bar

string = casefy.snakecase("fooBARbaz", keep_together=["bar"])
print(string)  # foo_bar_baz

string = casefy.snakecase("FOO BAR")
print(string)  # foo_bar


# CONST_CASE
string = casefy.constcase("fooBar")
print(string)  # FOO_BAR


# kebab-case
string = casefy.kebabcase("fooBar")
print(string)  # foo-bar


# UPPER-KEBAB-CASE
string = casefy.upperkebabcase("fooBar")
print(string)  # FOO-BAR


# separator case
string = casefy.separatorcase("fooBar", separator="/")
print(string)  # foo/bar

string = casefy.separatorcase("fooBARbaz", separator="%", keep_together=["bar"])
print(string)  # foo%bar%baz


# Sentence case
string = casefy.sentencecase("fooBar")
print(string)  # Foo bar


# Title Case
string = casefy.titlecase("fooBar")
print(string)  # Foo Bar


# Alphanum3ric case (removes non-alphanumeric chars)
string = casefy.alphanumcase("foo - 123 ; bar!")
print(string)  # foo123bar

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.

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

casefy-0.1.7.tar.gz (123.3 kB view details)

Uploaded Source

Built Distribution

casefy-0.1.7-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file casefy-0.1.7.tar.gz.

File metadata

  • Download URL: casefy-0.1.7.tar.gz
  • Upload date:
  • Size: 123.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.13

File hashes

Hashes for casefy-0.1.7.tar.gz
Algorithm Hash digest
SHA256 6accce985a64b9edb2a610a29ac489d78fac80e52ff8f2d137e294f2f92b8027
MD5 47b6bbcf29d0b55b3945c2a2a22a192a
BLAKE2b-256 64bd198e4bc5dbfa8d363106fac2ca0bbd8639e1c66d7fbd2c4e3383a9cc0cb4

See more details on using hashes here.

File details

Details for the file casefy-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: casefy-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.13

File hashes

Hashes for casefy-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 ab05ff1c67f2a8e62d9f8986fa9a849416d61ac5413ec57d1f827b4f36589cf6
MD5 e5b66548cb8bd86030b39f922494216c
BLAKE2b-256 aa0924eff895c2b59e7bd2d6aa1cc2e7955137844ec4f9f06e2770a1399755a3

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