Module formatting

Source
Expand description

This module contains various helper functions for easier formatting and creation of user-friendly messages.

Enums§

Enclosing
Indent

Functions§

a_or_an
Returns indefinite article “a” or “an” that corresponds to the word, or an empty string if the indefinite article do not fit to the word.
ascii_sentence_case
Returns text with the first character turned into ASCII uppercase.
call_path_suffix_with_args
Returns the suffix of the call_path together with any type arguments if they exist. Convenient for subsequent showing of only the short name of a full name that was already shown.
did_you_mean
Finds strings from an iterable of possible_values similar to a given value v. Returns a vector of all possible values that exceed a similarity threshold, sorted by similarity (most similar comes first). The returned vector will have at most max_num_of_suggestions elements.
first_line
Returns the first line in text, up to the first \n if the text contains multiple lines, and optionally adds ellipses “…” to the end of the line if with_ellipses is true.
get_file_name
Returns the file name (with extension) for the provided source_id, or None if the source_id is None or the file name cannot be obtained.
is_are
Returns “is” if count is 1, otherwise “are”.
number_to_str
Returns reading-friendly textual representation for number smaller than or equal to 10 or its numeric representation if it is greater than 10.
plural_s
Returns “s” if count is different than 1, otherwise empty string. Convenient for building simple plural of words.
sequence_to_list
Returns reading-friendly textual representation of the sequence, with vertically listed items and each item indented for the indent and preceded with the dash (-). If the sequence has more than max_items the remaining items are replaced with the text “and more”.
sequence_to_str
Returns reading-friendly textual representation of the sequence, with comma-separated items and each item optionally enclosed in the specified enclosing. If the sequence has more than max_items the remaining items are replaced with the text “and more”.
sequence_to_str_or
Returns reading-friendly textual representation of the sequence, with comma-separated items and each item optionally enclosed in the specified enclosing. If the sequence has more than max_items the remaining items are replaced with the text “or more”.
singular_plural
Returns singular if count is 1, otherwise plural.