crashbytes-strutils 1.0.0__tar.gz

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 @@
1
+ * @CrashBytes
@@ -0,0 +1,23 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ python-version: ["3.10", "3.11", "3.12", "3.13"]
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+ - uses: actions/setup-python@v5
18
+ with:
19
+ python-version: ${{ matrix.python-version }}
20
+ - run: pip install -e ".[dev]"
21
+ - run: ruff check src/ tests/
22
+ - run: mypy --strict src/
23
+ - run: pytest --cov=crashbytes_strutils --cov-branch --cov-fail-under=90
@@ -0,0 +1,19 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ push:
5
+ tags: ["*"]
6
+
7
+ jobs:
8
+ publish:
9
+ runs-on: ubuntu-latest
10
+ permissions:
11
+ id-token: write
12
+ steps:
13
+ - uses: actions/checkout@v4
14
+ - uses: actions/setup-python@v5
15
+ with:
16
+ python-version: "3.12"
17
+ - run: pip install build
18
+ - run: python -m build
19
+ - uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,11 @@
1
+ __pycache__/
2
+ *.pyc
3
+ *.pyo
4
+ dist/
5
+ build/
6
+ *.egg-info/
7
+ .coverage
8
+ .pytest_cache/
9
+ .mypy_cache/
10
+ .ruff_cache/
11
+
@@ -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.
@@ -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,38 @@
1
+ # crashbytes-strutils
2
+
3
+ Zero-dependency string utilities — case conversion, slugify, masking, and more.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pip install crashbytes-strutils
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```python
14
+ from crashbytes_strutils import to_snake_case, slugify, mask, truncate
15
+
16
+ to_snake_case("helloWorld") # "hello_world"
17
+ slugify("Hello World!") # "hello-world"
18
+ mask("4111111111111111") # "************1111"
19
+ truncate("Long text here", 10) # "Long te..."
20
+ ```
21
+
22
+ ## API
23
+
24
+ ### Case Conversion
25
+ `to_snake_case`, `to_camel_case`, `to_pascal_case`, `to_kebab_case`, `to_title_case`, `to_constant_case`
26
+
27
+ ### Text Manipulation
28
+ `slugify`, `truncate`, `mask`, `between`, `strip_html`, `reverse`, `pad_left`, `pad_right`, `remove_whitespace`
29
+
30
+ ### Validation
31
+ `is_valid_email`, `is_blank`
32
+
33
+ ### Analysis
34
+ `count_words`, `initials`
35
+
36
+ ## License
37
+
38
+ MIT
@@ -0,0 +1,53 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "crashbytes-strutils"
7
+ version = "1.0.0"
8
+ description = "Zero-dependency string utilities — case conversion, slugify, masking, and more."
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ requires-python = ">=3.10"
12
+ authors = [{ name = "CrashBytes", email = "crashbytes@users.noreply.github.com" }]
13
+ keywords = ["string", "utilities", "slugify", "case-conversion", "text"]
14
+ classifiers = [
15
+ "Development Status :: 5 - Production/Stable",
16
+ "Intended Audience :: Developers",
17
+ "License :: OSI Approved :: MIT License",
18
+ "Programming Language :: Python :: 3",
19
+ "Programming Language :: Python :: 3.10",
20
+ "Programming Language :: Python :: 3.11",
21
+ "Programming Language :: Python :: 3.12",
22
+ "Programming Language :: Python :: 3.13",
23
+ "Typing :: Typed",
24
+ ]
25
+
26
+ [project.optional-dependencies]
27
+ dev = ["pytest", "pytest-cov", "mypy", "ruff"]
28
+
29
+ [project.urls]
30
+ Homepage = "https://github.com/CrashBytes/crashbytes-strutils"
31
+ Repository = "https://github.com/CrashBytes/crashbytes-strutils"
32
+ Issues = "https://github.com/CrashBytes/crashbytes-strutils/issues"
33
+
34
+ [tool.ruff]
35
+ target-version = "py310"
36
+ line-length = 99
37
+
38
+ [tool.ruff.lint]
39
+ select = ["E", "F", "I", "N", "UP", "B", "SIM", "TCH"]
40
+
41
+ [tool.mypy]
42
+ strict = true
43
+ python_version = "3.10"
44
+
45
+ [tool.pytest.ini_options]
46
+ testpaths = ["tests"]
47
+
48
+ [tool.coverage.run]
49
+ branch = true
50
+ source = ["crashbytes_strutils"]
51
+
52
+ [tool.coverage.report]
53
+ fail_under = 90
@@ -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)
@@ -0,0 +1,173 @@
1
+ """Tests for crashbytes-strutils."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from crashbytes_strutils import (
6
+ between,
7
+ count_words,
8
+ initials,
9
+ is_blank,
10
+ is_valid_email,
11
+ mask,
12
+ pad_left,
13
+ pad_right,
14
+ remove_whitespace,
15
+ reverse,
16
+ slugify,
17
+ strip_html,
18
+ to_camel_case,
19
+ to_constant_case,
20
+ to_kebab_case,
21
+ to_pascal_case,
22
+ to_snake_case,
23
+ to_title_case,
24
+ truncate,
25
+ )
26
+
27
+
28
+ class TestCaseConversion:
29
+ def test_to_snake_case(self) -> None:
30
+ assert to_snake_case("helloWorld") == "hello_world"
31
+ assert to_snake_case("HelloWorld") == "hello_world"
32
+ assert to_snake_case("hello-world") == "hello_world"
33
+ assert to_snake_case("HELLO_WORLD") == "hello_world"
34
+ assert to_snake_case("XMLParser") == "xml_parser"
35
+
36
+ def test_to_camel_case(self) -> None:
37
+ assert to_camel_case("hello_world") == "helloWorld"
38
+ assert to_camel_case("HelloWorld") == "helloWorld"
39
+ assert to_camel_case("hello-world") == "helloWorld"
40
+ assert to_camel_case("") == ""
41
+
42
+ def test_to_pascal_case(self) -> None:
43
+ assert to_pascal_case("hello_world") == "HelloWorld"
44
+ assert to_pascal_case("helloWorld") == "HelloWorld"
45
+
46
+ def test_to_kebab_case(self) -> None:
47
+ assert to_kebab_case("helloWorld") == "hello-world"
48
+ assert to_kebab_case("hello_world") == "hello-world"
49
+
50
+ def test_to_title_case(self) -> None:
51
+ assert to_title_case("hello_world") == "Hello World"
52
+ assert to_title_case("helloWorld") == "Hello World"
53
+
54
+ def test_to_constant_case(self) -> None:
55
+ assert to_constant_case("helloWorld") == "HELLO_WORLD"
56
+ assert to_constant_case("hello-world") == "HELLO_WORLD"
57
+
58
+
59
+ class TestSlugify:
60
+ def test_basic(self) -> None:
61
+ assert slugify("Hello World") == "hello-world"
62
+
63
+ def test_special_chars(self) -> None:
64
+ assert slugify("Hello & World!") == "hello-world"
65
+
66
+ def test_unicode(self) -> None:
67
+ assert slugify("H\u00e9llo W\u00f6rld") == "hello-world"
68
+
69
+ def test_multiple_dashes(self) -> None:
70
+ assert slugify("hello world") == "hello-world"
71
+
72
+ def test_leading_trailing(self) -> None:
73
+ assert slugify(" hello ") == "hello"
74
+
75
+
76
+ class TestTruncate:
77
+ def test_no_truncation_needed(self) -> None:
78
+ assert truncate("hello", 10) == "hello"
79
+
80
+ def test_truncation(self) -> None:
81
+ assert truncate("hello world", 8) == "hello..."
82
+
83
+ def test_custom_suffix(self) -> None:
84
+ assert truncate("hello world", 8, "~") == "hello w~"
85
+
86
+ def test_exact_length(self) -> None:
87
+ assert truncate("hello", 5) == "hello"
88
+
89
+
90
+ class TestMask:
91
+ def test_basic(self) -> None:
92
+ assert mask("1234567890") == "******7890"
93
+
94
+ def test_custom_visible(self) -> None:
95
+ assert mask("1234567890", visible=2) == "********90"
96
+
97
+ def test_custom_char(self) -> None:
98
+ assert mask("1234567890", char="#") == "######7890"
99
+
100
+ def test_short_string(self) -> None:
101
+ assert mask("123", visible=4) == "123"
102
+
103
+
104
+ class TestBetween:
105
+ def test_basic(self) -> None:
106
+ assert between("Hello [World] End", "[", "]") == "World"
107
+
108
+ def test_no_start(self) -> None:
109
+ assert between("Hello World", "[", "]") is None
110
+
111
+ def test_no_end(self) -> None:
112
+ assert between("Hello [World", "[", "]") is None
113
+
114
+ def test_empty_result(self) -> None:
115
+ assert between("Hello [] End", "[", "]") == ""
116
+
117
+
118
+ class TestStripHtml:
119
+ def test_basic(self) -> None:
120
+ assert strip_html("<p>Hello</p>") == "Hello"
121
+
122
+ def test_nested(self) -> None:
123
+ assert strip_html("<div><b>Hello</b></div>") == "Hello"
124
+
125
+ def test_no_tags(self) -> None:
126
+ assert strip_html("Hello") == "Hello"
127
+
128
+ def test_self_closing(self) -> None:
129
+ assert strip_html("Hello<br/>World") == "HelloWorld"
130
+
131
+
132
+ class TestValidation:
133
+ def test_valid_email(self) -> None:
134
+ assert is_valid_email("user@example.com") is True
135
+
136
+ def test_invalid_email(self) -> None:
137
+ assert is_valid_email("not-an-email") is False
138
+
139
+ def test_is_blank_none(self) -> None:
140
+ assert is_blank(None) is True
141
+
142
+ def test_is_blank_empty(self) -> None:
143
+ assert is_blank("") is True
144
+
145
+ def test_is_blank_whitespace(self) -> None:
146
+ assert is_blank(" ") is True
147
+
148
+ def test_is_blank_content(self) -> None:
149
+ assert is_blank("hello") is False
150
+
151
+
152
+ class TestMisc:
153
+ def test_reverse(self) -> None:
154
+ assert reverse("hello") == "olleh"
155
+ assert reverse("") == ""
156
+
157
+ def test_count_words(self) -> None:
158
+ assert count_words("hello world foo") == 3
159
+ assert count_words("") == 0
160
+
161
+ def test_initials(self) -> None:
162
+ assert initials("John Doe") == "JD"
163
+ assert initials("John Doe", separator=".") == "J.D"
164
+
165
+ def test_pad_left(self) -> None:
166
+ assert pad_left("42", 5, "0") == "00042"
167
+
168
+ def test_pad_right(self) -> None:
169
+ assert pad_right("hi", 5) == "hi "
170
+
171
+ def test_remove_whitespace(self) -> None:
172
+ assert remove_whitespace("hello world") == "helloworld"
173
+ assert remove_whitespace(" a b ") == "ab"