pyutils-extended 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.
@@ -0,0 +1,3 @@
1
+ """pyutils_extended — a small collection of handy utility functions."""
2
+ from .utils import slugify, pluralize, humanize_bytes
3
+ __version__ = "0.1.0"
@@ -0,0 +1,13 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ setup(
4
+ name="pyutils-extended",
5
+ version="0.1.0",
6
+ packages=find_packages(),
7
+ description="A small collection of handy utility functions.",
8
+ long_description=open("README.md").read(),
9
+ long_description_content_type="text/markdown",
10
+ author="Revenue Worker",
11
+ license="MIT",
12
+ python_requires=">=3.8",
13
+ )
File without changes
@@ -0,0 +1,21 @@
1
+ """Unit tests for pyutils_extended.utils."""
2
+ from pyutils_extended.utils import slugify, pluralize, humanize_bytes
3
+
4
+
5
+ def test_slugify():
6
+ assert slugify("Hello World!") == "hello-world"
7
+ assert slugify("Multiple Spaces") == "multiple-spaces"
8
+ assert slugify("Special!@#$%^&*()") == "special"
9
+
10
+
11
+ def test_pluralize():
12
+ assert pluralize("apple", 1) == "apple"
13
+ assert pluralize("apple", 5) == "apples"
14
+ assert pluralize("bus", 2) == "buses"
15
+ assert pluralize("day", 3) == "days"
16
+
17
+
18
+ def test_humanize_bytes():
19
+ assert humanize_bytes(1000) == "1.0 KiB"
20
+ assert humanize_bytes(1500) == "1.5 KiB"
21
+ assert humanize_bytes(0) == "0.0 B"
@@ -0,0 +1,38 @@
1
+ """String helpers, pluralization, and size formatting."""
2
+ import re
3
+ import math
4
+
5
+ def slugify(text: str) -> str:
6
+ """Convert arbitrary text to a URL-safe slug."""
7
+ text = text.lower().strip()
8
+ text = re.sub(r'[^a-z0-9]+', '-', text)
9
+ return re.sub(r'-+', '-', text).strip('-')
10
+
11
+ def pluralize(word: str, count: int) -> str:
12
+ """Return plural form. Singular form is used only when count == 1."""
13
+ if count == 1:
14
+ return word
15
+ # Simple English pluralization
16
+ if word.endswith(('s', 'x', 'z', 'sh', 'ch')):
17
+ return word + 'es'
18
+ # y preceded by consonant → -ies (fly→flies)
19
+ # y preceded by vowel → -s (day→days, key→keys)
20
+ if word.endswith('y') and len(word) > 1:
21
+ if word[-2] not in 'aeiou':
22
+ return word[:-1] + 'ies'
23
+ return word + 's'
24
+
25
+ def humanize_bytes(size: int, binary: bool = False) -> str:
26
+ """Format bytes as human-readable string.
27
+
28
+ Args:
29
+ size: Number of bytes.
30
+ binary: If True, use 1024 base (KiB/MiB); else 1000.
31
+ """
32
+ base = 1024 if binary else 1000
33
+ units = ['B', 'KiB', 'MiB', 'GiB', 'TiB']
34
+ for unit in units:
35
+ if abs(size) < base:
36
+ return f"{size:.1f} {unit}"
37
+ size /= base
38
+ return f"{size:.1f} PiB"
@@ -0,0 +1,24 @@
1
+ Metadata-Version: 2.1
2
+ Name: pyutils-extended
3
+ Version: 0.1.0
4
+ Summary: A small collection of handy utility functions.
5
+ Author: Revenue Worker
6
+ License: MIT
7
+ Requires-Python: >=3.8
8
+ Description-Content-Type: text/markdown
9
+
10
+ # pyutils-extended
11
+
12
+ A small collection of handy utility functions.
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ pip install pyutils-extended
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ ```python
23
+ from pyutils_extended import slugify, pluralize, humanize_bytes
24
+ ```
@@ -0,0 +1,9 @@
1
+ pyutils_extended/__init__.py,sha256=3BexNer4DBSQ6SKMBZe2YUWGYXFslyKm7nCv9Ce0z6o,150
2
+ pyutils_extended/setup.py,sha256=-oTEtPGpPwAdhG2kEesLmjPbLeqB6zimZ5pJsdEOYlY,375
3
+ pyutils_extended/utils.py,sha256=joyybVo6R7YmEEEXfCKYnweMU64MUh6U12JF08dNbaQ,1257
4
+ pyutils_extended/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ pyutils_extended/tests/test_utils.py,sha256=iYTLS3CShLztj9PE-3moIBYgtUJV-KVzKf8vH1a0TJo,658
6
+ pyutils_extended-0.1.0.dist-info/METADATA,sha256=2vWMWZ_LclbJVyKpXgtJ44CFQ5EfLb_vjB11S7c_Mlk,431
7
+ pyutils_extended-0.1.0.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
8
+ pyutils_extended-0.1.0.dist-info/top_level.txt,sha256=Dqe0ypfozbEzDz21o7BDTnKorVTLeIrTw2OFvCpn9pY,17
9
+ pyutils_extended-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: bdist_wheel (0.42.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ pyutils_extended