Skip to main content

A string case conversion package.

Project description

Case Converter

pipline wheel coverage license

A robust python package for transforming string cases such as Hello, world! into helloWorld (camelcase).

General usage

Import a case conversion helper function, or the conversion object itself.

from caseconverter import camelcase, Camel

camelcase("Hello, world!") # output: helloWorld
Camel("Hello, world!").convert() # output: helloWorld

By default, case conversion takes into consideration 2 boundary conditions for token separation.

  1. Delimiters.
  2. Lowercase char followed by an uppercase char.

The action taken when a boundary is identified depends on the case conversion.

If the input string is all uppercase it can only be processed based on delimiters.

Customizing delimiters

Default delimiters used to denote a token boundary.

# Default delimiters
DELIMITERS = " -_"

You can pass delims to each case conversion function to specify a custom set of delimiters.

from caseconverter import camelcase

# Use a pipe `|` as the only delimiter.
camelcase("Hello,|world!", delims="|") # output: helloWorld

Stripping punctuation

Generally, punctuation is stripped when doing a case conversion. However, should you wish to keep the punctuation you can do so by passing strip_punctuation=False.

from caseconverter import camelcase

camelcase("Hello, world!", strip_punctuation=False) # output: hello,World!

Available conversions

camelcase

from caseconverter import camelcase

camelcase("Hello, world!") 
helloWorld

pascalcase

from caseconverter import pascalcase

pascalcase("Hello, world!")
HelloWorld

snakecase

from caseconverter import snakecase

snakecase("Hello, world!")
hello_world

flatcase

from caseconverter import flatcase

flatcase("Hello, world!")
helloworld

kebabcase

from caseconverter import kebabcase

kebabcase("Hello, world!")
hello-world

cobolcase

from caseconverter import cobolcase

cobolcase("Hello, world!")
HELLO-WORLD

macrocase

from caseconverter import macrocase

macrocase("Hello, world!")
HELLO_WORLD

Contributing

  1. Write clean code.
  2. Write new tests for new use-cases.
  3. Test your code before raising a PR.
  4. Use black to format your code.

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

case-converter-1.0.2.tar.gz (6.6 kB view hashes)

Uploaded Source

Built Distribution

case_converter-1.0.2-py3-none-any.whl (7.6 kB view hashes)

Uploaded Python 3

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