npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tg-text-formatter

v1.2.1

Published

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.

Downloads

925

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:

npm i tg-text-formatter
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

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

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

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!