extended_data.primitives.strings¶
This module provides utilities for string manipulation and validation.
It includes functions to sanitize keys, truncate messages, manipulate character cases, validate URLs, convert camelCase to TitleCase, and convert string representations of truth to boolean values.
Module Contents¶
Functions¶
Convert bytes, memoryview, bytearray, or another object to a string. |
|
Sanitizes a key by replacing non-alphanumeric characters with a delimiter. |
|
Truncates a message to a maximum length, appending an ender if truncated. |
|
Converts the first character of a string to lowercase. |
|
Converts the first character of a string to uppercase. |
|
Checks if the given string is a valid URL using urlparse. |
|
Converts a camelCase name to a TitleCase name. |
API¶
- extended_data.primitives.strings.bytes_to_string(value: object) str¶
Convert bytes, memoryview, bytearray, or another object to a string.
Bytes-like values are decoded as UTF-8. Strings are returned unchanged and all other objects use their standard string representation.
Args: value: The value to convert.
Returns: The string representation of the input.
Raises: UnicodeDecodeError: If the bytes or bytearray cannot be decoded into a valid UTF-8 string.
- extended_data.primitives.strings.sanitize_key(key: str, delim: str = '_') str¶
Sanitizes a key by replacing non-alphanumeric characters with a delimiter.
Args: key (str): The key to sanitize. delim (str): The delimiter to replace non-alphanumeric characters with. Defaults to “_”.
Returns: str: The sanitized key.
- extended_data.primitives.strings.truncate(msg: str, max_length: int, ender: str = '...') str¶
Truncates a message to a maximum length, appending an ender if truncated.
Args: msg (str): The message to truncate. max_length (int): The maximum length of the truncated message. ender (str): The string to append to the truncated message. Defaults to “…”.
Returns: str: The truncated message.
- extended_data.primitives.strings.lower_first_char(inp: str) str¶
Converts the first character of a string to lowercase.
Args: inp (str): The input string.
Returns: str: The string with the first character in lowercase.
- extended_data.primitives.strings.upper_first_char(inp: str) str¶
Converts the first character of a string to uppercase.
Args: inp (str): The input string.
Returns: str: The string with the first character in uppercase.