Skip to main content

Convert strings into different cases.

Project description

altercase

Convert strings into different cases.

Installation

pip install altercase

Usage

altercase --help
Usage: altercase [OPTIONS] CASE INPUT

  Convert strings into different cases. (version: x.x.x)

Options:
  -h/--help   Show this message and exit.

Arguments:
  CASE        Accepts one of ('camel', 'pascal', 'snake', 'hazard', 'kebab', 'train', 'title', 'sentence').
  INPUT       String(s) to convert.

altercase title theQuickBrownFoxJumpsOverTheLazyDog
The Quick Brown Fox Jumps Over The Lazy Dog

altercase kebab Foobar2000 'HTTP/2 Protocol'
foobar-2000
http-2-protocol

echo IEEE802.3EthernetStandard PCIe4.0Interface | altercase hazard
IEEE_802_3_ETHERNET_STANDARD
PCI_E_4_0_INTERFACE

Case conversion

Camel case

theQuickBrownFoxJumpsOverTheLazyDog

Spaces and punctuation are removed and the first word will be in lowercase. Other words will have their first letter be capitalized. Abbreviation capitalization is always preserved.

import altercase

                                            # ['API', 'v2', 'Parser']
                                            #   ↓↓↓    ↓
                                            # ['api', 'V2', 'Parser']
print(altercase.camel_case("APIv2Parser"))  # apiV2Parser

Pascal case

TheQuickBrownFoxJumpsOverTheLazyDog

Spaces and punctuation are removed and the first letter of each word is capitalized. Abbreviation capitalization is always preserved.

import altercase

                                             # ['API', 'v2', 'Parser']
                                             #          ↓
                                             # ['API', 'V2', 'Parser']
print(altercase.pascal_case("APIv2Parser"))  # APIV2Parser

Snake case

the_quick_brown_fox_jumps_over_the_lazy_dog

Spaces and punctuation are replaced by single underscores (_). All letters will be lowercase.

import altercase

                                            # ['API', 'v2', 'Parser']
                                            #   ↓↓↓          ↓
                                            # ['api', 'v2', 'parser']
print(altercase.snake_case("APIv2Parser"))  # api_v2_parser

Hazard case (Screaming Snake case)

THE_QUICK_BROWN_FOX_JUMPS_OVER_THE_LAZY_DOG

Spaces and punctuation are replaced by single underscores (_). All letters will be in uppercase.

import altercase

                                             # ['API', 'v2', 'Parser']
                                             #          ↓      ↓↓↓↓↓
                                             # ['API', 'V2', 'PARSER']
print(altercase.hazard_case("APIv2Parser"))  # API_V2_PARSER

Kebab case

the-quick-brown-fox-jumps-over-the-lazy-dog

Spaces and punctuation are replaced by single hyphens (-). All letters will be in lowercase.

import altercase

                                            # ['API', 'v2', 'Parser']
                                            #   ↓↓↓          ↓
                                            # ['api', 'v2', 'parser']
print(altercase.kebab_case("APIv2Parser"))  # api-v2-parser

Train case

THE-QUICK-BROWN-FOX-JUMPS-OVER-THE-LAZY-DOG

Spaces and punctuation are replaced by single hyphens (-). All letters will be in uppercase.

import altercase

                                            # ['API', 'v2', 'Parser']
                                            #          ↓      ↓↓↓↓↓
                                            # ['API', 'V2', 'PARSER']
print(altercase.train_case("APIv2Parser"))  # API-V2-PARSER

Title case

The Quick Brown Fox Jumps Over The Lazy Dog

Punctuations are removed and the first letter of each word is capitalized. Abbreviation capitalization is always preserved.

import altercase

                                            # ['API', 'v2', 'Parser']
                                            #          ↓
                                            # ['API', 'V2', 'Parser']
print(altercase.title_case("APIv2Parser"))  # API V2 Parser

Sentence case

The quick brown fox jumps over the lazy dog

Punctuations are removed and the first letter of the first word is capitalized. Other words will be in lowercase. Abbreviation capitalization is always preserved.

import altercase

                                               # ['API', 'v2', 'Parser']
                                               #          ↓     ↓
                                               # ['API', 'v2', 'parser']
print(altercase.sentence_case("APIv2Parser"))  # API v2 parser

String splitting

1st Pass
- separate the input string into 'words' whenever it switches from lowercase, uppercase, or digits;
  while ignoring non-alphanumeric chars

  'Foo'         → ['F', 'oo']
  'Foobar2000'  → ['F', 'oobar', '2000']
  'JWTToken'    → ['JWTT', 'oken']
  'WiFi'        → ['W', 'i', 'F', 'i']
  'APIv2Parser' → ['API', 'v', '2', 'P', 'arser']

2nd Pass
- if the previous word (is uppercase) and the current word (length > 1), (is lowercase)
  then take the last char from the previous word and insert it in front of the current word

  'Foo'         → ['F', 'oo']                     → ['Foo']
  'Foobar2000'  → ['F', 'oobar', '2000']          → ['Foobar', '2000']
  'JWTToken'    → ['JWTT', 'oken']                → ['JWT', 'Token']
  'APIv2Parser' → ['API', 'v', '2', 'P', 'arser'] → ['API', 'v', '2', 'Parser']

- if the previous word (length == 1), (is uppercase) and the current word (length == 1), (is lowercase)
  then move the char from the previous word and insert it in front of the current word

  'WiFi'        → ['W', 'i', 'F', 'i']   → ['Wi', 'Fi']

- if the previous word (length == 1), (is either 'v' or 'V') and the current word (is digit)
  then move the char from the previous word and insert it in front of the current word

  'APIv2Parser' → ['API', 'v', '2', 'P', 'arser'] → ['API', 'v', '2', 'Parser'] → ['API', 'v2', 'Parser']
import altercase

print(altercase.split_string("APIv2Parser"))  # ['API', 'v2', 'Parser']

Contributing

Contributions are welcome! If you have any suggestions, feature requests, or bug reports, please create an issue or submit a pull request.

License

This package is licensed under the MIT License. See the LICENSE file for details.

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

altercase-0.1.0.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

altercase-0.1.0-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file altercase-0.1.0.tar.gz.

File metadata

  • Download URL: altercase-0.1.0.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.3

File hashes

Hashes for altercase-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b4b1f16fb00312db5a0490ff927d5f8f3cf73f564ccd5b92950cc4f8b3117a4f
MD5 7a7a443e8f1435e23f6cbd4d330f17d7
BLAKE2b-256 4fd60c5fb9cc96ca8badd154d6fb6f02dc9c502990e9d7e6eb41b0ccfddd43d5

See more details on using hashes here.

File details

Details for the file altercase-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: altercase-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.3

File hashes

Hashes for altercase-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 edc333de243bc8dda750d9a5243eb7c8beafea1e8f961193cf1157343440a251
MD5 39710fc16524a55f3da99608779568da
BLAKE2b-256 95e160b969508080da908d22d8f7133918b43e9de5221f058426a0c8ec87c4d8

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