Skip to main content

string-decorator

Python Module to have fun with strings. The module also makes use of python decorators
PyPI version Downloads Downloads License: MIT

Usage

Example 1 -> Calculating expression from given string

from string_decorator import calculate
print(calculate("(123+23) * 23 / 32"))

Output

104.9375

Example 2 -> Validating text based on given conditions

from string_decorator import validate_text
print(validate_text("imEternity1234@strings", length = 13, uppercase = 1, lowercase = 5, numbers = 4, special_characters=1))

Output

True

Example 3 -> Converting the string to random cases

from string_decorator import randcase
print(randcase("hello"))

Output

hELlO

Example 4 -> Extracting numbers from the given string

from string_decorator import num_extract
print(num_extract("hello123 23,211 42.23 -134 g00d"))

Output

['123', '23,211', '42.23', '-134', '00']

Example 5 -> Changing string to CONSTANT_CASE

from string_decorator import constantcase
print(constantcase("hello there"))

Output

HELLO_THERE

Using String Decorators

Example 1 -> Calculating Expression From String

from string_decorator.decorators import calculate
@calculate
def calc():
  print("The answer is:", end = " ")

print(calc("843 + sin(32)"))

Output

The answer is: 843.5514266812417

Example 2 -> Validating text based on given conditions

@validate_text
def validate():
    return

print(validate("imEternity1234@strings", length = 13, uppercase = 1, lowercase = 5, numbers = 4, special_characters=1))

Output

True

Documentation

text is a common parameter for all the functions

Name Description
randcase Changes the given text to random cases (upper or lower)
snakecase Changes the given text to snake_case
constantcase Changes the given text to CONSTANT_CASE
kebabcase Changes the given text to kebab-case
headercase Changes the given text to PascalCase
camelcase Changes the given text to camelCase
dotcase Changes the given text to dot.case
pathcase Changes the given text to path/case
swapcase Changes each upper characters to lower and vice versa
scramble_sentence Returns the sentence in random order Eg: 'Hello my friend' might change to 'my friend Hello'
sentence_reverse Reverses given sentence Eg: 'Hello world' changes to 'world Hello'
random_string Generates a random string comprising of lower cased or upper cased characters, numbers, symbols
str_encode Encodes the given text into bytes format
bytes_decode Decodes bytes back to string
num_extract Extracts numbers from the given strings
parameters:
- string: Set it to True to return numbers in a list of strings
validate_email Validates the text to check if the email format is correct
validate_text Validates the text to check if it is right according to the conditions specified
parameters:
- length: The minimum length of the text
- uppercase: The minimum number of uppercase letters in the text. Set to 'all' if all letters have to be in uppercase.
- lowercase: The minimum number of lowercase letters in the text. Set to 'all' if all letters have to be in lowercase.
- numbers: The minimum number of numbers (positive integers) in the text. Set to 'all' if all are numbers.
- special_characters: The minimum number of special characters in the text. Set to 'all' if all are special characters.
calculate Evaluates the given string
Eg: "5+2" gives 7

Metadata

Release files for string-decorator 1.0.0

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

Source distribution (sdist)

Source distribution for string-decorator 1.0.0
File Size Uploaded
string_decorator-1.0.0.tar.gz 9.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for string-decorator 1.0.0
File Interpreter ABI Platform
string_decorator-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 19.6 kB

Release files / string_decorator-1.0.0.tar.gz

Download URL string_decorator-1.0.0.tar.gz
Size 9.2 kB
Tags Source
SHA-256 checksum
How to use checksums
7e5d637431fb008b44f88d81706dc80a90931111969067373505a5338945457d
BLAKE2b-256 checksum
How to use checksums
125c4d654a1400c2a7ee67f340aefd198f6aa9bc7396fea28d85fde7d593915a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.21

Release files / string_decorator-1.0.0-py3-none-any.whl

Download URL string_decorator-1.0.0-py3-none-any.whl
Size 10.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
76a4751735b0133ccaa31922d7f300278d167e9364386beb5fc704b70381b0b2
BLAKE2b-256 checksum
How to use checksums
a26e828e11c6c0ccbf8cfcdc7217d6a7bf7fca5be81017782bf0b35a0b58581a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.21

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.5

2 release files

0.2.0

2 release files

0.1.15

2 release files

0.1.1

2 release files

0.1.0

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