Text Module¶
The rite.text module provides comprehensive text processing utilities
including case conversions, slug generation, text analysis, validation,
manipulation, search operations, and sanitization.
Overview¶
This section introduces the text processing helpers at a high level. Each submodule page provides the detailed API reference.
Submodules¶
- Case: Case conversion utilities.
- Slug: Slug generation and validation.
- Analysis: Text analysis helpers.
- Validation: Validate text input.
- Manipulation: Text manipulation helpers.
- Search: Search within text.
- Sanitize: Text sanitization utilities.
- Morse: Morse code conversion.
- Random: Random text generation.
from rite.text import to_snake_case, slugify, text_truncate # Case conversion text = "HelloWorld" snake = to_snake_case(text) # "hello_world" # Slug generation title = "Hello World! This is a test." slug = slugify(title) # "hello-world-this-is-a-test" # Text manipulation long_text = "This is a very long text that needs truncation" short = text_truncate(long_text, 20) # "This is a very l..."
Advanced Examples¶
from rite.text import (
text_is_email,
text_pad_left,
char_frequency,
text_contains
)
# Validation
email = "[email protected]"
is_valid = text_is_email(email) # True
# Padding
number = "42"
padded = text_pad_left(number, 5, "0") # "00042"
# Analysis
text = "hello world"
freq = char_frequency(text) # {'h': 1, 'e': 1, 'l': 3, ...}
# Search
haystack = "The quick brown fox"
found = text_contains(haystack, "quick") # True