This library provides a set of functions for formatting text for use in Telegram messages. The functions can be used to format text with bold, italic, underline, strikethrough, inline code, code blocks, links and images.
💪 Installation
To install @telegram.ts/formatters, run:
npm install @telegram.ts/formatters
⭐️ Usage
const { bold, italic, underline, strikethrough, code, link, image, heading, paragraph, list, codeBlock } = require('@telegram.ts/formatters').html;
const message = `
${bold('Hello World!')}
${italic('This is an italicized text.')}
${underline('This is an underlined text.')}
${strikethrough('This text has a strikethrough.')}
${code('This is inline code.')}
${link('Click me!', 'https://example.com')}
${image('https://example.com/image.jpg', 'Image description')}
${heading('This is a heading.', 1)}
${paragraph('This is a paragraph.')}
${list(['Item 1', 'Item 2', 'Item 3'], true)}
${codeBlock('const x = 1;', 'javascript')}
`;
console.log(message);
This will output:
<b>Hello World!</b>
<i>This is an italicized text.</i>
<u>This is an underlined text.</u>
<s>This text has a strikethrough.</s>
<code>This is inline code.</code>
<a href="https://example.com">Click me!</a>
<img src="https://example.com/image.jpg" alt="Image description">
<h1>This is a heading.</h1>
This is a paragraph.
1. Item 1
2. Item 2
3. Item 3
📜 Functions
bold(text: string): string
Formats text in bold.
italic(text: string): string
Formats text in italic.
underline(text: string): string
Formats text with an underline.
strikethrough(text: string): string
Formats text with a strikethrough.
code(text: string): string
Formats text as inline code.
link(text: string, url: string): string
Formats a link with the specified text and URL.
image(url: string, alt: string): string
Formats an image with the specified URL and alt text.
heading(text: string, level: number = 1): string
Formats a heading with the specified text and level (1-6).
paragraph(text: string): string
Formats a paragraph of text.
list(items: string[], ordered: boolean = false): string
Formats a list with the specified items. If ordered is true, the list will be ordered.
codeBlock(code: string, language: string = ''): string
Formats a code block with the specified code and language (optional).