text
Text helpers: padding, wrapping, number formatting and random ids.
import text
Example
import text
say(text.pad_left("7", 3, "0"))
say(text.center("TB", 10, "*"))
say(text.format_number(1234567.891, 2))
say(text.title("hello there, tanisha"))
say(text.count("banana", "a"))
Functions
pad_left(value, width, fill?)
returns textAdd fill (a space by default) on the left until it is width letters: pad_left(7, 3, "0") is "007".
pad_right(value, width, fill?)
returns textAdd fill (a space by default) on the right until it is width letters.
center(value, width, fill?)
returns textPut the text in the middle of width letters.
wrap(text, width)
returns textBreak long text into lines of at most width letters (between words).
is_digit(text)
returns boolTrue if the text is only the digits 0-9 (and not empty).
format_number(n, decimals?)
returns textThe number with commas between thousands: format_number(1234.5, 2) is "1,234.50".
random_id(length?)
returns textA random id of letters and digits (8 by default), safe for secrets.
reverse(text)
returns textThe text backwards.
title(text)
returns textEvery Word Starting With A Capital.
count(text, part)
returns numberHow many times part appears in the text.