---
title: text | CodeWeaver Docs
description: API reference for codeweaver.core.utils.text
url: "https://docs.knitli.com/api/core/utils/text"
type: static
generatedAt: "2026-04-17T17:21:08.336Z"
---

# text
       [Open in ChatGPT](https://chatgpt.com/?q=Read%20https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Futils%2Ftext%2F.%20I%20want%20to%20ask%20questions%20about%20it.)[Open in Claude](https://claude.ai/new?q=Read%20https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Futils%2Ftext%2F.%20I%20want%20to%20ask%20questions%20about%20it.)[View in Markdown](/codeweaver/api/core/utils/text.md)       [Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Futils%2Ftext%2F)[Share on X](https://x.com/intent/tweet?url=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Futils%2Ftext%2F&text=text)[Share on Threads](https://threads.net/intent/post?url=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Futils%2Ftext%2F&text=text)[Share on Bluesky](https://bsky.app/intent/compose?text=text%20https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Futils%2Ftext%2F)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Futils%2Ftext%2F)[Share on Reddit](https://reddit.com/submit?url=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Futils%2Ftext%2F&title=text)[Share on Hacker News](https://news.ycombinator.com/submitlink?u=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Futils%2Ftext%2F&t=text)[Share on Email](mailto:?subject=text&body=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Futils%2Ftext%2F)[Share on WhatsApp](https://wa.me/?text=text%20https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Futils%2Ftext%2F)[Share on Telegram](https://t.me/share/url?url=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Futils%2Ftext%2F&text=text)
# `codeweaver.core.utils.text`
[Section titled “codeweaver.core.utils.text”](#codeweavercoreutilstext)
Text manipulation utilities.

## Function: `elapsed_time_to_human_readable`
[Section titled “Function: elapsed_time_to_human_readable”](#function-elapsed_time_to_human_readable)

**

```
elapsed_time_to_human_readable()
```

Convert elapsed time between start_time and end_time to a human-readable format.

## Function: `format_descriptor`
[Section titled “Function: format_descriptor”](#function-format_descriptor)

**

```
format_descriptor()
```

Format a code descriptor for display.

## Function: `format_docstring`
[Section titled “Function: format_docstring”](#function-format_docstring)

**

```
format_docstring()
```

Format a docstring for display.

## Function: `format_signature`
[Section titled “Function: format_signature”](#function-format_signature)

**

```
format_signature()
```

Format a function signature for display.

## Function: `format_snippet_name`
[Section titled “Function: format_snippet_name”](#function-format_snippet_name)

**

```
format_snippet_name()
```

Format a snippet name for display.

## Function: `humanize`
[Section titled “Function: humanize”](#function-humanize)

**

```
humanize()
```

Capitalize the first word and turn underscores into spaces and strip a trailing `"_id"`, if any. Creates a nicer looking string.

Examples: >>> humanize(“employee_salary”) ‘Employee salary’ >>> humanize(“author_id”) ‘Author’

## Function: `sanitize_unicode`
[Section titled “Function: sanitize_unicode”](#function-sanitize_unicode)

**

```
sanitize_unicode()
```

Sanitize unicode text by normalizing and removing invisible/control characters.

## Function: `to_lowly_lowercase`
[Section titled “Function: to_lowly_lowercase”](#function-to_lowly_lowercase)

**

```
to_lowly_lowercase()
```

Ensure insignificant words are lowercase.

## Function: `to_tokens`
[Section titled “Function: to_tokens”](#function-to_tokens)

**

```
to_tokens()
```

Convert a text string into a list of tokens.

## Function: `truncate_text`
[Section titled “Function: truncate_text”](#function-truncate_text)

**

```
truncate_text()
```

Truncate text to a maximum length, adding an ellipsis if truncated.

Args: text: The input text to truncate. max_length: The maximum allowed length of the text (default: 100). ellipsis: The string to append if truncation occurs (default: ”…”).

Returns: The truncated text if it exceeds max_length, otherwise the original text.

## Function: `validate_regex_pattern`
[Section titled “Function: validate_regex_pattern”](#function-validate_regex_pattern)

**

```
validate_regex_pattern()
```

Validate and compile a regex pattern from config/env.

 - Accepts compiled patterns as-is.
 - For strings, applies normalization via `_walk_pattern`, basic length and nested-quantifier checks, then compiles. Raises `ConfigurationError` on invalid/unsafe patterns.

## Function: `variable_to_env_var`
[Section titled “Function: variable_to_env_var”](#function-variable_to_env_var)

**

```
variable_to_env_var()
```

Convert a variable name to an environment variable name.