ft3.core.strings.utl module

Strings utility functions.

camel_case_to_snake_case(camelCaseString: string[camelCase]) string[snake_case]

Convert a valid str[camelCase] to str[snake_case].

cname_for(string: str | string[StringType], container: tuple[string[StringType] | str, ...]) string[StringType] | str | None

Get the actual, canonical name for valid string, as contained in an arbitrary, valid, immutable Container[str] (i.e. a tuple[str, ...]), agnostic of string casing and / or underscores.

Example Usage

d = {
    '_id': 123,
    '_meaning_of_life': 42
    }

cname_for(d, 'id')
'_id'

cname_for(d, 'meaningOfLife')
'_meaning_of_life'
convert_for_repr(obj_: Any) dict[bool | int | float | None | str | string[StringType], Serial] | list[Serial] | bool | int | float | None | str | string[StringType]

Recursively prepare obj_ for neat __repr__.

is_snake_case_iterable(strings: Iterable[str] | MappingProto[str, AnyType]) TypeGuard[Iterable[string[snake_case]] | MappingProto[string[snake_case], AnyType]]

Check if all strings are str[snake_case].

Ignores leading and / or trailing underscores.

is_snake_case_string(string: str | string[StringType]) TypeGuard[string[snake_case]]

Check if string is valid snake_case.

Checks for strict [lower] snake_case (i.e. python attribute casing).

is_valid_datetime_str(any_str: str) TypeGuard[string[datetime]]

Return True if python str is parsable as a valid datetime.

is_valid_number_str(any_str: str) TypeGuard[string[numeric]]

Return True if python str is parsable as a valid numbers.Number.

isCamelCaseIterable(strings: Iterable[str] | MappingProto[str, AnyType]) TypeGuard[Iterable[string[camelCase]] | MappingProto[string[camelCase], AnyType]]

Check if all strings are str[camelCase].

Ignores leading and / or trailing underscores.

isCamelCaseString(string: str) TypeGuard[string[camelCase]]

Check if string is valid camelCase.

Checks for strict [lower] camelCase (i.e. RESTful casing) according to the Google Java Style Guide.

Unlike Google, does NOT allow for an optional uppercase character at the end of the string.

pluralize(string: str) str

Pluralize a singular string.

redact_key_value_pair(key: str, value: str) str

Redact potentially sensitive key, value pairs.

Returns only the value (or a redacted version).

redact_string(string: str) str

Redact potentially sensitive values.

snake_case_to_camel_case(snake_case_string: string[snake_case]) string[camelCase]

Convert a valid str[snake_case] to str[camelCase].

validate_casing(value: Any, casing: camelCase | snake_case) Never | None

Assert value is str and of correct Casing.

Raises TypeError if not str.

Raises StringCasingError if str of incorrect Casing.