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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for altercase-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | edc333de243bc8dda750d9a5243eb7c8beafea1e8f961193cf1157343440a251 |
|
MD5 | 39710fc16524a55f3da99608779568da |
|
BLAKE2b-256 | 95e160b969508080da908d22d8f7133918b43e9de5221f058426a0c8ec87c4d8 |