Skip to main content

Convert between different types of cases (unicode supported)

Project description

This is a fork

All credit goes to Alejandro Frias - here is the original repo. I only forked to gain vendorized dependencies.

differences between my fork and the original

  • I needed to remove the 'regex' dependency because it is not pure python and thus couldn't be vendorized.
  • I removed python2 support. It might be trivial to add later but I don't plan on using python2 personally so if you want to use this fork and need support then create a github issue.

Case Conversion

This is a port of the CaseConversion Sublime Plugin, by Davis Clark's, to a regular python package. I couldn't find any other python packages on PyPi at the time (Feb 2016) that could seamlessly convert from any case to any other case without having to specify from what type of case I was converting. This plugin worked really well, so I separated the (non-sublime) python parts of the plugin into this useful python package. I also added Unicode support using the regex package. Credit goes to Davis Clark's and the contributors to that plugin (Scott Bessler, Curtis Gibby, Matt Morrison) for their awesome work on making such a robust and awesome case converter.

Features

  • Autodetection of case (no need to specify explicitly which case you are converting from!)
  • Unicode supported (non-ASCII characters for days!)
  • Acronym detection (no funky splitting on every capital letter of an all caps acronym like HTTPError!)
  • And obviously case conversions from/to the following types of cases:
    • camelcase
    • pascalcase
    • snakecase
    • dashcase
    • spinalcase (alias for dashcase)
    • kebabcase (alias for dashcase)
    • constcase
    • screaming_snakecase (alias for constcase)
    • dotcase
    • separate_words
    • slashcase
    • backslashcase
  • Oh! Python2 and Python3 supported!
Usage

Normal use is self-explanatory.

>>> import case_conversion
>>> case_conversion.kebabcase("FOO_BAR_STRING")
'foo-bar-string'
>>> print(case_conversion.constcase(u"fóó-bar-string"))
FÓÓ_BAR_STRING

To use acronym detection set detect_acronyms to True and pass in a list of acronyms to detect as whole words.

>>> import case_conversion
>>> case_conversion.snakecase("fooBarHTTPError")
'foo_bar_h_t_t_p_error'  # ewwww
>>> case_conversion.snakecase("fooBarHTTPError", detect_acronyms=True, acronyms=['HTTP'])
'foo_bar_http_error'  # pretty

Install

pip install case-conversion

Licence

Using MIT licence with Davis Clark's Copyright

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

po_case_conversion-0.4.0.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

po_case_conversion-0.4.0-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file po_case_conversion-0.4.0.tar.gz.

File metadata

  • Download URL: po_case_conversion-0.4.0.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.17 CPython/3.7.4 Linux/5.2.11-arch1-1-ARCH

File hashes

Hashes for po_case_conversion-0.4.0.tar.gz
Algorithm Hash digest
SHA256 3081a4b05004558ba4d4e881a5333ad707243b72bcc21377772a96fd28b77827
MD5 2fd7f71ee1aae02102816a0fc41ecbce
BLAKE2b-256 05def67e3bfdbfd902113701f593c69384cec4042b513e94d492eed621539170

See more details on using hashes here.

File details

Details for the file po_case_conversion-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: po_case_conversion-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.17 CPython/3.7.4 Linux/5.2.11-arch1-1-ARCH

File hashes

Hashes for po_case_conversion-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 624e73247b42e0be0d726c3f45f672a2d7f0e7aad3ae8354a665fb3ded72bc9d
MD5 fb5d35142e9f80b23520bb416089ae37
BLAKE2b-256 7dcb59e844f19ae1e8bf026b428cf08e0bc4295a8fb37f451f6084b351d9970c

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