umt-python 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- __init__.py +32 -0
- delete_spaces.py +19 -0
- format_string.py +30 -0
- from_base64.py +25 -0
- has_no_letters.py +22 -0
- pad_end.py +29 -0
- pad_start.py +36 -0
- random_string.py +30 -0
- random_string_initialization.py +33 -0
- reverse_string.py +17 -0
- to_base64.py +17 -0
- to_half_width.py +32 -0
- trim_characters.py +21 -0
- trim_end_characters.py +23 -0
- trim_start_characters.py +23 -0
- umt_python-0.1.0.dist-info/METADATA +131 -0
- umt_python-0.1.0.dist-info/RECORD +20 -0
- umt_python-0.1.0.dist-info/WHEEL +5 -0
- umt_python-0.1.0.dist-info/licenses/LICENSE +21 -0
- umt_python-0.1.0.dist-info/top_level.txt +15 -0
__init__.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
from .delete_spaces import delete_spaces
|
|
2
|
+
from .format_string import format_string
|
|
3
|
+
from .from_base64 import from_base64
|
|
4
|
+
from .to_base64 import to_base64
|
|
5
|
+
from .has_no_letters import has_no_letters
|
|
6
|
+
from .pad_end import pad_end
|
|
7
|
+
from .pad_start import pad_start
|
|
8
|
+
from .random_string import random_string, DEFAULT_RANDOM_STRING_CHARS
|
|
9
|
+
from .random_string_initialization import random_string_initialization
|
|
10
|
+
from .reverse_string import reverse_string
|
|
11
|
+
from .to_half_width import to_half_width
|
|
12
|
+
from .trim_characters import trim_characters
|
|
13
|
+
from .trim_end_characters import trim_end_characters
|
|
14
|
+
from .trim_start_characters import trim_start_characters
|
|
15
|
+
|
|
16
|
+
__all__ = [
|
|
17
|
+
"delete_spaces",
|
|
18
|
+
"format_string",
|
|
19
|
+
"from_base64",
|
|
20
|
+
"to_base64",
|
|
21
|
+
"has_no_letters",
|
|
22
|
+
"pad_end",
|
|
23
|
+
"pad_start",
|
|
24
|
+
"random_string",
|
|
25
|
+
"DEFAULT_RANDOM_STRING_CHARS",
|
|
26
|
+
"random_string_initialization",
|
|
27
|
+
"reverse_string",
|
|
28
|
+
"to_half_width",
|
|
29
|
+
"trim_characters",
|
|
30
|
+
"trim_end_characters",
|
|
31
|
+
"trim_start_characters",
|
|
32
|
+
]
|
delete_spaces.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import re
|
|
2
|
+
|
|
3
|
+
def delete_spaces(string_: str) -> str:
|
|
4
|
+
"""
|
|
5
|
+
Removes all whitespace characters from a string.
|
|
6
|
+
|
|
7
|
+
Args:
|
|
8
|
+
string_: Input string.
|
|
9
|
+
|
|
10
|
+
Returns:
|
|
11
|
+
String with all whitespace characters removed.
|
|
12
|
+
|
|
13
|
+
Example:
|
|
14
|
+
>>> delete_spaces("Hello World")
|
|
15
|
+
'HelloWorld'
|
|
16
|
+
>>> delete_spaces(" tab\\t space ")
|
|
17
|
+
'tabspace'
|
|
18
|
+
"""
|
|
19
|
+
return re.sub(r'\s', '', string_)
|
format_string.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import re
|
|
2
|
+
|
|
3
|
+
def format_string(template: str, *values: object) -> str:
|
|
4
|
+
"""
|
|
5
|
+
Replaces placeholders in a template string with specified values.
|
|
6
|
+
Placeholders are in the format {0}, {1}, {2}... and corresponding
|
|
7
|
+
values are passed as arguments.
|
|
8
|
+
|
|
9
|
+
Args:
|
|
10
|
+
template: Template string containing placeholders.
|
|
11
|
+
*values: Values to replace the placeholders in the template.
|
|
12
|
+
|
|
13
|
+
Returns:
|
|
14
|
+
String with placeholders replaced with values.
|
|
15
|
+
|
|
16
|
+
Example:
|
|
17
|
+
>>> format_string("Hello, {0}!", "World")
|
|
18
|
+
'Hello, World!'
|
|
19
|
+
>>> format_string("The sum of {0} and {1} is {2}.", 1, 2, 3)
|
|
20
|
+
'The sum of 1 and 2 is 3.'
|
|
21
|
+
>>> format_string("Not enough values: {0} {1}", "val1") # Mimics TS behavior
|
|
22
|
+
'Not enough values: val1 {1}'
|
|
23
|
+
"""
|
|
24
|
+
def replace(match):
|
|
25
|
+
index = int(match.group(1))
|
|
26
|
+
if index < len(values):
|
|
27
|
+
return str(values[index])
|
|
28
|
+
return match.group(0) # Return the original placeholder if value not found
|
|
29
|
+
|
|
30
|
+
return re.sub(r'{(\d+)}', replace, template)
|
from_base64.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import base64
|
|
2
|
+
|
|
3
|
+
def from_base64(base64_string: str) -> str:
|
|
4
|
+
"""
|
|
5
|
+
Converts Base64 to string.
|
|
6
|
+
|
|
7
|
+
Args:
|
|
8
|
+
base64_string: Base64 encoded string.
|
|
9
|
+
|
|
10
|
+
Returns:
|
|
11
|
+
Decoded string from Base64.
|
|
12
|
+
|
|
13
|
+
Raises:
|
|
14
|
+
ValueError: When input is not a valid Base64 string.
|
|
15
|
+
|
|
16
|
+
Example:
|
|
17
|
+
>>> from_base64("SGVsbG8gV29ybGQ=")
|
|
18
|
+
'Hello World'
|
|
19
|
+
"""
|
|
20
|
+
if not base64_string:
|
|
21
|
+
return ""
|
|
22
|
+
try:
|
|
23
|
+
return base64.b64decode(base64_string.encode('utf-8')).decode('utf-8')
|
|
24
|
+
except Exception as e:
|
|
25
|
+
raise ValueError("Invalid Base64 string") from e
|
has_no_letters.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
def has_no_letters(text: str) -> bool:
|
|
2
|
+
"""
|
|
3
|
+
Checks if the string contains no letters (contains only emojis, numbers, or special characters).
|
|
4
|
+
|
|
5
|
+
Args:
|
|
6
|
+
text: The string to check.
|
|
7
|
+
|
|
8
|
+
Returns:
|
|
9
|
+
True if the string has no letters, False otherwise.
|
|
10
|
+
|
|
11
|
+
Example:
|
|
12
|
+
>>> has_no_letters("123")
|
|
13
|
+
True
|
|
14
|
+
>>> has_no_letters("🌟123#")
|
|
15
|
+
True
|
|
16
|
+
>>> has_no_letters("abc123")
|
|
17
|
+
False
|
|
18
|
+
"""
|
|
19
|
+
for char_code in text:
|
|
20
|
+
if char_code.isalpha():
|
|
21
|
+
return False
|
|
22
|
+
return True
|
pad_end.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
def pad_end(string_: str, target_length: int, pad_string: str) -> str:
|
|
2
|
+
"""
|
|
3
|
+
Adds the specified string to the end of the string until it reaches the specified length.
|
|
4
|
+
|
|
5
|
+
Args:
|
|
6
|
+
string_: The original string to apply padding.
|
|
7
|
+
target_length: The target length after padding.
|
|
8
|
+
pad_string: The string to use for padding.
|
|
9
|
+
|
|
10
|
+
Returns:
|
|
11
|
+
The string after padding has been applied.
|
|
12
|
+
|
|
13
|
+
Example:
|
|
14
|
+
>>> pad_end("abc", 5, "0")
|
|
15
|
+
'abc00'
|
|
16
|
+
>>> pad_end("hello", 8, "123")
|
|
17
|
+
'hello123'
|
|
18
|
+
>>> pad_end("world", 3, "!") # target_length is less than string length
|
|
19
|
+
'world'
|
|
20
|
+
>>> pad_end("test", 6, "") # pad_string is empty
|
|
21
|
+
'test'
|
|
22
|
+
"""
|
|
23
|
+
if not pad_string:
|
|
24
|
+
return string_
|
|
25
|
+
result = string_
|
|
26
|
+
while len(result) < target_length:
|
|
27
|
+
needed = target_length - len(result)
|
|
28
|
+
result += pad_string[:needed]
|
|
29
|
+
return result
|
pad_start.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
def pad_start(string_: str, target_length: int, pad_string: str) -> str:
|
|
2
|
+
"""
|
|
3
|
+
Pads the start of a string with another string until the target length is reached.
|
|
4
|
+
|
|
5
|
+
Args:
|
|
6
|
+
string_: The original string to pad.
|
|
7
|
+
target_length: The target length after padding.
|
|
8
|
+
pad_string: The string to use for padding.
|
|
9
|
+
|
|
10
|
+
Returns:
|
|
11
|
+
The padded string.
|
|
12
|
+
|
|
13
|
+
Raises:
|
|
14
|
+
ValueError: If pad_string is empty.
|
|
15
|
+
|
|
16
|
+
Example:
|
|
17
|
+
>>> pad_start("123", 5, "0")
|
|
18
|
+
'00123'
|
|
19
|
+
>>> pad_start("abc", 8, "def")
|
|
20
|
+
'defdeabc'
|
|
21
|
+
>>> pad_start("world", 3, "!") # target_length is less than string length
|
|
22
|
+
'world'
|
|
23
|
+
"""
|
|
24
|
+
if not pad_string:
|
|
25
|
+
raise ValueError("pad_string cannot be empty")
|
|
26
|
+
|
|
27
|
+
if len(string_) >= target_length:
|
|
28
|
+
return string_
|
|
29
|
+
|
|
30
|
+
padding = ""
|
|
31
|
+
padding_length = target_length - len(string_)
|
|
32
|
+
|
|
33
|
+
while len(padding) < padding_length:
|
|
34
|
+
padding += pad_string
|
|
35
|
+
|
|
36
|
+
return padding[:padding_length] + string_
|
random_string.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import random
|
|
2
|
+
import string
|
|
3
|
+
|
|
4
|
+
DEFAULT_RANDOM_STRING_CHARS = string.ascii_letters + string.digits
|
|
5
|
+
|
|
6
|
+
def random_string(size: int = 8, char_pool: str = DEFAULT_RANDOM_STRING_CHARS) -> str:
|
|
7
|
+
"""
|
|
8
|
+
Generates a random string.
|
|
9
|
+
|
|
10
|
+
Args:
|
|
11
|
+
size: Length of the random string. Defaults to 8.
|
|
12
|
+
char_pool: String of characters to use for generating random string.
|
|
13
|
+
Defaults to alphanumeric characters.
|
|
14
|
+
|
|
15
|
+
Returns:
|
|
16
|
+
Random string.
|
|
17
|
+
|
|
18
|
+
Example:
|
|
19
|
+
>>> len(random_string()) == 8
|
|
20
|
+
True
|
|
21
|
+
>>> len(random_string(10)) == 10
|
|
22
|
+
True
|
|
23
|
+
>>> all(c in 'abc' for c in random_string(5, 'abc'))
|
|
24
|
+
True
|
|
25
|
+
"""
|
|
26
|
+
if size == 0:
|
|
27
|
+
return ""
|
|
28
|
+
# When char_pool is empty and size > 0, random.choice will raise IndexError.
|
|
29
|
+
# This is the expected behavior for the tests.
|
|
30
|
+
return ''.join(random.choice(char_pool) for _ in range(size))
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
from typing import Callable
|
|
2
|
+
from .random_string import random_string, DEFAULT_RANDOM_STRING_CHARS
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def random_string_initialization(
|
|
6
|
+
char_pool: str = DEFAULT_RANDOM_STRING_CHARS,
|
|
7
|
+
) -> Callable[[int], str]:
|
|
8
|
+
"""
|
|
9
|
+
Initializes a function that generates random strings with a specific character pool.
|
|
10
|
+
|
|
11
|
+
Args:
|
|
12
|
+
char_pool: String of characters to use for generating random strings.
|
|
13
|
+
Defaults to alphanumeric characters.
|
|
14
|
+
|
|
15
|
+
Returns:
|
|
16
|
+
A function that generates random strings (size: int) -> str.
|
|
17
|
+
|
|
18
|
+
Example:
|
|
19
|
+
>>> from .random_string import DEFAULT_RANDOM_STRING_CHARS # For doctest
|
|
20
|
+
>>> custom_random = random_string_initialization("xyz")
|
|
21
|
+
>>> r_string = custom_random(3)
|
|
22
|
+
>>> len(r_string) == 3
|
|
23
|
+
True
|
|
24
|
+
>>> all(c in "xyz" for c in r_string)
|
|
25
|
+
True
|
|
26
|
+
>>> default_pool_func = random_string_initialization()
|
|
27
|
+
>>> another_string = default_pool_func(5)
|
|
28
|
+
>>> len(another_string) == 5
|
|
29
|
+
True
|
|
30
|
+
>>> all(c in DEFAULT_RANDOM_STRING_CHARS for c in another_string)
|
|
31
|
+
True
|
|
32
|
+
"""
|
|
33
|
+
return lambda size: random_string(size, char_pool)
|
reverse_string.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
def reverse_string(char: str) -> str:
|
|
2
|
+
"""
|
|
3
|
+
Reverses a string.
|
|
4
|
+
|
|
5
|
+
Args:
|
|
6
|
+
char: String to reverse.
|
|
7
|
+
|
|
8
|
+
Returns:
|
|
9
|
+
Reversed string.
|
|
10
|
+
|
|
11
|
+
Example:
|
|
12
|
+
>>> reverse_string("Hello")
|
|
13
|
+
'olleH'
|
|
14
|
+
>>> reverse_string("madam")
|
|
15
|
+
'madam'
|
|
16
|
+
"""
|
|
17
|
+
return char[::-1]
|
to_base64.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import base64
|
|
2
|
+
|
|
3
|
+
def to_base64(char: str) -> str:
|
|
4
|
+
"""
|
|
5
|
+
Convert string to Base64.
|
|
6
|
+
|
|
7
|
+
Args:
|
|
8
|
+
char: String to convert to Base64.
|
|
9
|
+
|
|
10
|
+
Returns:
|
|
11
|
+
Base64 encoded string.
|
|
12
|
+
|
|
13
|
+
Example:
|
|
14
|
+
>>> to_base64("Hello World")
|
|
15
|
+
'SGVsbG8gV29ybGQ='
|
|
16
|
+
"""
|
|
17
|
+
return base64.b64encode(char.encode('utf-8')).decode('utf-8')
|
to_half_width.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
def to_half_width(string_: str) -> str:
|
|
2
|
+
"""
|
|
3
|
+
Convert full-width characters (zenkaku) to half-width characters (hankaku).
|
|
4
|
+
This implementation specifically targets full-width alphanumeric characters and some symbols.
|
|
5
|
+
|
|
6
|
+
Args:
|
|
7
|
+
string_: String to convert.
|
|
8
|
+
|
|
9
|
+
Returns:
|
|
10
|
+
Converted string.
|
|
11
|
+
|
|
12
|
+
Example:
|
|
13
|
+
>>> to_half_width("Hello World 123")
|
|
14
|
+
'Hello World 123'
|
|
15
|
+
>>> to_half_width("ABCdef")
|
|
16
|
+
'ABCdef'
|
|
17
|
+
>>> to_half_width("!"#$%&'()*+,-./") # Full-width symbols
|
|
18
|
+
"!\"#$%&'()*+,-./"
|
|
19
|
+
>>> to_half_width(" ") # Full-width space
|
|
20
|
+
' '
|
|
21
|
+
"""
|
|
22
|
+
# Mapping for full-width to half-width for ASCII range based on Unicode block
|
|
23
|
+
# Full-width exclamation mark to tilde: U+FF01 to U+FF5E
|
|
24
|
+
# Half-width corresponding characters: U+0021 to U+007E
|
|
25
|
+
# The difference is 0xFEE0 (65248)
|
|
26
|
+
# Full-width space U+3000 -> Half-width space U+0020
|
|
27
|
+
translation_table = {}
|
|
28
|
+
for i in range(0xFF01, 0xFF5F): # Covers full-width '!' to '~'
|
|
29
|
+
translation_table[i] = i - 0xFEE0
|
|
30
|
+
translation_table[0x3000] = 0x0020 # Full-width space to half-width space
|
|
31
|
+
|
|
32
|
+
return string_.translate(translation_table)
|
trim_characters.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
from .trim_start_characters import trim_start_characters
|
|
2
|
+
from .trim_end_characters import trim_end_characters
|
|
3
|
+
|
|
4
|
+
def trim_characters(string_: str, chars: str) -> str:
|
|
5
|
+
"""
|
|
6
|
+
Removes specified characters from both ends of a string.
|
|
7
|
+
|
|
8
|
+
Args:
|
|
9
|
+
string_: The string to trim.
|
|
10
|
+
chars: The set of characters to remove.
|
|
11
|
+
|
|
12
|
+
Returns:
|
|
13
|
+
A new string with specified characters removed from both ends.
|
|
14
|
+
|
|
15
|
+
Example:
|
|
16
|
+
>>> trim_characters("-.-hello-.-", "-.")
|
|
17
|
+
'hello'
|
|
18
|
+
>>> trim_characters("123abc123", "123")
|
|
19
|
+
'abc'
|
|
20
|
+
"""
|
|
21
|
+
return trim_end_characters(trim_start_characters(string_, chars), chars)
|
trim_end_characters.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
def trim_end_characters(string_: str, chars: str) -> str:
|
|
2
|
+
"""
|
|
3
|
+
Removes specified characters from the end of a string.
|
|
4
|
+
|
|
5
|
+
Args:
|
|
6
|
+
string_: The input string to trim.
|
|
7
|
+
chars: Characters to remove from the end.
|
|
8
|
+
|
|
9
|
+
Returns:
|
|
10
|
+
A new string with specified characters removed from the end.
|
|
11
|
+
|
|
12
|
+
Example:
|
|
13
|
+
>>> trim_end_characters("hello!!!", "!")
|
|
14
|
+
'hello'
|
|
15
|
+
>>> trim_end_characters("123---", "-")
|
|
16
|
+
'123'
|
|
17
|
+
>>> trim_end_characters("abc123", "xyz")
|
|
18
|
+
'abc123'
|
|
19
|
+
"""
|
|
20
|
+
end_index = len(string_)
|
|
21
|
+
while end_index > 0 and string_[end_index - 1] in chars:
|
|
22
|
+
end_index -= 1
|
|
23
|
+
return string_[:end_index]
|
trim_start_characters.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
def trim_start_characters(string_: str, chars: str) -> str:
|
|
2
|
+
"""
|
|
3
|
+
Removes specified characters from the start of a string.
|
|
4
|
+
|
|
5
|
+
Args:
|
|
6
|
+
string_: The input string to trim.
|
|
7
|
+
chars: Characters to remove from the start.
|
|
8
|
+
|
|
9
|
+
Returns:
|
|
10
|
+
A new string with specified characters removed from the start.
|
|
11
|
+
|
|
12
|
+
Example:
|
|
13
|
+
>>> trim_start_characters("!!!hello", "!")
|
|
14
|
+
'hello'
|
|
15
|
+
>>> trim_start_characters("---123", "-")
|
|
16
|
+
'123'
|
|
17
|
+
>>> trim_start_characters("abc123", "xyz")
|
|
18
|
+
'abc123'
|
|
19
|
+
"""
|
|
20
|
+
start_index = 0
|
|
21
|
+
while start_index < len(string_) and string_[start_index] in chars:
|
|
22
|
+
start_index += 1
|
|
23
|
+
return string_[start_index:]
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: umt_python
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A collection of useful utility functions for various tasks in Python, focusing on string manipulation and formatting.
|
|
5
|
+
Author-email: riya-amemiya <riyaamemiya@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Bug Tracker, https://github.com/riya-amemiya/UMT/issues
|
|
8
|
+
Project-URL: Homepage, https://github.com/riya-amemiya/UMT
|
|
9
|
+
Project-URL: Repository, https://github.com/riya-amemiya/UMT
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
17
|
+
Classifier: Topic :: Utilities
|
|
18
|
+
Requires-Python: >=3.9
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Dynamic: license-file
|
|
22
|
+
|
|
23
|
+
# UMT Python Package
|
|
24
|
+
|
|
25
|
+
UMT Python Package is a collection of useful utility functions for various tasks in Python, focusing on string manipulation and formatting.
|
|
26
|
+
|
|
27
|
+
## Install
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
pip install umt-python
|
|
31
|
+
|
|
32
|
+
# or using uv
|
|
33
|
+
uv add umt-python
|
|
34
|
+
|
|
35
|
+
# or using poetry
|
|
36
|
+
poetry add umt-python
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Quick Start
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
from umt_python import random_string, format_string, to_base64
|
|
43
|
+
|
|
44
|
+
# Generate a random string
|
|
45
|
+
random_str = random_string(10)
|
|
46
|
+
print(random_str) # e.g., "aBcD3fGh1j"
|
|
47
|
+
|
|
48
|
+
# Format a string with placeholders
|
|
49
|
+
formatted = format_string("Hello, {0}! Today is {1}.", "World", "Monday")
|
|
50
|
+
print(formatted) # "Hello, World! Today is Monday."
|
|
51
|
+
|
|
52
|
+
# Encode string to Base64
|
|
53
|
+
encoded = to_base64("Hello World")
|
|
54
|
+
print(encoded) # "SGVsbG8gV29ybGQ="
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Function List
|
|
58
|
+
|
|
59
|
+
### String Manipulation Functions
|
|
60
|
+
|
|
61
|
+
| Function | Type | Description | Example |
|
|
62
|
+
|----------|------|-------------|---------|
|
|
63
|
+
| `delete_spaces` | `(string_: str) -> str` | Remove all whitespace characters from a string | `delete_spaces("Hello World") # "HelloWorld"` |
|
|
64
|
+
| `format_string` | `(template: str, *values: object) -> str` | Replace placeholders {0}, {1}, etc. in a template string | `format_string("Sum of {0} and {1} is {2}", 1, 2, 3) # "Sum of 1 and 2 is 3"` |
|
|
65
|
+
| `reverse_string` | `(char: str) -> str` | Reverse a string | `reverse_string("Hello") # "olleH"` |
|
|
66
|
+
| `to_half_width` | `(string_: str) -> str` | Convert full-width characters to half-width | `to_half_width("Hello 123") # "Hello 123"` |
|
|
67
|
+
|
|
68
|
+
### Base64 Encoding Functions
|
|
69
|
+
|
|
70
|
+
| Function | Type | Description | Example |
|
|
71
|
+
|----------|------|-------------|---------|
|
|
72
|
+
| `to_base64` | `(char: str) -> str` | Encode a string to Base64 | `to_base64("Hello") # "SGVsbG8="` |
|
|
73
|
+
| `from_base64` | `(base64_string: str) -> str` | Decode a Base64 string | `from_base64("SGVsbG8=") # "Hello"` |
|
|
74
|
+
|
|
75
|
+
### String Padding Functions
|
|
76
|
+
|
|
77
|
+
| Function | Type | Description | Example |
|
|
78
|
+
|----------|------|-------------|---------|
|
|
79
|
+
| `pad_start` | `(string_: str, target_length: int, pad_string: str) -> str` | Pad string from the start to reach target length | `pad_start("123", 5, "0") # "00123"` |
|
|
80
|
+
| `pad_end` | `(string_: str, target_length: int, pad_string: str) -> str` | Pad string from the end to reach target length | `pad_end("abc", 5, "0") # "abc00"` |
|
|
81
|
+
|
|
82
|
+
### String Trimming Functions
|
|
83
|
+
|
|
84
|
+
| Function | Type | Description | Example |
|
|
85
|
+
|----------|------|-------------|---------|
|
|
86
|
+
| `trim_characters` | `(string_: str, chars: str) -> str` | Remove specified characters from both ends | `trim_characters("-.-hello-.-", "-.") # "hello"` |
|
|
87
|
+
| `trim_start_characters` | `(string_: str, chars: str) -> str` | Remove specified characters from the start | `trim_start_characters("!!!hello", "!") # "hello"` |
|
|
88
|
+
| `trim_end_characters` | `(string_: str, chars: str) -> str` | Remove specified characters from the end | `trim_end_characters("hello!!!", "!") # "hello"` |
|
|
89
|
+
|
|
90
|
+
### Random String Generation
|
|
91
|
+
|
|
92
|
+
| Function | Type | Description | Example |
|
|
93
|
+
|----------|------|-------------|---------|
|
|
94
|
+
| `random_string` | `(size: int = 8, char_pool: str = DEFAULT_RANDOM_STRING_CHARS) -> str` | Generate a random string of specified length | `random_string(10) # "aBcD3fGh1j"` |
|
|
95
|
+
| `random_string_initialization` | `(char_pool: str = DEFAULT_RANDOM_STRING_CHARS) -> Callable[[int], str]` | Create a custom random string generator with specific character pool | `custom_random = random_string_initialization("xyz")` → `custom_random(3) # "xyx"` |
|
|
96
|
+
|
|
97
|
+
### String Validation Functions
|
|
98
|
+
|
|
99
|
+
| Function | Type | Description | Example |
|
|
100
|
+
|----------|------|-------------|---------|
|
|
101
|
+
| `has_no_letters` | `(text: str) -> bool` | Check if string contains no letters (only numbers, emojis, special chars) | `has_no_letters("123!@#") # True` / `has_no_letters("abc123") # False` |
|
|
102
|
+
|
|
103
|
+
## Constants
|
|
104
|
+
|
|
105
|
+
- `DEFAULT_RANDOM_STRING_CHARS`: Default character pool for random string generation (ASCII letters + digits)
|
|
106
|
+
|
|
107
|
+
## Requirements
|
|
108
|
+
|
|
109
|
+
- Python 3.9 or higher
|
|
110
|
+
|
|
111
|
+
## Development
|
|
112
|
+
|
|
113
|
+
This project uses `uv` for dependency management.
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
# Install dependencies
|
|
117
|
+
uv sync
|
|
118
|
+
|
|
119
|
+
# Run tests
|
|
120
|
+
uv run pytest
|
|
121
|
+
|
|
122
|
+
# Format code
|
|
123
|
+
uv run ruff format
|
|
124
|
+
|
|
125
|
+
# Lint code
|
|
126
|
+
uv run ruff check
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## License
|
|
130
|
+
|
|
131
|
+
MIT License
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
__init__.py,sha256=VZz3TwQJokyFAjRLAkeQzTrmLIaax-uyc6sj_ZKHV4g,998
|
|
2
|
+
delete_spaces.py,sha256=-mSYxzSGr-7-q8cwSw2vGdT-nqFCTE91bQMXaxASWkg,409
|
|
3
|
+
format_string.py,sha256=xzL1GWtm6ScWihwpSdVvLAFQxl9NRd6iKM6xFpH7ODs,1047
|
|
4
|
+
from_base64.py,sha256=vldBQe_8Z-dsuDHYNX9TXxW-rj8NbeQmxhwcwPZ4k6M,583
|
|
5
|
+
has_no_letters.py,sha256=U8hZMbwYMJzn07rljZiAIhndaUqhgZWKCocSwVmnZ9w,540
|
|
6
|
+
pad_end.py,sha256=CIpIQeR3O0RmVFv_VBftzk7sOLSNtIgBe8ZH05jPkeA,917
|
|
7
|
+
pad_start.py,sha256=0AosSpYf9aOPnTPu-ET5tioxhdK-a983iX1uMmX-QGE,991
|
|
8
|
+
random_string.py,sha256=kpV5ZgjDztFwkeKpV9zgybXfQ8YYw-3ZFNyM06we61A,897
|
|
9
|
+
random_string_initialization.py,sha256=sRIHuTFTQJXZCM4Y24nN4SuTd26M1tN_R01ZMAXTA4A,1151
|
|
10
|
+
reverse_string.py,sha256=zd5BrBeYy1PaglWnJMSDbZ7an2Ok2II4rORayZ2sGz4,300
|
|
11
|
+
to_base64.py,sha256=RDTlzbjHxnL4elO24k7x6XbZ-SFzguJPwW1xD_flLIw,337
|
|
12
|
+
to_half_width.py,sha256=xw1FXcbyqCFKwfofj9FT-hHlzGdl8fWuGyrVqlfNDb4,1254
|
|
13
|
+
trim_characters.py,sha256=cuNhwE6yyKG0d5ogouOufur0O24BJ22uAA_5RRjJXK4,641
|
|
14
|
+
trim_end_characters.py,sha256=Cnr-tyjqoKB-hqIDV5PI0x1p2CleIyOGcIZ62hkwLMI,670
|
|
15
|
+
trim_start_characters.py,sha256=TcGa9T3ArIIxguvYf8I2EJ1AUUN3AzYk1Y-0YYprBk8,690
|
|
16
|
+
umt_python-0.1.0.dist-info/licenses/LICENSE,sha256=1sfH4YyDPcU1Flbmf9AwxZHlsxt0bMsoU7TpSvVPaTo,1069
|
|
17
|
+
umt_python-0.1.0.dist-info/METADATA,sha256=ro255Am3UjSxtNPLY6NUGrvcVAFpbS53pIlCDkTldys,5111
|
|
18
|
+
umt_python-0.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
19
|
+
umt_python-0.1.0.dist-info/top_level.txt,sha256=E6bnKdLKlF_McWeJ2DcD2ApFGe3MEWvEAssItHZf_Kw,222
|
|
20
|
+
umt_python-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 riya-amemiya
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
__init__
|
|
2
|
+
delete_spaces
|
|
3
|
+
format_string
|
|
4
|
+
from_base64
|
|
5
|
+
has_no_letters
|
|
6
|
+
pad_end
|
|
7
|
+
pad_start
|
|
8
|
+
random_string
|
|
9
|
+
random_string_initialization
|
|
10
|
+
reverse_string
|
|
11
|
+
to_base64
|
|
12
|
+
to_half_width
|
|
13
|
+
trim_characters
|
|
14
|
+
trim_end_characters
|
|
15
|
+
trim_start_characters
|