https://github.com/ayocord-js/tg-text-formatter
Telegram markdown formatter. Helpful for work with message content in telegram
https://github.com/ayocord-js/tg-text-formatter
library module string telegram tg typescript
Last synced: 6 months ago
JSON representation
Telegram markdown formatter. Helpful for work with message content in telegram
- Host: GitHub
- URL: https://github.com/ayocord-js/tg-text-formatter
- Owner: ayocord-js
- Created: 2024-11-03T21:28:47.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-11-04T19:57:22.000Z (11 months ago)
- Last Synced: 2025-03-07T21:48:46.011Z (7 months ago)
- Topics: library, module, string, telegram, tg, typescript
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/tg-text-formatter
- Size: 199 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# Tg Text Formatter
Hello! Welcome to the **tg-text-formatter** package for Telegram text markdown. This library provides convenient methods for formatting text without the hassle of manual markdown syntax.
## Installation
You can easily install this package via npm or yarn:
```bash
npm i tg-text-formatter
``````bash
yarn add tg-text-formatter
```## Tests of this Library
## Ways to Use
There are two ways to use this library:
1. Using classes
2. Using methods# TelegramMarkdown
## Using Class
```ts
import { TelegramMarkdown } from "tg-text-formatter";console.log(TelegramMarkdown.bold("idk")); // **idk**
console.log(TelegramMarkdown.cursive("idk")); // __idk__
console.log(TelegramMarkdown.boldCursive("idk")); // **__idk__**
console.log(TelegramMarkdown.crossedOut("idk")); // ~~idk~~
console.log(TelegramMarkdown.monospace("idk")); // `idk`/**
* Code with language
*/
console.log(TelegramMarkdown.code("console.log(`idk`)", "ts")); // ```ts\nidk```/**
* Code without language
*/
console.log(TelegramMarkdown.code("console.log(`idk`)")); // ```\nidk```
console.log(TelegramMarkdown.spoiler("idk")); // ||idk||
```## Using Methods
```ts
import {
bold,
cursive,
boldCursive,
crossedOut,
monospace,
code,
spoiler,
} from "tg-text-formatter";console.log(bold("idk")); // **idk**
console.log(cursive("idk")); // __idk__
console.log(boldCursive("idk")); // **__idk__**
console.log(crossedOut("idk")); // ~~idk~~
console.log(monospace("idk")); // `idk`/**
* Code with language
*/
console.log(code("console.log(`idk`)", "ts")); // ```ts\nidk```/**
* Code without language
*/
console.log(code("console.log(`idk`)")); // ```\nidk```
console.log(spoiler("idk")); // ||idk||
```# TelegramMentionParsers
The **TelegramMentionParsers** class provides methods for detecting and parsing Telegram mentions within text.
## Using TelegramMentionParsers
```ts
import { TelegramMentionParsers } from "tg-text-formatter";console.log(TelegramMentionParsers.isMention("@Stickers")); // true
console.log(TelegramMentionParsers.isMention("@@Stickers")); // false
console.log(TelegramMentionParsers.mentions("@Stickers @akakuke", true)); // ["@Stickers", "@akakuke"]
console.log(TelegramMentionParsers.mentions("@Stickers @@akakuke", true)); // ["@Stickers"]
console.log(TelegramMentionParsers.mentions("Stickers akakuke", true)); // []
console.log(TelegramMentionParsers.isLinkMention("Check this link: https://t.me/username")); // true
```## Methods in TelegramMentionParsers
- `isMention(content: string): boolean` - Checks if the content contains a valid mention.
- `mentions(content: string, mentions?: boolean): string[]` - Extracts mentions from the content. If `mentions` is true, it returns the mentions with the "@" symbol; otherwise, it returns without the "@".
- `isLinkMention(content: string): boolean` - Checks if the content contains a valid Telegram link.# TelegramMarkdownParser
The **TelegramMarkdownParser** class provides methods for detecting and parsing various markdown styles in Telegram text.
## Methods in TelegramMarkdownParser
- `isBold(text: string): boolean` - Checks if the text is bold.
- `parseBold(text: string, markdown = false): string[]` - Parses bold text. Returns the formatted text if `markdown` is true, otherwise returns the plain text.
- `isCursive(text: string): boolean` - Checks if the text is cursive.
- `parseCursive(text: string, markdown = false): string[]` - Parses cursive text.
- `isMonospace(text: string): boolean` - Checks if the text is monospace.
- `parseMonospace(text: string, markdown = false): string[]` - Parses monospace text.
- `isCode(text: string): boolean` - Checks if the text is a code block.
- `parseCode(text: string, markdown = false): string[]` - Parses code blocks.
- `isSpoiler(text: string): boolean` - Checks if the text is a spoiler.
- `parseSpoiler(text: string, markdown = false): string[]` - Parses spoilers.
- `isLink(text: string): boolean` - Checks if the text contains a markdown link.
- `parseLink(text: string): boolean` - Parses markdown links.
Now you can easily format your Telegram messages and manage mentions with this comprehensive library!