跳转到主要内容

Documentation Index

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

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

字符串工具刻意保持很小,只保留能减少展示、日志和测试中重复代码的 helper。

1. 控制展示长度

truncateshorten 可用于 CLI、日志或报告中的短预览。
from heavenbase.utils.strings import shorten

preview = shorten("a very long explanation that should not dominate a table", cutoff=24)
cutoff 为负数,或文本已经足够短时,helper 会返回原字符串。

2. 格式化文本块

indentdedent 用于生成多行文本。
from heavenbase.utils.strings import dedent, indent

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

print(indent(body, tab=2))

3. 规范化名字

snake 可以把自由文本转成简单的 snake_case 名称。
from heavenbase.utils.strings import snake

assert snake("Search Result") == "search_result"
如果你要校验 entity ID、workspace ID 或后端物理名,使用 heavenbase.utils 中的专门 helper:check_entity_id, check_workspace_id, entity_table_name, workspace_index_name

Further Exploration

相关资源:
  • 通用工具 - 类型、脱敏、颜色和 hash helper。
  • Schema - entity 和字段命名约定。