crashbytes-strutils 1.0.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,45 @@
1
+ """crashbytes-strutils — Zero-dependency string utilities."""
2
+
3
+ from crashbytes_strutils._core import (
4
+ between,
5
+ count_words,
6
+ initials,
7
+ is_blank,
8
+ is_valid_email,
9
+ mask,
10
+ pad_left,
11
+ pad_right,
12
+ remove_whitespace,
13
+ reverse,
14
+ slugify,
15
+ strip_html,
16
+ to_camel_case,
17
+ to_constant_case,
18
+ to_kebab_case,
19
+ to_pascal_case,
20
+ to_snake_case,
21
+ to_title_case,
22
+ truncate,
23
+ )
24
+
25
+ __all__ = [
26
+ "between",
27
+ "count_words",
28
+ "initials",
29
+ "is_blank",
30
+ "is_valid_email",
31
+ "mask",
32
+ "pad_left",
33
+ "pad_right",
34
+ "remove_whitespace",
35
+ "reverse",
36
+ "slugify",
37
+ "strip_html",
38
+ "to_camel_case",
39
+ "to_constant_case",
40
+ "to_kebab_case",
41
+ "to_pascal_case",
42
+ "to_snake_case",
43
+ "to_title_case",
44
+ "truncate",
45
+ ]
@@ -0,0 +1,128 @@
1
+ """String utilities — case conversion, slugify, masking, and more."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import re
6
+ import unicodedata
7
+
8
+ _EMAIL_RE = re.compile(r"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$")
9
+ _WORD_BOUNDARY_RE = re.compile(r"[A-Z]+(?=[A-Z][a-z])|[A-Z]?[a-z]+|[A-Z]+|[0-9]+")
10
+ _NON_ALPHANUM_RE = re.compile(r"[^a-z0-9]+")
11
+ _HTML_TAG_RE = re.compile(r"<[^>]+>")
12
+
13
+
14
+ def _split_words(text: str) -> list[str]:
15
+ """Split text into words at case boundaries, spaces, hyphens, underscores."""
16
+ return _WORD_BOUNDARY_RE.findall(text)
17
+
18
+
19
+ def to_snake_case(text: str) -> str:
20
+ """Convert text to ``snake_case``."""
21
+ return "_".join(w.lower() for w in _split_words(text))
22
+
23
+
24
+ def to_camel_case(text: str) -> str:
25
+ """Convert text to ``camelCase``."""
26
+ words = _split_words(text)
27
+ if not words:
28
+ return ""
29
+ return words[0].lower() + "".join(w.capitalize() for w in words[1:])
30
+
31
+
32
+ def to_pascal_case(text: str) -> str:
33
+ """Convert text to ``PascalCase``."""
34
+ return "".join(w.capitalize() for w in _split_words(text))
35
+
36
+
37
+ def to_kebab_case(text: str) -> str:
38
+ """Convert text to ``kebab-case``."""
39
+ return "-".join(w.lower() for w in _split_words(text))
40
+
41
+
42
+ def to_title_case(text: str) -> str:
43
+ """Convert text to ``Title Case``."""
44
+ return " ".join(w.capitalize() for w in _split_words(text))
45
+
46
+
47
+ def to_constant_case(text: str) -> str:
48
+ """Convert text to ``CONSTANT_CASE``."""
49
+ return "_".join(w.upper() for w in _split_words(text))
50
+
51
+
52
+ def slugify(text: str) -> str:
53
+ """Convert text to a URL-friendly slug."""
54
+ normalized = unicodedata.normalize("NFKD", text)
55
+ ascii_text = normalized.encode("ascii", "ignore").decode("ascii").lower()
56
+ slug = _NON_ALPHANUM_RE.sub("-", ascii_text).strip("-")
57
+ return re.sub(r"-{2,}", "-", slug)
58
+
59
+
60
+ def truncate(text: str, max_length: int, suffix: str = "...") -> str:
61
+ """Truncate *text* to *max_length* characters, appending *suffix* if cut."""
62
+ if len(text) <= max_length:
63
+ return text
64
+ return text[: max_length - len(suffix)] + suffix
65
+
66
+
67
+ def mask(text: str, visible: int = 4, char: str = "*") -> str:
68
+ """Mask all but the last *visible* characters."""
69
+ if len(text) <= visible:
70
+ return text
71
+ return char * (len(text) - visible) + text[-visible:]
72
+
73
+
74
+ def between(text: str, start: str, end: str) -> str | None:
75
+ """Extract the substring between *start* and *end*, or ``None``."""
76
+ s = text.find(start)
77
+ if s == -1:
78
+ return None
79
+ s += len(start)
80
+ e = text.find(end, s)
81
+ if e == -1:
82
+ return None
83
+ return text[s:e]
84
+
85
+
86
+ def strip_html(text: str) -> str:
87
+ """Remove HTML tags from *text*."""
88
+ return _HTML_TAG_RE.sub("", text)
89
+
90
+
91
+ def is_valid_email(value: str) -> bool:
92
+ """Check if *value* is a valid email address."""
93
+ return bool(_EMAIL_RE.match(value))
94
+
95
+
96
+ def is_blank(value: str | None) -> bool:
97
+ """Check if *value* is ``None``, empty, or whitespace-only."""
98
+ return value is None or value.strip() == ""
99
+
100
+
101
+ def reverse(text: str) -> str:
102
+ """Reverse a string."""
103
+ return text[::-1]
104
+
105
+
106
+ def count_words(text: str) -> int:
107
+ """Count the number of words in *text*."""
108
+ return len(text.split())
109
+
110
+
111
+ def initials(text: str, separator: str = "") -> str:
112
+ """Extract initials from *text*."""
113
+ return separator.join(w[0].upper() for w in text.split() if w)
114
+
115
+
116
+ def pad_left(text: str, length: int, char: str = " ") -> str:
117
+ """Pad *text* on the left to *length* with *char*."""
118
+ return text.rjust(length, char)
119
+
120
+
121
+ def pad_right(text: str, length: int, char: str = " ") -> str:
122
+ """Pad *text* on the right to *length* with *char*."""
123
+ return text.ljust(length, char)
124
+
125
+
126
+ def remove_whitespace(text: str) -> str:
127
+ """Remove all whitespace from *text*."""
128
+ return re.sub(r"\s+", "", text)
File without changes
@@ -0,0 +1,66 @@
1
+ Metadata-Version: 2.4
2
+ Name: crashbytes-strutils
3
+ Version: 1.0.0
4
+ Summary: Zero-dependency string utilities — case conversion, slugify, masking, and more.
5
+ Project-URL: Homepage, https://github.com/CrashBytes/crashbytes-strutils
6
+ Project-URL: Repository, https://github.com/CrashBytes/crashbytes-strutils
7
+ Project-URL: Issues, https://github.com/CrashBytes/crashbytes-strutils/issues
8
+ Author-email: CrashBytes <crashbytes@users.noreply.github.com>
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: case-conversion,slugify,string,text,utilities
12
+ Classifier: Development Status :: 5 - Production/Stable
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Typing :: Typed
21
+ Requires-Python: >=3.10
22
+ Provides-Extra: dev
23
+ Requires-Dist: mypy; extra == 'dev'
24
+ Requires-Dist: pytest; extra == 'dev'
25
+ Requires-Dist: pytest-cov; extra == 'dev'
26
+ Requires-Dist: ruff; extra == 'dev'
27
+ Description-Content-Type: text/markdown
28
+
29
+ # crashbytes-strutils
30
+
31
+ Zero-dependency string utilities — case conversion, slugify, masking, and more.
32
+
33
+ ## Install
34
+
35
+ ```bash
36
+ pip install crashbytes-strutils
37
+ ```
38
+
39
+ ## Usage
40
+
41
+ ```python
42
+ from crashbytes_strutils import to_snake_case, slugify, mask, truncate
43
+
44
+ to_snake_case("helloWorld") # "hello_world"
45
+ slugify("Hello World!") # "hello-world"
46
+ mask("4111111111111111") # "************1111"
47
+ truncate("Long text here", 10) # "Long te..."
48
+ ```
49
+
50
+ ## API
51
+
52
+ ### Case Conversion
53
+ `to_snake_case`, `to_camel_case`, `to_pascal_case`, `to_kebab_case`, `to_title_case`, `to_constant_case`
54
+
55
+ ### Text Manipulation
56
+ `slugify`, `truncate`, `mask`, `between`, `strip_html`, `reverse`, `pad_left`, `pad_right`, `remove_whitespace`
57
+
58
+ ### Validation
59
+ `is_valid_email`, `is_blank`
60
+
61
+ ### Analysis
62
+ `count_words`, `initials`
63
+
64
+ ## License
65
+
66
+ MIT
@@ -0,0 +1,7 @@
1
+ crashbytes_strutils/__init__.py,sha256=hyyeSsxyoQgOm1tsoZTUPQFO8zZr_MvnYClXy-yYKmM,788
2
+ crashbytes_strutils/_core.py,sha256=OPUp_g_ZxQKDbu_R0JUysh722WOQ9AAwnGOx1Tf8H3Q,3785
3
+ crashbytes_strutils/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ crashbytes_strutils-1.0.0.dist-info/METADATA,sha256=jnROKs2zhJ04Mtn0ezTtK7aplC4nT6PDAR-RpH956Ig,2042
5
+ crashbytes_strutils-1.0.0.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
6
+ crashbytes_strutils-1.0.0.dist-info/licenses/LICENSE,sha256=Ic61HOO4EsyXXAGNY-D-1nG62feh_IBbipY1v_QcYcY,1067
7
+ crashbytes_strutils-1.0.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.29.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 CrashBytes
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.