fmt
ref / parse-mode / fmt
This is the format tagged template function. It accepts a template literal containing any mix of Stringable
and string
values, and constructs a Formatted
that represents the combination of all the given values. The constructed Formatted
also implements Stringable, and can be used in further fmt
tagged templates.
Can also be called like regular function and passed an array of Stringable
s.
ts
// Using return values of fmt in fmt
const left = fmt`${bold('>>>')} >>>`;
const right = fmt`<<< ${bold('<<<')}`;
const final = fmt`${left} ${ctx.msg.text} ${right}`;
await ctx.replyFmt(final);
// Using regular function form
const cart = fmt([
"Your shopping cart:\n",
...items.map((item) => fmt`- ${bold(item.name)} (${item.price})\n`),
]);
// Using result in editMessageText
await ctx.editMessageText(cart.text, { entities: cart.entities });
Type
ts
(rawStringParts: TemplateStringsArray | Stringable[], ...stringLikes: Stringable[]) => FormattedString