Skip to main content

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

Project description

philiprehberger-str-case

Tests PyPI version License

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.2.tar.gz (4.4 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.2-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: philiprehberger_str_case-0.1.2.tar.gz
  • Upload date:
  • Size: 4.4 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.2.tar.gz
Algorithm Hash digest
SHA256 0e7ed2f825d631a4bee851b59724d0a7d236cba7f29871e4f8f40c45d98ac72c
MD5 9cf6f65c701970cc9e2dd1342a5741cc
BLAKE2b-256 94e1e3f644181d04752e8fdc77c54cae257fcc20624427103c2d5a28b0194540

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for philiprehberger_str_case-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7ce5f5ba79a2909b2ae94ad0c3b7c63867b964136d6762a46aa33925bd0c98cf
MD5 57f98a437a7bff0abe72f7429717214e
BLAKE2b-256 35a5e78b29f39c7f0528b2201bd986275ff8cd7da34313dd506349043a850ff8

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