text.layout
fit text to a width, convert between naming styles like snake_case and camelCase, and count words
Shapes text for display. Pad, center, truncate or wrap it to a width, switch between naming styles like snake_case and camelCase, and count words.
Tags: formatting
padadd fill to the right until the text is width characters, so it lines up on the leftpad_leftadd fill to the left until the text is width characters, so it lines up on the rightcentercenter the text in width characterstruncateshorten to at most n characters, ending in … if anything was cutwrapbreak lines between words so none is longer than width charactersdedentremove the indentation that every non-blank line has in commontitleCapitalize The First Letter Of Each Wordsnakerewrite as snake_case: lowercase words joined by _camelrewrite as camelCase: words joined with no separator, each after the first capitalizedkebabrewrite as kebab-case: lowercase words joined by -sluga lowercase version for use in a URL: only letters and digits, with - between wordswordsa list of the words, with punctuation removed except apostropheswccount lines, words and bytes, like the Unix wc toolword_counthow many words there are, counted as words does
Functions
Section titled “Functions”pad(s: any, width: int, fill: str = “ “) -> str
add fill to the right until the text is width characters, so it lines up on the left
1"ab".pad(5) + "|""ab |"2"ab".pad(5, ".")"ab..."pad_left
Section titled “pad_left”pad_left(s: any, width: int, fill: str = “ “) -> str
add fill to the left until the text is width characters, so it lines up on the right
Numbers work too
142.pad_left(6, "0")"000042"center
Section titled “center”center(s: any, width: int, fill: str = “ “) -> str
center the text in width characters
When the fill can’t split evenly, the extra goes on the right
1"hi".center(8, "*")"***hi***"truncate
Section titled “truncate”truncate(s: str, n: int) -> str
shorten to at most n characters, ending in … if anything was cut
1"a long sentence here".truncate(10)"a long se…"See also wrap
wrap(s: str, width: int) -> str
break lines between words so none is longer than width characters
1"the quick brown fox jumps over the lazy dog".wrap(15)the quick brown
fox jumps over
the lazy dogdedent
Section titled “dedent”dedent(s: str) -> str
remove the indentation that every non-blank line has in common
1" a\n b\n c".dedenta
b
ctitle(s: str) -> str
Capitalize The First Letter Of Each Word
1"the lord of the rings".title"The Lord Of The Rings"See also capitalize, snake
snake(s: str) -> str
rewrite as snake_case: lowercase words joined by _
Words are split at spaces, punctuation and where a lowercase letter meets a capital
1"parseHTTPRequest".snake"parse_http_request"2"Total Price".snake"total_price"camel(s: str) -> str
rewrite as camelCase: words joined with no separator, each after the first capitalized
1"user_id_v2".camel"userIdV2"kebab(s: str) -> str
rewrite as kebab-case: lowercase words joined by -
1"MyComponentName".kebab"my-component-name"slug(s: str) -> str
a lowercase version for use in a URL: only letters and digits, with - between words
1"Hello, World! It's 2026".slug"hello-world-its-2026"See also kebab
words(s: str) -> list
a list of the words, with punctuation removed except apostrophes
1"Hello, world! Don't panic.".words["Hello", "world", "Don't", "panic"]See also word_count, split
wc(v: str|bytes, *, lines: bool = false, words: bool = false, bytes: bool = false) -> map|int
count lines, words and bytes, like the Unix wc tool
1"a b\nc\n".wc{lines: 2, words: 3, bytes: 6}2wc("a b\nc\n", words: true)3As a command:
-l,--linesjust the line count-w,--wordsjust the word count-c,--bytesjust the byte count
wc -l notes.txt# → wc(read_file("notes.txt"), lines: true)See also word_count, lines, read_file
word_count
Section titled “word_count”word_count(s: str) -> int
how many words there are, counted as words does
1"Hello, world! Don't panic.".word_count4See also words
More examples
Section titled “More examples”layout
Section titled “layout”1# a receipt line2"coffee".pad(12, ".") + "$4.50".pad_left(8)"coffee...... $4.50"3# a banner4"menu".upper.center(20, "=")"========MENU========"5# a column name as a variable name6"Total Price (USD)".snake"total_price_usd"7# a title as a URL slug8"Hello, World! It's 2026".slug"hello-world-its-2026"9# minutes to read 450 words at 200 a minute10(lorem(450).word_count / 200).ceil3Example results generated on 2026-11-04. Ones using now, today or randomness will differ when you run them.