Giter VIP home page Giter VIP logo

pycasestyle's Introduction

pycasestyle

pycasestyle is a Python library for converting variable naming styles between CamelCase, snake_case, kebab-case, and PascalCase.

Supported styles:
  • CamelCase
  • SnakeCase
  • KebabCase
  • PascalCase

Installation

To install pycasestyle, you can use pip:

Usage

You can import the text formatting styles directly from the pycasestyle module and use them in your code. Here's an example of how to use the text formatting styles:

# Converting to camelcase from text
camelcased_text = pycasestyle.camelcase.from_string("i want a camel")
print(camelcased_text)  # Output: "iWantACamel"

# Converting to camelcase from dict
camelcased_dict = pycasestyle.camelcase.from_dict({"i want a camel": "value"})
print(camelcased_dict)  # Output: {"iWantACamel": "value"}

# Converting to snakecase from text
snakecased_text = pycasestyle.snakecase.from_string("I Want A Snake")
print(snakecased_text)  # Output: "i_want_a_snake"

# Converting to snakecase from dict
snakecased_dict = pycasestyle.snakecase.from_dict({"I Want A Snake": "value"})
print(snakecased_dict)  # Output: {"i_want_a_snake": "value"}

# Converting to kebab-case
kebabcased_text = pycasestyle.kebabcase.from_string("I Want A Kebab")
print(kebabcased_text)  # Output: "i-want-a-kebab"

# Converting to kebab-case from dict
kebabcased_dict = pycasestyle.kebabcase.from_dict({"I Want A Kebab": "value"})
print(kebabcased_dict)  # Output: {"i-want-a-kebab": "value"}

# Converting to PascalCase from text
pascalcased_text = pycasestyle.pascalcase.from_string("i want a pascal")
print(pascalcased_text)  # Output: "IWantAPascal"

# Converting to PascalCase from dict
pascalcased_dict = pycasestyle.pascalcase.from_dict({"i want a pascal": "value"})
print(pascalcased_dict)  # Output: {"IWantAPascal": "value"}

Use cases

If you needed convert schemas, mappings, contracts, etc. This tool is specific to turn easily your job.

Real use case:

You need to migrate information from Postgres to Elasticsearch, however, the mapping used in Elastic is following the camelcase pattern, whereas in Postgres it is with the Snakecase pattern, see how simple it is to solve:

postgres_contract = {
    "id": 1,
    "customers_id": 32,
    "users_id": 56,
    "period_datetime": "2024-08-10"
}

elastic_contract = pycasestyle.camelcase.from_dict(postgres_contract)
print(elastic_contract) # Output: {
    "id": 1,
    "customersId": 32,
    "usersId": 56,
    "periodDatetime": "2024-08-10"
}

Contributing

If you encounter any issues or have suggestions for improvement, feel free to open an issue or submit a pull request on the GitHub repository <https://github.com/preduus/pycasestyle>.

License

This project is licensed under the Apache License 2.0 License. See the LICENSE <https://github.com/preduus/pycasestyle/LICENSE> file for more details.

pycasestyle's People

Contributors

preduus avatar

Stargazers

 avatar

Watchers

 avatar

pycasestyle's Issues

Package setuptools missing "packages" params.

Traceback (most recent call last): File "main.py", line 2, in <module> import pycasestyle ModuleNotFoundError: No module named 'pycasestyle'

even after install package via pip, the package is not found.

Reason:
The setuptools was missing "packages" param with package name.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.