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

Development

pip install -e .
python -m pytest tests/ -v

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.4.tar.gz (4.5 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.4-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for philiprehberger_str_case-0.1.4.tar.gz
Algorithm Hash digest
SHA256 4d18f4b1544d337ea43a36726b2b295299a8763ca656cd4e4bde4ff5b46b24f8
MD5 4f46365f7861e3733004cf9d2ffc2059
BLAKE2b-256 8e4295709bd8a431fe30b059eee963e62a52d369168902e48164b02d31fcf147

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for philiprehberger_str_case-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 b8c9bac238a887dddbb3e1e4d9e8926e6269225e8a939bbb316dfa0806f247b0
MD5 02a2757fd105a8a296af6179d3205ad6
BLAKE2b-256 817f0bbe06001e11665df64ce8638ae6f0bf4d8a1f8ef753d2b0d40c47ce00a8

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