UNPKG

@gramio/format

Version:

Library for formatting text for Telegram Bot API

245 lines (240 loc) 8.48 kB
import { APIMethods, APIMethodParams, TelegramUser } from '@gramio/types'; import { S as Stringable, F as FormattableString } from './formattable-string-DSBfRcG4.js'; export { g as getFormattable } from './formattable-string-DSBfRcG4.js'; type FormattableMethods = { [Method in keyof APIMethods]?: (params: NonNullable<APIMethodParams<Method>>) => NonNullable<APIMethodParams<Method>>; }; /** * A set of methods that decompose the {@link FormattableString} into a string and * an array of [entities](https://core.telegram.org/bots/api#messageentity) for further sending to the Telegram Bot API * * @codegenerated */ declare const FormattableMap: FormattableMethods; /** * @module * * Library for [formatting](https://core.telegram.org/bots/api#messageentity) text for Telegram Bot API * */ /** * Format text as **bold**. Cannot be combined with `code` and `pre`. * @example * ```ts * bold`test` * format`test ${bold(italic("GramIO"))}` * format`Format text as ${bold`bold`}`; * ``` * ![bold](https://gramio.dev/formatting/bold.png) */ declare const bold: { (str: Stringable): FormattableString; (strings: TemplateStringsArray, ...values: Stringable[]): FormattableString; }; /** * Format text as _italic_. Cannot be combined with `code` and `pre`. * @example * ```ts * italic`test` * format`test ${italic(bold("GramIO"))}` * format`Format text as ${italic`italic`}`; * ``` * ![italic](https://gramio.dev/formatting/italic.png) */ declare const italic: { (str: Stringable): FormattableString; (strings: TemplateStringsArray, ...values: Stringable[]): FormattableString; }; /** * Format text as underline. Cannot be combined with `code` and `pre`. * @example * ```ts * underline`test` * format`test ${underline(bold("GramIO"))}` * format`Format text as ${underline`underline`}`; * ``` * ![underline](https://gramio.dev/formatting/underline.png) */ declare const underline: { (str: Stringable): FormattableString; (strings: TemplateStringsArray, ...values: Stringable[]): FormattableString; }; /** * Format text as ~~strikethrough~~. Cannot be combined with `code` and `pre`. * @example * ```ts * strikethrough`test` * format`test ${strikethrough(bold("GramIO"))}` * format`Format text as ${strikethrough`strikethrough`}`; * ``` * ![](https://gramio.dev/formatting/strikethrough.png) */ declare const strikethrough: { (str: Stringable): FormattableString; (strings: TemplateStringsArray, ...values: Stringable[]): FormattableString; }; /** * Format text as spoiler. Cannot be combined with `code` and `pre`. * @example * ```ts * spoiler`test` * format`test ${spoiler(bold("GramIO"))}` * format`Format text as ${spoiler`spoiler`}`; * ``` * ![spoiler](https://gramio.dev/formatting/spoiler.png) */ declare const spoiler: { (str: Stringable): FormattableString; (strings: TemplateStringsArray, ...values: Stringable[]): FormattableString; }; /** * Format text as blockquote. Cannot be nested. * @example * ```ts * blockquote`test` * format`test ${blockquote(bold("GramIO"))}` * format`Format text as ${blockquote`blockquote`}`; * ``` * ![blockquote](https://gramio.dev/formatting/blockquote.png) */ declare const blockquote: { (str: Stringable): FormattableString; (strings: TemplateStringsArray, ...values: Stringable[]): FormattableString; }; /** * Format text as expandable blockquote. Cannot be nested. * @example * ```ts * blockquote`test` * format`test ${expandableBlockquote(bold("GramIO"))}` * format`Format text as ${expandableBlockquote`blockquote`}`; * ``` * ![blockquote](https://gramio.dev/formatting/expandable_blockquote.png) */ declare const expandableBlockquote: { (str: Stringable): FormattableString; (strings: TemplateStringsArray, ...values: Stringable[]): FormattableString; }; /** * Format text as `code`. Cannot be combined with any other format. * @example * ```ts * code`test` * format`test ${code("copy it")}` * format`Format text as ${code`code`}`; * ``` * ![code](https://gramio.dev/formatting/code.png) */ declare const code: { (str: Stringable): FormattableString; (strings: TemplateStringsArray, ...values: Stringable[]): FormattableString; }; /** * Format text as ```pre```. Cannot be combined with any other format. * @example * ```ts * pre`test` * format`test ${pre(`console.log("GramIO")`, "js")}` * ``` * pre with language result is * ```js * console.log("GramIO") * ``` * [Supported languages](https://github.com/TelegramMessenger/libprisma#supported-languages) * * ![pre](https://gramio.dev/formatting/pre.png) */ declare const pre: (str: Stringable, language?: string | undefined) => FormattableString; /** * Format text as [link](https://github.com/gramiojs/gramio). Cannot be combined with `code` and `pre`. * @example * ```ts * link("test", "https://...") * format`test ${bold(link("GramIO", "https://github.com/gramiojs/gramio"))}` * format`Format text as ${link("link", "https://github.com/gramiojs/gramio")}`; * ``` * ![link](https://gramio.dev/formatting/link.png) */ declare const link: (str: Stringable, url: string) => FormattableString; /** * Format text as mention. Cannot be combined with `code` and `pre`. * @example * ```ts * mention("friend", { id: 228, is_bot: false, first_name: "GramIO"}) * format`test ${mention("friend", { id: 228, is_bot: false, first_name: "GramIO"})}` * ``` * ![mention](https://gramio.dev/formatting/mention.png) */ declare const mention: (str: Stringable, user: TelegramUser) => FormattableString; /** * Insert custom emoji by their id. * @example * ```ts * customEmoji("⚔️", "5222106016283378623") * format`test ${customEmoji("⚔️", "5222106016283378623")}` * ``` * **NOTE**: Custom emoji entities can only be used by bots that purchased additional usernames on [Fragment](https://fragment.com/). */ declare const customEmoji: (str: Stringable, custom_emoji_id: string) => FormattableString; /** * Helper for great work with formattable arrays. ([].join break styling) * Separator by default is `, ` * @example * ```ts * format`${join(["test", "other"], (x) => format`${bold(x)}`, "\n")}` * ``` */ declare function join<T>(array: T[], iterator: (item: T, index: number) => Stringable | false | undefined | null, separator?: string): FormattableString; /** * [Template literal](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals) * that helps construct message [entities](https://core.telegram.org/bots/api#messageentity) for text formatting. * * [Documentation](https://gramio.dev/formatting/) * * Use if you want to strip all of the indentation from the beginning of each line. * * **NOTE**: for format with **arrays** use it with {@link join} helper - * ```ts * format`${join(["test", "other"], (x) => format`${bold(x)}`, "\n")}` * ``` * * @example * ```ts * bot.api.sendMessage({ * chat_id: 12321, * text: format`${bold`Hi!`} * Can ${italic(`you`)} help ${spoiler`me`}? * Can you give me a ${link("star", "https://github.com/gramiojs/gramio")}?` * }) * ``` * * ![format](https://gramio.dev/formatting/format.png) */ declare function format(stringParts: TemplateStringsArray, ...strings: Stringable[]): FormattableString; /** * [Template literal](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals) * that helps construct message [entities](https://core.telegram.org/bots/api#messageentity) for text formatting. * * [Documentation](https://gramio.dev/formatting/) * * Use if you want to save all of the indentation. * * **NOTE**: for format with **arrays** use it with {@link join} helper - * ```ts * format`${join(["test", "other"], (x) => format`${bold(x)}`, "\n")}` * ``` * * @example * ```ts * bot.api.sendMessage({ * chat_id: 12321, * text: format`${bold`Hi!`} * Can ${italic(`you`)} help ${spoiler`me`}? * Can you give me a ${link("star", "https://github.com/gramiojs/gramio")}?` * }) * ``` * * ![formatSaveIndents](https://gramio.dev/formatting/format-save-indents.png) */ declare function formatSaveIndents(stringParts: TemplateStringsArray, ...strings: Stringable[]): FormattableString; export { FormattableMap, FormattableString, Stringable, blockquote, bold, code, customEmoji, expandableBlockquote, format, formatSaveIndents, italic, join, link, mention, pre, spoiler, strikethrough, underline };