Skip to main content

Contributors Forks Stargazers Issues MIT License LinkedIn


icon

incase

A word case management library with too many features (just in case).

Table of Contents

  1. About The Project
  2. Getting Started
  3. Usage
  4. Roadmap
  5. Contributing
  6. Contact

About The Project

Incase is a library to help manage word case. It includes a class for abstracting away from case for easy comparison of words or conversion to any case. Incase also includes a flexible decorator for managing the case of keywords, inputs, and outputs from functions.

Getting Started

To get a local copy up and running follow these simple steps.

Installing with pip

pip install incase

For information about cloning and dev setup see: Contributing

Usage

CLI

You can leverage incase in shell scripts or other non-python contexts by calling it from the cli. Example:

The default output is snake case.

$ incase someCamel
some_camel

Use the --case option to set output case

$ incase someCamel --case lower
some camel

Caseless

Here is an example showing basic usage of the Caseless class.

from incase import Case, Caseless

# Easily output any case
example = Caseless("example string")


# By property
print(example.snake)
# my_cool_example_class

# Or by subscript (string or Case)
print(example["camel"])
# exampleString

print(example[Case.UPPER_SNAKE])
# EXAMPLE_STRING

# Caseless ignores case when checking equality with strings
print(Caseless("some name") == "SOME_NAME")
# True

# Caseless can also generate case coercion functions
make_camel = Caseless.factory("camel")

print(make_camel("snake_case"))
# snakeCase

Helper functions

case_modifier is a function for altering other functions. It can change the incoming case of parameter values, the case of the keywords provided, or the case of the function output.

from incase import Case, case_modifier


# Some functions you don't control
def external_function(expectsCamel, iterationCount):
    # expects camelCase parameter names
    for i in range(iterationCount):
        print(expectsCamel)

# We'll use case_modifier. Now any keyword will be turned to camelCase
f = case_modifier(keywords_case=Case.CAMEL)(external_function)

f(expects_camel="this", iteration_count=1)
# this

# Here, we'll use case modifier as a function decorator
#  to give a sarcastic twist to our output
@case_modifier(args_case="sarcasm")
def say_words(*args) -> None:
    [print(word) for word in args]

say_words("It's all about", "the he said", "SHE SAID")
# It's aLl aBoUt
# ThE He sAi
# ShE SaId

Finally, incase is a powerful case coercion function.

from incase import incase


# It covers the basic case
print(incase("snake", "example text"))
# example_text

# But can also handle sequences
print(incase("upper", ["three", "word", "list"]))
# ['THREE', 'WORD', 'LIST']
print(incase("upper", ("three", "word", "tuple")))
# ('THREE', 'WORD', 'TUPLE')

# Even generators
generator = (word for word in ["some", "list"])
incased = incase("upper", generator)
print(incased)
# <generator object _incase_single.<locals>.<genexpr> at ...
print(list(incased))
# ['SOME', 'LIST']

# Or nested objects
nested = {
    "first_key": ["some", "list"],
    "second_key": {"another": "dict"},
    "third_key": 1,
}
print(incase("upper", nested))
# {"first_key": ["SOME", "LIST"], "second_key": {"another": "DICT"}, "third_key": 1}

# Finally, it is possible to map case to objects
print(incase(["upper", "lower", "snake", "camel"], ["some_word"] * 4))
# ['SOME WORD', 'some word', 'some_word', 'someWord']

# By key
print(
    incase(
        {"first_key": "alternating", "second_key": "title"},
        {"first_key": "some example", "second_key": "another example"},
    )
)
# {'first_key': 'SoMe eXaMpLe', 'second_key': 'Another Example'}

Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Add tests, we aim for 100% test coverage Using Coverage
  4. Commit your Changes (git commit -m 'Add some AmazingFeature')
  5. Push to the Branch (git push origin feature/AmazingFeature)
  6. Open a Pull Request

Cloning / Development setup

  1. Clone the repo and install
    git clone https://github.com/kajuberdut/incase.git
    cd incase
    pipenv install --dev
    
  2. Run tests
    pipenv shell
    ward
    

For more about pipenv see: Pipenv Github

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Patrick Shechet - patrick.shechet@gmail.com

Project Link: https://github.com/kajuberdut/incase

Release files for incase 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for incase 0.0.2
File Size Uploaded
incase-0.0.2.tar.gz 7.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for incase 0.0.2
File Interpreter ABI Platform
incase-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 16.1 kB

Release files / incase-0.0.2.tar.gz

Download URL incase-0.0.2.tar.gz
Size 7.9 kB
Tags Source
SHA-256 checksum
How to use checksums
5194f4798d26b5dac888014937f4111e859ea979fa7d9032310173acb9e65479
BLAKE2b-256 checksum
How to use checksums
5cb77a6ecbc9308a62ab65031bdac1ac58da090f675f4435f6d32168cbd890d4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.5

Release files / incase-0.0.2-py3-none-any.whl

Download URL incase-0.0.2-py3-none-any.whl
Size 8.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
185f361c7cd6286c8076efbab323c73db32246db0a4d0d7dc790c2a3d1e997e6
BLAKE2b-256 checksum
How to use checksums
c17cf75646deb0285f93bd6fdaf017ad5c6be04fa999d686e2059c87179c599c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.5

Release history Release notifications | RSS feed

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

This release

0.0.2 This release

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page