Skip to main content

Documentation Index

Fetch the complete documentation index at: https://ahvn.top/llms.txt

Use this file to discover all available pages before exploring further.

String utilities provide compact display helpers plus Markdown builders used by prompts, reports, generated docs, and tests.

1. Keep display text short

Use truncate or shorten when CLI output, logs, or reports should show a compact preview.
from heavenbase.utils.strings import shorten

preview = shorten("a very long explanation that should not dominate a table", cutoff=24)
The helper returns the original string when cutoff is negative or the value already fits.

2. Format blocks

Use indent and dedent for generated text blocks. They wrap Python’s text formatting behavior behind one project-level import.
from heavenbase.utils.strings import dedent, indent

body = dedent("""
    First line
    Second line
""")

print(indent(body, tab=2))
Use md_block, code_block, file_block, and json_block for fenced Markdown output. Fences expand automatically when the content already contains backticks.
from heavenbase.utils.strings import code_block, json_block

print(code_block("print('hello')", lang="python"))
print(json_block({"status": "ok"}))
Use bullet_list, numbered_list, and bullet_dict for compact lists that preserve indentation for multi-line values.
from heavenbase.utils.strings import bullet_dict

print(bullet_dict({"backend": "sqlite", "rows": 1000}))

3. Build Markdown sections

Use md_section to build nested Markdown with stable blank lines and heading levels.
from heavenbase.utils.strings import bullet_list, code_block, md_section

report = md_section(
    title="Run report",
    content="Summary text.",
    sections=[
        {"title": "Inputs", "content": bullet_list(["sqlite", "1000 rows"])},
        {"title": "Snippet", "content": code_block("result = hb.open('demo')", lang="python")},
    ],
    end="Done.",
)
The rendered section uses exactly one blank line between headings, body blocks, nested sections, and the ending paragraph. That makes generated Markdown readable without extra post-processing.

4. Normalize names and text

Use snake when free-form names must become simple identifiers for diagnostics or generated artifacts.
from heavenbase.utils.strings import snake

assert snake("Search Result") == "search_result"
For entity IDs and backend-safe names, use the dedicated validation helpers in heavenbase.utils: check_entity_id, check_workspace_id, entity_table_name, and workspace_index_name. For lightweight matching, is_delimiter, generate_ngrams, resolve_match_conflicts, and asymmetric_jaccard_score are available. normalize_text uses spaCy when en_core_web_sm is installed and raises a clear error otherwise.

Further Exploration

Related resources:
  • Common utilities - typing helpers, debug output, colors, and hashing.
  • Schema - entity and field naming conventions.