Data and Math

vtextwrap

Wraps and fills text to the width you choose.

Released v1.0.0 · 2026-09-28
Import
use "stdlib/textwrap.ven"

Wraps and fills text to a width you choose, and splits text into words.

vtextwrap.ven
print words_of("  hello   world  ")
:: ["hello", "world"]
Reference (11 functions)

API reference

words_of(text)

Splits text into a list of whitespace-separated words.

print(words_of("  hello   world  "))
:: prints: ["hello", "world"]

collapse_whitespace(text)

Collapses every run of whitespace in text down to a single space.

print(collapse_whitespace("  hello   world  "))
:: prints: hello world

hard_break_word(word, width)

Splits word into width-sized chunks, hard-breaking it as needed.

print(hard_break_word("abcdefgh", 3))
:: prints: ["abc", "def", "gh"]

wrap_to_width(text, width)

Wraps text into a list of lines, each at most width characters.

print(wrap_to_width("The quick brown fox jumps over the lazy dog", 10))
:: prints: ["The quick", "brown fox", "jumps over", "the lazy", "dog"]

fill_to_width(text, width)

Wraps text to width, then joins the lines back into one Text.

print(fill_to_width("The quick brown fox jumps over the lazy dog", 10))
:: prints: The quick
::         brown fox
::         jumps over
::         the lazy
::         dog

indent_lines(text, prefix)

Prepends prefix to every line of text.

print(indent_lines("a\nb\nc", "> "))
:: prints: > a
::         > b
::         > c

is_blank_line(l)

Tests whether l is empty or contains only whitespace.

print(is_blank_line("   "))
:: prints: yes

leading_whitespace(l)

Gives back the leading run of whitespace characters at the start of l.

print(length(leading_whitespace("   abc")))
:: prints: 3

common_prefix_of(a, b)

Gives back the longest common leading substring shared by a and b.

print(common_prefix_of("hello", "help"))
:: prints: hel

dedent_lines(text)

Removes the common leading whitespace shared by every line of text.

print(dedent_lines("    a\n      b\n    c"))
:: prints: a
::           b
::         c

shorten_to_width(text, width, placeholder)

Collapses whitespace in text, then truncates it to fit width.

print(shorten_to_width("The quick brown fox jumps over the lazy dog", 20, "..."))
:: prints: The quick brown...

Get notified when vtextwrap changes

Get notified about

New versions and security advisories.

New and updated packages, once a day.

News on the math model built in Venutian.