vbot-utils 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.
vbot_utils/__init__.py ADDED
@@ -0,0 +1,31 @@
1
+ """vbot-utils: a small, dependency-free utility library for VBot.
2
+
3
+ Provides practical helpers for strings, dates and validation that are used
4
+ across VBot's Python tooling.
5
+
6
+ Example:
7
+ >>> from vbot_utils import slugify, is_email, truncate
8
+ >>> slugify("Hello, World!")
9
+ 'hello-world'
10
+ """
11
+
12
+ from .dates import format_date, parse_date, relative_time
13
+ from .strings import slugify, truncate, is_blank, to_kebab, to_snake
14
+ from .validation import is_email, is_url, is_ip, is_uuid
15
+
16
+ __all__ = [
17
+ "slugify",
18
+ "truncate",
19
+ "is_blank",
20
+ "to_kebab",
21
+ "to_snake",
22
+ "format_date",
23
+ "parse_date",
24
+ "relative_time",
25
+ "is_email",
26
+ "is_url",
27
+ "is_ip",
28
+ "is_uuid",
29
+ ]
30
+
31
+ __version__ = "0.1.0"
vbot_utils/dates.py ADDED
@@ -0,0 +1,81 @@
1
+ """Date & time helpers for vbot-utils."""
2
+
3
+ import re
4
+ from datetime import date, datetime, timedelta
5
+
6
+ __all__ = ["format_date", "parse_date", "relative_time"]
7
+
8
+ _ISO_RE = re.compile(r"^\d{4}-\d{2}-\d{2}([T ]\d{2}:\d{2}(:\d{2})?)?$")
9
+
10
+
11
+ def parse_date(value) -> datetime:
12
+ """Parse ``value`` into a :class:`datetime.datetime`.
13
+
14
+ Accepts ISO 8601 strings, ``datetime``, ``date`` and timestamps.
15
+
16
+ Args:
17
+ value: The value to parse.
18
+
19
+ Returns:
20
+ A ``datetime`` instance.
21
+
22
+ Raises:
23
+ ValueError: If ``value`` cannot be parsed.
24
+ """
25
+ if isinstance(value, datetime):
26
+ return value
27
+ if isinstance(value, date):
28
+ return datetime(value.year, value.month, value.day)
29
+ if isinstance(value, (int, float)):
30
+ return datetime.fromtimestamp(value)
31
+ if isinstance(value, str):
32
+ value = value.strip()
33
+ if _ISO_RE.match(value):
34
+ if "T" in value or " " in value:
35
+ return datetime.fromisoformat(value.replace(" ", "T")[:19])
36
+ return datetime.strptime(value[:10], "%Y-%m-%d")
37
+ raise ValueError(f"Unsupported date format: {value!r}")
38
+ raise TypeError(f"Cannot parse date from type {type(value).__name__}")
39
+
40
+
41
+ def format_date(value, fmt: str = "%Y-%m-%d") -> str:
42
+ """Format ``value`` using ``fmt``.
43
+
44
+ Args:
45
+ value: Date-like value.
46
+ fmt: ``strftime`` format string (default ``%Y-%m-%d``).
47
+
48
+ Returns:
49
+ The formatted string.
50
+ """
51
+ return parse_date(value).strftime(fmt)
52
+
53
+
54
+ def relative_time(value, now=None) -> str:
55
+ """Return a human-friendly relative time string.
56
+
57
+ Args:
58
+ value: Date-like value.
59
+ now: Optional reference ``datetime`` (defaults to now).
60
+
61
+ Returns:
62
+ A short relative description such as ``"3 hours ago"``.
63
+ """
64
+ dt = parse_date(value)
65
+ now = now or datetime.now()
66
+ delta = now - dt
67
+ seconds = int(delta.total_seconds())
68
+
69
+ if seconds < 0:
70
+ return "in the future"
71
+ if seconds < 60:
72
+ return "just now"
73
+ if seconds < 3600:
74
+ return f"{seconds // 60} minutes ago"
75
+ if seconds < 86400:
76
+ return f"{seconds // 3600} hours ago"
77
+ if seconds < 2592000:
78
+ return f"{seconds // 86400} days ago"
79
+ if seconds < 31536000:
80
+ return f"{seconds // 2592000} months ago"
81
+ return f"{seconds // 31536000} years ago"
vbot_utils/py.typed ADDED
@@ -0,0 +1 @@
1
+ # Marker file for PEP 561 type information.
vbot_utils/strings.py ADDED
@@ -0,0 +1,65 @@
1
+ """String helpers for vbot-utils."""
2
+
3
+ import re
4
+ import unicodedata
5
+
6
+ __all__ = ["slugify", "truncate", "is_blank", "to_kebab", "to_snake"]
7
+
8
+ _SLUG_RE = re.compile(r"[^a-z0-9]+")
9
+ _SNAKE_RE = re.compile(r"(?<!^)(?=[A-Z])")
10
+
11
+
12
+ def slugify(text: str, separator: str = "-") -> str:
13
+ """Convert text into a URL/identifier friendly slug.
14
+
15
+ Args:
16
+ text: Input string.
17
+ separator: Separator used between words (default ``-``).
18
+
19
+ Returns:
20
+ Lowercased, ASCII-normalised slug.
21
+
22
+ Example:
23
+ >>> slugify(" Hello, World! ")
24
+ 'hello-world'
25
+ """
26
+ text = unicodedata.normalize("NFKD", str(text))
27
+ text = text.encode("ascii", "ignore").decode("ascii")
28
+ text = text.lower()
29
+ parts = [p for p in _SLUG_RE.split(text) if p]
30
+ return separator.join(parts)
31
+
32
+
33
+ def truncate(text: str, length: int = 80, suffix: str = "...") -> str:
34
+ """Truncate ``text`` to at most ``length`` characters.
35
+
36
+ Args:
37
+ text: Input string.
38
+ length: Maximum length (default 80).
39
+ suffix: Appended when truncation happens (default ``...``).
40
+
41
+ Returns:
42
+ The truncated string.
43
+ """
44
+ if length <= 0:
45
+ return suffix
46
+ if len(text) <= length:
47
+ return text
48
+ return text[: max(0, length - len(suffix))] + suffix
49
+
50
+
51
+ def is_blank(text) -> bool:
52
+ """Return ``True`` if ``text`` is ``None`` or only whitespace."""
53
+ return text is None or str(text).strip() == ""
54
+
55
+
56
+ def to_kebab(text: str) -> str:
57
+ """Convert CamelCase, spaced or underscored text to kebab-case."""
58
+ text = _SNAKE_RE.sub("-", str(text)).replace("_", "-").replace(" ", "-")
59
+ return "-".join(p for p in text.lower().split("-") if p)
60
+
61
+
62
+ def to_snake(text: str) -> str:
63
+ """Convert CamelCase, spaced or dashed text to snake_case."""
64
+ text = _SNAKE_RE.sub("_", str(text)).replace("-", "_").replace(" ", "_")
65
+ return "_".join(p for p in text.lower().split("_") if p)
@@ -0,0 +1,45 @@
1
+ """Validation helpers for vbot-utils."""
2
+
3
+ import re
4
+ import uuid as _uuid
5
+
6
+ __all__ = ["is_email", "is_url", "is_ip", "is_uuid"]
7
+
8
+ _EMAIL_RE = re.compile(r"^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$")
9
+ _URL_RE = re.compile(r"^https?://[^\s/$.?#].[^\s]*$", re.IGNORECASE)
10
+ _IPV4_RE = re.compile(r"^(\d{1,3}\.){3}\d{1,3}$")
11
+
12
+
13
+ def is_email(value) -> bool:
14
+ """Return ``True`` if ``value`` looks like an email address."""
15
+ if not isinstance(value, str):
16
+ return False
17
+ return bool(_EMAIL_RE.match(value.strip()))
18
+
19
+
20
+ def is_url(value) -> bool:
21
+ """Return ``True`` if ``value`` looks like an http(s) URL."""
22
+ if not isinstance(value, str):
23
+ return False
24
+ return bool(_URL_RE.match(value.strip()))
25
+
26
+
27
+ def is_ip(value) -> bool:
28
+ """Return ``True`` if ``value`` is a valid IPv4 address."""
29
+ if not isinstance(value, str):
30
+ return False
31
+ parts = value.split(".")
32
+ if len(parts) != 4:
33
+ return False
34
+ return all(p.isdigit() and 0 <= int(p) <= 255 for p in parts)
35
+
36
+
37
+ def is_uuid(value) -> bool:
38
+ """Return ``True`` if ``value`` is a valid UUID."""
39
+ if not isinstance(value, str):
40
+ return False
41
+ try:
42
+ _uuid.UUID(value)
43
+ return True
44
+ except (ValueError, AttributeError):
45
+ return False
@@ -0,0 +1,92 @@
1
+ Metadata-Version: 2.4
2
+ Name: vbot-utils
3
+ Version: 0.1.0
4
+ Summary: VBot utility library: string, date and validation helpers.
5
+ Author-email: VBot <vexify@yeah.net>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/vexify-build/vbot-utils
8
+ Project-URL: Repository, https://github.com/vexify-build/vbot-utils
9
+ Keywords: vbot,utils,helpers,strings,dates,validation
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.8
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
21
+ Requires-Python: >=3.8
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Dynamic: license-file
25
+
26
+ # vbot-utils
27
+
28
+ > A small, dependency-free utility library for **VBot** 🐍
29
+
30
+ `vbot-utils` provides practical, well-tested helpers for **strings**, **dates** and **validation** — the everyday building blocks used across VBot's Python tooling. Zero runtime dependencies, Python 3.8+.
31
+
32
+ ## Install
33
+
34
+ ```bash
35
+ pip install vbot-utils
36
+ ```
37
+
38
+ ## Quick start
39
+
40
+ ```python
41
+ from vbot_utils import slugify, truncate, is_email, relative_time
42
+
43
+ slugify("Hello, World!") # 'hello-world'
44
+ truncate("a very long sentence", 10) # 'a very ...'
45
+ is_email("me@example.com") # True
46
+ relative_time("2026-11-25") # '3 hours ago' (example)
47
+ ```
48
+
49
+ ## Features
50
+
51
+ - **Strings** — `slugify`, `truncate`, `is_blank`, `to_kebab`, `to_snake`
52
+ - **Dates** — `parse_date`, `format_date`, `relative_time`
53
+ - **Validation** — `is_email`, `is_url`, `is_ip`, `is_uuid`
54
+
55
+ ## API
56
+
57
+ ### Strings
58
+ | Function | Description |
59
+ |---|---|
60
+ | `slugify(text, separator="-")` | Convert text to a URL-friendly slug |
61
+ | `truncate(text, length=80, suffix="...")` | Truncate text with a suffix |
62
+ | `is_blank(text)` | `True` if `None` or whitespace |
63
+ | `to_kebab(text)` | CamelCase → kebab-case |
64
+ | `to_snake(text)` | CamelCase → snake_case |
65
+
66
+ ### Dates
67
+ | Function | Description |
68
+ |---|---|
69
+ | `parse_date(value)` | Parse ISO string / `date` / timestamp → `datetime` |
70
+ | `format_date(value, fmt="%Y-%m-%d")` | Format a date-like value |
71
+ | `relative_time(value, now=None)` | Human-friendly relative time |
72
+
73
+ ### Validation
74
+ | Function | Description |
75
+ |---|---|
76
+ | `is_email(value)` | Email format check |
77
+ | `is_url(value)` | http(s) URL check |
78
+ | `is_ip(value)` | IPv4 check |
79
+ | `is_uuid(value)` | UUID check |
80
+
81
+ ## Development
82
+
83
+ ```bash
84
+ git clone https://github.com/vexify-build/vbot-utils
85
+ cd vbot-utils
86
+ python -m build
87
+ python -m pytest
88
+ ```
89
+
90
+ ## License
91
+
92
+ [MIT](LICENSE) © VBot
@@ -0,0 +1,10 @@
1
+ vbot_utils/__init__.py,sha256=40jbCSJ6iKUS9114iLWjv6tUqbFGKArJwnTLHG6YOcc,714
2
+ vbot_utils/dates.py,sha256=snMudaDU7fHPvCDT7VF-NFqzAoyavzRHid6SIa34sbU,2352
3
+ vbot_utils/py.typed,sha256=WqcInkQHOl79Ubpr3txasR-vjkpDYxhXXlxkUzumLNo,44
4
+ vbot_utils/strings.py,sha256=_X_KTgoVfLd6b9va1jqdr2bW5F9TIGEQFvWwI9ZpbxQ,1910
5
+ vbot_utils/validation.py,sha256=6tW4XLn9tk50KlgDAC4I9i4rj0U8mvsLpFs0pKvfExE,1270
6
+ vbot_utils-0.1.0.dist-info/licenses/LICENSE,sha256=lcURNHBTj3fEJul3Ohr3uzM9D9UT8OGuRETlUA-Ckuw,1061
7
+ vbot_utils-0.1.0.dist-info/METADATA,sha256=nGXEwtJpZQgNJ9QBDtCtV9v1IrkJjn_LdZGWXmS-qfw,2866
8
+ vbot_utils-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
9
+ vbot_utils-0.1.0.dist-info/top_level.txt,sha256=LeDaulGSWyV7sI5WV_bWqxxGjB37znJKqPIl9XrNQL8,11
10
+ vbot_utils-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 VBot
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
+ vbot_utils