@gramio/format
Version:
Library for formatting text for Telegram Bot API
245 lines (240 loc) • 8.48 kB
TypeScript
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`}`;
* ```
* 
*/
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`}`;
* ```
* 
*/
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`}`;
* ```
* 
*/
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`}`;
* ```
* 
*/
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`}`;
* ```
* 
*/
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`}`;
* ```
* 
*/
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`}`;
* ```
* 
*/
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`}`;
* ```
* 
*/
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)
*
* 
*/
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")}`;
* ```
* 
*/
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"})}`
* ```
* 
*/
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")}?`
* })
* ```
*
* 
*/
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")}?`
* })
* ```
*
* 
*/
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 };