Skip to main content

tocase provides an API to recase string into any case

Project description

PyPI Version Build Status

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 for_strings if you want to use the basic API to recase strings. Import the for_pandas modules to use the pandas API to recase column names and column values.

import tocase.tocase.for_strings.ToCase as ToCase
import tocase.tocase.for_pandas

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

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

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

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

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("Kebab-case").kebab() # ==> kebab-case
Tocase("kebab Case").kebab() # ==> kebab-case

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

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("Snake-case").snake() # ==> snake_case
Tocase("snake Case").snake() # ==> snake_case

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("Title-case").title() # ==> "Title Case"
Tocase("title Case").title() # ==> "Title Case"

With pandas DataFrames

You can work with pandas DataFrame to recase columns names or column values. See the following examples with fake data.

columns = ["first name", "last name", "age", "family doctor"]
values = [
        ["Jules", "Otti", 35, "Dr James Porter"],
        ["Marie", "Curie", 22, "Dr Vicky Laporte"],
        ["Marc", "El Bichon", 35, "Dr Hyde Frank"]
        ]
data =  pd.DataFrame(data=values, columns=columns)

To recase columns names, use the col DataFrame accessor and the appropriate recasing function described above.

print(data)

"""
  first name last name  age   family doctor
0      Jules      Otti   35   DrJamesPorter
1      Marie     Curie   22  DrVickyLaporte
2       Marc  ElBichon   35     DrHydeFrank

"""

print(data.col.constant())

"""
  FIRST_NAME LAST_NAME  AGE   FAMILY_DOCTOR
0      Jules      Otti   35   DrJamesPorter
1      Marie     Curie   22  DrVickyLaporte
2       Marc  ElBichon   35     DrHydeFrank
"""

To recase columns values, use the val DataFrame accessor, the appropriate recasing function described above with a list of the columns to be processed.

columns_to_process = ["first name", "last name", "family doctor"]
print(data.val.constant(columns_to_process))

"""
  first name  last name  age     family doctor
0      JULES       OTTI   35   DR_JAMES_PORTER
1      MARIE      CURIE   22  DR_VICKY_LAPORTE
2       MARC  EL_BICHON   35     DR_HYDE_FRANK

"""

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 tests, 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

tocase-1.0.0.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

tocase-1.0.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file tocase-1.0.0.tar.gz.

File metadata

  • Download URL: tocase-1.0.0.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.8 CPython/3.7.10 Linux/5.11.0-7620-generic

File hashes

Hashes for tocase-1.0.0.tar.gz
Algorithm Hash digest
SHA256 4b4b8e93ed55a830f05574ed9c6cb5b626d037129c2fa3548f47e78ffb316272
MD5 328ae1c826189c3c0206fce69a80bda4
BLAKE2b-256 0c877fe5fab77047993f77c31e35fb5836933af7d435fe128fde6fd1c0c15fe9

See more details on using hashes here.

File details

Details for the file tocase-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: tocase-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.8 CPython/3.7.10 Linux/5.11.0-7620-generic

File hashes

Hashes for tocase-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 61d62e17ac47e73b52dc76ddd6a5cf6f59a71d39e45e0ad3331d5f71a5055976
MD5 638011048ee8d5045239fe254245d460
BLAKE2b-256 cc73187395a742afb50f2fdfbf0690f13df4a9f1d165e357d692aeb9ce3d57ec

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