tocase provides an API to recase string into any case
Project description
Functionality
tocase
leverages the regex
library to convert your strings into any case.
Setup
To install the package run the following command:
pip install tocase
Once installed import the ToCase
class.
Usage
Camel
It is a naming convention where the first letter in compound words is capitalized, except for the first one.
# Example with simple string
Tocase("camel-case").camel() # ==> camelCase
Tocase("camel case").camel() # ==> camelCase
# Example with Pandas DataFrame and Iris DataFrame
list(df_with_original_column_names.columns) = ['sepal_length', 'sepal_width', 'petal_length', 'petal_width', 'species']
df_with_modified_column_names = df.rename(columns=lambda x: ToCase(x).camel()
list(df_with_modified_column_names.columns) = ['sepalLength', 'sepalWidth', 'petalLength', 'petalWidth', 'species']
Constant
It is a naming convention where all letters in compound words are capitalized. Words are joined with an underscore.
# Example with simple string
Tocase("Constant-case").constant() # ==> CONSTANT_CASE
Tocase("constant Case").constant() # ==> CONSTANT_CASE
# Example with Pandas DataFrame and Iris DataFrame
list(df_with_original_column_names.columns) = ['sepal_length', 'sepal_width', 'petal_length', 'petal_width', 'species']
df_with_modified_column_names = df.rename(columns=lambda x: ToCase(x).constant()
list(df_with_modified_column_names.columns) = ['SEPAL_LENGTH', 'SEPAL_WIDTH', 'PETAL_LENGTH', 'PETAL_WIDTH', 'SPECIES']
Dot
It is a naming convention where all letters in compound words are lowercased. Words are joined with a dot.
# Example with simple string
Tocase("Dot-case").dot() # ==> dot.case
Tocase("dot Case").dot() # ==> dot.case
# Example with Pandas DataFrame and Iris DataFrame
list(df_with_original_column_names.columns) = ['sepal_length', 'sepal_width', 'petal_length', 'petal_width', 'species']
df_with_modified_column_names = df.rename(columns=lambda x: ToCase(x).dot()
list(df_with_modified_column_names.columns) = ['sepal.length', 'sepal.width', 'petal.length', 'petal.width', 'species']
Header
It is a naming convention where the first letter in compound words is capitalized. Words are joined by a dash.
# Example with simple string
Tocase("Header-case").header() # ==> Header-Case
Tocase("header Case").header() # ==> Header-Case
# Example with Pandas DataFrame and Iris DataFrame
list(df_with_original_column_names.columns) = ['sepal_length', 'sepal_width', 'petal_length', 'petal_width', 'species']
df_with_modified_column_names = df.rename(columns=lambda x: ToCase(x).header()
list(df_with_modified_column_names.columns) = ['Sepal-Length', 'Sepal-Width', 'Petal-Length', 'Petal-Width', 'Species']
Kebab
It is a naming convention where all letters in compound words are lowercased. Words are joined by a dash.
# Example with simple string
Tocase("Header-case").kebab() # ==> Header-Case
Tocase("header Case").kebab() # ==> Header-Case
# Example with Pandas DataFrame and Iris DataFrame
list(df_with_original_column_names.columns) = ['sepal_length', 'sepal_width', 'petal_length', 'petal_width', 'species']
df_with_modified_column_names = df.rename(columns=lambda x: ToCase(x).kebab()
list(df_with_modified_column_names.columns) = ['sepal-length', 'sepal-width', 'petal-length', 'petal-width', 'species']
Pascal
It is a naming convention where the first letter in compound words is capitalized.
# Example with simple string
Tocase("Pascal-case").pascal() # ==> PascalCase
Tocase("pascal Case").pascal() # ==> PascalCase
# Example with Pandas DataFrame and Iris DataFrame
list(df_with_original_column_names.columns) = ['sepal_length', 'sepal_width', 'petal_length', 'petal_width', 'species']
df_with_modified_column_names = df.rename(columns=lambda x: ToCase(x).pascal()
list(df_with_modified_column_names.columns) = ['SepalLength', 'SepalWidth', 'PetalLength', 'PetalWidth', 'Species']
'Sepal-Length', 'Sepal-Width', 'Petal-Length', 'Petal-Width', 'Species'Snake
It is a naming convention where all letters in compound words are lowercased. Words are joined by an underscore.
# Example with simple string
Tocase("Pascal-case").snake() # ==> PascalCase
Tocase("pascal Case").snake() # ==> PascalCase
# Example with Pandas DataFrame and Iris DataFrame
list(df_with_original_column_names.columns) = ['sepal_length', 'sepal_width', 'petal_length', 'petal_width', 'species']
df_with_modified_column_names = df.rename(columns=lambda x: ToCase(x).snake()
list(df_with_modified_column_names.columns) = ['sepal_length', 'sepal_width', 'petal_length', 'petal_width', 'species']
Title
It is a naming convention where the first letter in compound words is capitalized. Words are separated by a space.
# Example with simple string
Tocase("Pascal-case").snake() # ==> PascalCase
Tocase("pascal Case").snake() # ==> PascalCase
# Example with Pandas DataFrame and Iris DataFrame
list(df_with_original_column_names.columns) = ['sepal_length', 'sepal_width', 'petal_length', 'petal_width', 'species']
df_with_modified_column_names = df.rename(columns=lambda x: ToCase(x).snake()
list(df_with_modified_column_names.columns) = ['Sepal Length', 'Sepal Width', 'Petal Length', 'Petal Width', 'Species']
For developers
Clone or download the repository on your machine. If you have poetry
installed just run the following command to restore the working environment:
poetry install
If you don't have poetry
you can use pip
and the requirements.txt
file:
pip install -r requirements.txt
To run test, stay at the root of the directory and run:
pytest -v
All contributions are more than welcome. So feel free to to make a PR.
Author
Faouzi Braza
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
Built Distribution
File details
Details for the file tocase-0.2.1.tar.gz
.
File metadata
- Download URL: tocase-0.2.1.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.7 CPython/3.7.10 Linux/5.11.0-7620-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f269d2d70b5fda815351d85b4213eb0a6eff3aeda154d3dff0d2ca72e6824581 |
|
MD5 | 1fb567b671191ec7c8a8fe2b06117e22 |
|
BLAKE2b-256 | 8457517bce7e41adb1e2b375f16193aebce68055e58652f4dd2b1a0f97dc64e9 |
File details
Details for the file tocase-0.2.1-py3-none-any.whl
.
File metadata
- Download URL: tocase-0.2.1-py3-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.7 CPython/3.7.10 Linux/5.11.0-7620-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f420ffc874e40b29af130330caa692dbca88e622c81083040d63800c05da3b4 |
|
MD5 | 37fa3d23c587b3f7f28ab5be67e07de6 |
|
BLAKE2b-256 | fd3a74cc7b0d9e5a7c313158977df83f0eec72e9740933c74343f102fcc1d338 |