Skip to main content

Convert strings between camelCase, snake_case, PascalCase, kebab-case, and more

Project description

philiprehberger-str-case

Convert strings between camelCase, snake_case, PascalCase, kebab-case, and more.

Install

pip install philiprehberger-str-case

Usage

from philiprehberger_str_case import to_snake, to_camel, to_pascal, to_kebab

to_snake("HTMLParser")       # "html_parser"
to_camel("html_parser")      # "htmlParser"
to_pascal("get-https-url")   # "GetHttpsUrl"
to_kebab("getHTTPSUrl")      # "get-https-url"

Acronym handling

Acronyms are split correctly:

from philiprehberger_str_case import to_snake

to_snake("HTMLParser")    # "html_parser"
to_snake("getHTTPSUrl")  # "get_https_url"
to_snake("XMLToJSON")    # "xml_to_json"

More formats

from philiprehberger_str_case import to_constant, to_title, to_dot, to_path

to_constant("htmlParser")  # "HTML_PARSER"
to_title("html_parser")    # "Html Parser"
to_dot("htmlParser")       # "html.parser"
to_path("htmlParser")      # "html/parser"

Convert dictionary keys

from philiprehberger_str_case import convert_keys, to_snake

data = {
    "firstName": "John",
    "lastName": "Doe",
    "contactInfo": {
        "emailAddress": "john@example.com",
        "phoneNumber": "555-1234",
    },
}

convert_keys(data, to_snake)
# {
#     "first_name": "John",
#     "last_name": "Doe",
#     "contact_info": {
#         "email_address": "john@example.com",
#         "phone_number": "555-1234",
#     },
# }

Detect case

from philiprehberger_str_case import detect_case

detect_case("my_variable")   # "snake_case"
detect_case("myVariable")    # "camelCase"
detect_case("MyVariable")    # "PascalCase"
detect_case("my-variable")   # "kebab-case"
detect_case("MY_VARIABLE")   # "CONSTANT_CASE"

API

Function Description
to_snake(s) Convert to snake_case
to_camel(s) Convert to camelCase
to_pascal(s) Convert to PascalCase
to_kebab(s) Convert to kebab-case
to_constant(s) Convert to CONSTANT_CASE
to_title(s) Convert to Title Case
to_dot(s) Convert to dot.case
to_path(s) Convert to path/case
convert_keys(d, converter) Recursively convert dict keys
detect_case(s) Detect case convention of a string

License

MIT

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

philiprehberger_str_case-0.1.1.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

philiprehberger_str_case-0.1.1-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file philiprehberger_str_case-0.1.1.tar.gz.

File metadata

  • Download URL: philiprehberger_str_case-0.1.1.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for philiprehberger_str_case-0.1.1.tar.gz
Algorithm Hash digest
SHA256 59a8f14ca082e81267c8e66d6333063ba6cb0ec07a831a0e7ed111f716f1786d
MD5 b379bc22b752cadec3583128dcdf5cc3
BLAKE2b-256 2ac011dc45e07d4005a1b7bcc038eb5258b9fcdb9168c8a049bc182fbbc67bc9

See more details on using hashes here.

File details

Details for the file philiprehberger_str_case-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for philiprehberger_str_case-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bbd9adb1783273fa38ab4d85ba18cbba3974cdaab99108186b17633045fe7572
MD5 baeb8668af5d9b680531ea3c0cd3e834
BLAKE2b-256 e678dd86171e732f813e3101bc36424d80a23ddaf2d49b7c604b1bf62742956c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page