Giter VIP home page Giter VIP logo

python-case-converter's Introduction

Case Converter

pipline wheel coverage license

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

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

Behavior

Delimiters

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.

Boundary 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

  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.

python-case-converter's People

Contributors

chrisdoherty4 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

python-case-converter's Issues

Update readme

The README no longer discusses rules correctly, specifically the notes on boundaries. Update to reflect the code.

Improve logging configurability

The logging capability that can be remarkably useful for debugging is prone to being left 'on'. There needs to be a much simpler way of enabling logging that is based on configuration rather than changing the code ad-hoc so it doesn't get left on like the 1.0.3 to 1.0.4 release.

Issue with single-letter words

For example, macrocase("FooXBar") produces "FOO_XBAR" as opposed to "FOO_X_BAR" which you would expect. snakecase("FooXBar") - "foo_xbar" instead of "foo_x_bar", respectively.

[Not an issue] Just a thank you :-)

This project worked so flawlessly and it helped me finishing up a critical feature

Thanks a lot for spending time and energy in creating this!

Macrocase adds extra delimiters for non-cased input strings in 1.0.4

Hi, and thanks for this lovely little utility library!

The fix for #1 appears to have some unintended consequences for string inputs that aren't camel or pascal-cased, i.e.
"IP Address" becomes I_P_Address. I'm wondering if it would make sense to only infer boundaries based on capital letters if e.g. the input does not contain spaces? I do understand that this is an edge-case, however.

Is the behavior of `macrocase` right?

macrocase("My URL") returns MY_UR_L (note the underscore between R and L). I would expect MY_URL

Regarding the word boundaries I would expect a result similar to cobolcase, snakecase, and kebabcase.

cobolcase("My URL") returns MY-URL

>>> from caseconverter import *
>>> cases = [str, macrocase, cobolcase, kebabcase, snakecase]
>>> for case in cases:
...     t = f"{case.__name__: <15}"
...     for s in ["My New URL", "My NewURL", "My URL", "My IP", "My MACRO"]:
...         t += f"{case(s): <15}"
...     print(t)

str            My New URL     My NewURL      My URL         My IP          My MACRO
macrocase      MY_NEW_UR_L    MY_NEW_U_R_L   MY_UR_L        MY_IP          MY_MA_C_R_O
cobolcase      MY-NEW-URL     MY-NEW-URL     MY-URL         MY-IP          MY-MACRO
kebabcase      my-new-url     my-new-url     my-url         my-ip          my-macro
snakecase      my_new_url     my_new_url     my_url         my_ip          my_macro

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.