A string case conversion package.
Project description
Case Converter
A robust python package for transforming string cases such as Hello, world!
into
helloWorld
(camelcase).
General usage
from caseconverter import camelcase
camelcase("Hello, world!") # output: helloWorld
Delimeter behavior
If multiple delimeter characters are identified next to eachother they will be considered as a single delimeter. For example, -_
contains 2 different delimeter characters and is considered a single delimeter.
Available conversions
camelcase
from caseconverter import camelcase
camelcase("Hello, world!")
helloWorld
cobolcase
from caseconverter import cobolcase
cobolcase("Hello, world!")
HELLO-WORLD
flatcase
from caseconverter import flatcase
flatcase("Hello, world!")
helloworld
kebabcase
from caseconverter import kebabcase
kebabcase("Hello, world!")
hello-world
macrocase
from caseconverter import macrocase
macrocase("Hello, world!")
HELLO_WORLD
Additional options
delims_only : bool
- Only consider delimiters as boundaries (default: False
).
pascalcase
from caseconverter import pascalcase
pascalcase("Hello, world!")
HelloWorld
snakecase
from caseconverter import snakecase
snakecase("Hello, world!")
hello_world
Options for all conversions
Stripping punctuation
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
.
camelcase("Hello, world!", strip_punctuation=False) # output: hello,World!
Delimeter customization
Default delimiters used to denote a token boundary.
DELIMITERS = " -_"
You can pass delims
to each case conversion function to specify a custom
set of delimiters.
# Use a pipe `|` as the only delimiter.
camelcase("Hello,|world!", delims="|") # output: helloWorld
Boundaries definitions
Name | Description |
---|---|
OnDelimeterUppercaseNext | On a delimieter, upper case the following character |
OnDelimeterLowercaseNext | On a delimeter, lower case the following character |
OnUpperPrecededByLowerAppendUpper | On an upper case character followed by a lower case character, append the upper case character |
OnUpperPrecededByLowerAppendLower | On an upper case character preceeded by a lower case character append the lower case character |
OnUpperPrecededByUpperAppendJoin | On an upper case caharacter preceeded by an upper append the join character. Join characters are context dependent. Example: macro cast join character is _ |
OnUpperPrecededByUpperAppendCurrent | On an upper case character preceeded by an upper case character append the upper case character |
Contributing
- Write clean code.
- Write new tests for new use-cases.
- Test your code before raising a PR.
- Use black to format your code.
Reference
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for case_convertor-1.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 54a6b4d72600e0e39b94c87d24baa7159937d29c490b5086e3b151d88922c0f2 |
|
MD5 | 36745ec1efcbd99ba6e4c56001917ea4 |
|
BLAKE2b-256 | f519de37729844b005db9f7e8451d8e3b0848a942b20aa3ad959374a859b701b |