ingabotool 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.
ingabotool/__init__.py
ADDED
ingabotool/text_utils.py
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import re
|
|
2
|
+
import uuid
|
|
3
|
+
|
|
4
|
+
def slugify(text: str) -> str:
|
|
5
|
+
"""
|
|
6
|
+
Convert text to lowercase, remove unnecessary punctuation,
|
|
7
|
+
and replace spaces and repeated separators with a single hyphen.
|
|
8
|
+
"""
|
|
9
|
+
if not isinstance(text, str):
|
|
10
|
+
raise TypeError("Input must be a string")
|
|
11
|
+
|
|
12
|
+
text = text.lower()
|
|
13
|
+
# Remove punctuation except spaces and hyphens
|
|
14
|
+
text = re.sub(r'[^\w\s-]', '', text)
|
|
15
|
+
# Replace spaces and repeated hyphens with a single hyphen
|
|
16
|
+
text = re.sub(r'[\s-]+', '-', text)
|
|
17
|
+
# Strip leading/trailing hyphens
|
|
18
|
+
return text.strip('-')
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def truncate(text: str, max_length: int, suffix: str = "...") -> str:
|
|
22
|
+
"""
|
|
23
|
+
Return the original text if it fits within max_length.
|
|
24
|
+
Otherwise truncate it and append the suffix.
|
|
25
|
+
The final result will not exceed max_length.
|
|
26
|
+
"""
|
|
27
|
+
if not isinstance(text, str):
|
|
28
|
+
raise TypeError("Text must be a string")
|
|
29
|
+
if not isinstance(max_length, int) or max_length < 0:
|
|
30
|
+
raise ValueError("max_length must be a non-negative integer")
|
|
31
|
+
if len(suffix) > max_length:
|
|
32
|
+
raise ValueError("suffix length cannot be greater than max_length")
|
|
33
|
+
|
|
34
|
+
if len(text) <= max_length:
|
|
35
|
+
return text
|
|
36
|
+
|
|
37
|
+
return text[:max_length - len(suffix)] + suffix
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def is_valid_email(email: str) -> bool:
|
|
41
|
+
"""
|
|
42
|
+
Perform a simple practical email-format validation.
|
|
43
|
+
"""
|
|
44
|
+
if not isinstance(email, str):
|
|
45
|
+
return False
|
|
46
|
+
# Simple regex for practical validation: something@something.something
|
|
47
|
+
pattern = r'^[^@\s]+@[^@\s]+\.[^@\s]+$'
|
|
48
|
+
return bool(re.match(pattern, email))
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def mask_email(email: str) -> str:
|
|
52
|
+
"""
|
|
53
|
+
Hide part of the username while keeping the domain visible.
|
|
54
|
+
"""
|
|
55
|
+
if not isinstance(email, str) or '@' not in email:
|
|
56
|
+
return email
|
|
57
|
+
|
|
58
|
+
parts = email.split('@')
|
|
59
|
+
if len(parts) != 2:
|
|
60
|
+
return email
|
|
61
|
+
|
|
62
|
+
username, domain = parts
|
|
63
|
+
|
|
64
|
+
# Handle empty username
|
|
65
|
+
if not username:
|
|
66
|
+
return f"@{domain}"
|
|
67
|
+
|
|
68
|
+
if len(username) > 1:
|
|
69
|
+
masked_username = username[0] + "*" * (len(username) - 1)
|
|
70
|
+
else:
|
|
71
|
+
masked_username = "*" * len(username)
|
|
72
|
+
|
|
73
|
+
return f"{masked_username}@{domain}"
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def generate_id(prefix: str = "id") -> str:
|
|
77
|
+
"""
|
|
78
|
+
Generate a short unique identifier using Python's standard library.
|
|
79
|
+
"""
|
|
80
|
+
if not isinstance(prefix, str):
|
|
81
|
+
raise TypeError("Prefix must be a string")
|
|
82
|
+
|
|
83
|
+
unique_part = uuid.uuid4().hex[:8]
|
|
84
|
+
if prefix:
|
|
85
|
+
return f"{prefix}_{unique_part}"
|
|
86
|
+
return unique_part
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ingabotool
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A small, professional Python package for developer utilities.
|
|
5
|
+
Author: Developer
|
|
6
|
+
License: MIT License
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.8
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Dynamic: license-file
|
|
14
|
+
|
|
15
|
+
# ingabotool
|
|
16
|
+
|
|
17
|
+
A small, professional Python package that provides a set of reusable developer utilities for common text manipulation and validation tasks.
|
|
18
|
+
|
|
19
|
+
## Features
|
|
20
|
+
|
|
21
|
+
- **`slugify`**: Convert text into URL-friendly strings.
|
|
22
|
+
- **`truncate`**: Safely truncate strings and append a suffix if they exceed a maximum length.
|
|
23
|
+
- **`is_valid_email`**: Perform practical validation of email formats.
|
|
24
|
+
- **`mask_email`**: Obfuscate email usernames while preserving the domain for privacy.
|
|
25
|
+
- **`generate_id`**: Generate short, unique alphanumeric identifiers with an optional prefix.
|
|
26
|
+
|
|
27
|
+
## Installation for Local Development
|
|
28
|
+
|
|
29
|
+
You can install this package locally in editable mode. Navigate to the root directory of the package (where `pyproject.toml` is located) and run:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pip install -e .
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
To build the package distribution files:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
python -m build
|
|
39
|
+
```
|
|
40
|
+
*(If `build` is not installed, install it via: `pip install build`)*
|
|
41
|
+
|
|
42
|
+
To run the test suite:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
python -m unittest discover -s tests
|
|
46
|
+
```
|
|
47
|
+
*Note: Make sure your `PYTHONPATH` includes the `src` directory if not installing first, or run from the root directory.*
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
## Usage Examples
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
from ingabotool import slugify, truncate, is_valid_email, mask_email, generate_id
|
|
54
|
+
|
|
55
|
+
# 1. slugify
|
|
56
|
+
print(slugify("Hello, World!"))
|
|
57
|
+
# Output: "hello-world"
|
|
58
|
+
|
|
59
|
+
# 2. truncate
|
|
60
|
+
print(truncate("This is a long sentence", 10))
|
|
61
|
+
# Output: "This is..."
|
|
62
|
+
|
|
63
|
+
# 3. is_valid_email
|
|
64
|
+
print(is_valid_email("user@example.com"))
|
|
65
|
+
# Output: True
|
|
66
|
+
|
|
67
|
+
# 4. mask_email
|
|
68
|
+
print(mask_email("john.doe@gmail.com"))
|
|
69
|
+
# Output: "j*******@gmail.com"
|
|
70
|
+
|
|
71
|
+
# 5. generate_id
|
|
72
|
+
print(generate_id("user"))
|
|
73
|
+
# Output: "user_a8f31c4b" (random)
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Available Functions
|
|
77
|
+
|
|
78
|
+
- `slugify(text: str) -> str`
|
|
79
|
+
- `truncate(text: str, max_length: int, suffix: str = "...") -> str`
|
|
80
|
+
- `is_valid_email(email: str) -> bool`
|
|
81
|
+
- `mask_email(email: str) -> str`
|
|
82
|
+
- `generate_id(prefix: str = "id") -> str`
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
ingabotool/__init__.py,sha256=BEB-0YuH5gULQvwSF_LN9aQJaFNdO9OqYvKHEioLDys,191
|
|
2
|
+
ingabotool/text_utils.py,sha256=ty2fW9Hn9eVELDu6t9DnFrf5Y233niOoo1jVj7eiaGQ,2617
|
|
3
|
+
ingabotool-0.1.0.dist-info/licenses/LICENSE,sha256=sUW-CyNFPxU9jXLoXhI9kJwgi4Yy4oAmTuANa6J7Vfw,1087
|
|
4
|
+
ingabotool-0.1.0.dist-info/METADATA,sha256=-iPU8jDg2vMS7TqbzVEM8eIJ_Hsw-_2qyMWSVAXXAak,2382
|
|
5
|
+
ingabotool-0.1.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
6
|
+
ingabotool-0.1.0.dist-info/top_level.txt,sha256=BxQGSRqNmNBPl8pAYP5pPEGmdjKUfuLjf1bSRzHjz-E,11
|
|
7
|
+
ingabotool-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Developer
|
|
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 @@
|
|
|
1
|
+
ingabotool
|