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.
Metadata
Release files for altercase 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| altercase-0.1.0.tar.gz | 8.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| altercase-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 15.3 kB
Release files / altercase-0.1.0.tar.gz
| Download URL | altercase-0.1.0.tar.gz |
|---|---|
| Size | 8.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b4b1f16fb00312db5a0490ff927d5f8f3cf73f564ccd5b92950cc4f8b3117a4f
|
|
BLAKE2b-256 checksum How to use checksums |
4fd60c5fb9cc96ca8badd154d6fb6f02dc9c502990e9d7e6eb41b0ccfddd43d5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.12.3
|
Release files / altercase-0.1.0-py3-none-any.whl
| Download URL | altercase-0.1.0-py3-none-any.whl |
|---|---|
| Size | 7.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
edc333de243bc8dda750d9a5243eb7c8beafea1e8f961193cf1157343440a251
|
|
BLAKE2b-256 checksum How to use checksums |
95e160b969508080da908d22d8f7133918b43e9de5221f058426a0c8ec87c4d8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.12.3
|
Security for altercase 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.