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 🙏

© 2026 – Pkg Stats / Ryan Hefner

telegram-transformer

v1.4.0

Published

Telegram message transformer

Readme

Introduction

Telegram transformer is a library that makes it simple for you to transform telegram message to any markup.

Getting started

Installation

$ npm install telegram-transformer

or

$ yarn add telegram-transformer

Example

import formatText, { htmlFormatters } from 'telegram-transformer';
import { MessageEntity } from 'typegram';

const text =
  'Hello @username #awesome_hashtag $USD /start@jobs_bot https://telegram.org [email protected] +1-212-555-0123 bold text italic text underlined text strikethrough text spoiler message monowidth string monowidth block text_link custom_emoji text_mention';
const entities: MessageEntity[] = [
  { offset: 6, length: 9, type: 'mention' },
  { offset: 16, length: 16, type: 'hashtag' },
  { offset: 25, length: 7, type: 'bold' },
  { offset: 33, length: 4, type: 'cashtag' },
  { offset: 38, length: 15, type: 'bot_command' },
  { offset: 54, length: 20, type: 'url' },
  { offset: 75, length: 25, type: 'email' },
  { offset: 101, length: 15, type: 'phone_number' },
  { offset: 117, length: 9, type: 'bold' },
  { offset: 127, length: 11, type: 'italic' },
  { offset: 139, length: 5, type: 'underline' },
  { offset: 144, length: 10, type: 'underline' },
  { offset: 144, length: 5, type: 'bold' },
  { offset: 155, length: 18, type: 'strikethrough' },
  { offset: 174, length: 15, type: 'spoiler' },
  {
    offset: 223,
    length: 9,
    type: 'text_link',
    url: 'https://telegram.org/',
  },
  {
    offset: 233,
    length: 12,
    type: 'custom_emoji',
    custom_emoji_id: '12345',
  },
  {
    offset: 246,
    length: 12,
    type: 'text_mention',
    user: {
      id: 9876543210,
      is_bot: false,
      first_name: 'First Name',
    },
  },
];

const formatted = formatText(text, entities, { formatters: htmlFormatters });

console.log(formatted);

/*
{
  text: "Hello <a href='https://t.me/username'>@username</a> <a href='#awesome_hashtag'>#awesome_<strong>hashtag</strong></a> $USD /start@jobs_bot <a href='https://telegram.org'>https://telegram.org</a> <a href='mailto:[email protected]'>[email protected]</a> <a href='tel:+1-212-555-0123'>+1-212-555-0123</a> <strong>bold text</strong> <i>italic text</i> <u>under</u><u><strong>lined</strong> text</u> <strike>strikethrough text</strike> <span class='spoiler-hover'>spoiler message</span> monowidth string monowidth block <a href='https://telegram.org/'>text_link</a> <span>custom_emoji | <b>EMOJI ID:12345</b></span> <span>text_mention: First Name | <b>ID:9876543210</b></span>",
  entities: [
    { offset: 6, length: 45, type: 'mention' },
    { offset: 52, length: 64, type: 'hashtag' },
    { offset: 88, length: 24, type: 'bold' },
    { offset: 117, length: 4, type: 'cashtag' },
    { offset: 122, length: 15, type: 'bot_command' },
    { offset: 138, length: 55, type: 'url' },
    { offset: 194, length: 72, type: 'email' },
    { offset: 267, length: 49, type: 'phone_number' },
    { offset: 317, length: 26, type: 'bold' },
    { offset: 344, length: 18, type: 'italic' },
    { offset: 363, length: 12, type: 'underline' },
    { offset: 375, length: 34, type: 'underline' },
    { offset: 378, length: 22, type: 'bold' },
    { offset: 410, length: 35, type: 'strikethrough' },
    { offset: 446, length: 50, type: 'spoiler' },
    {
      offset: 530,
      length: 45,
      type: 'text_link',
      url: 'https://telegram.org/',
    },
    {
      offset: 576,
      length: 49,
      type: 'custom_emoji',
      custom_emoji_id: '12345',
    },
    {
      offset: 626,
      length: 60,
      type: 'text_mention',
      user: {
        id: 9876543210,
        is_bot: false,
        first_name: 'First Name',
      },
    },
  ]
}
*/

Custom transformer

import formatText, { htmlFormatters } from 'telegram-transformer';
import { MessageEntity } from 'typegram';

const text = 'Hello @username #awesome_hashtag';
const entities: MessageEntity[] = [
  { offset: 6, length: 9, type: 'mention' },
  { offset: 16, length: 16, type: 'hashtag' },
];

const formatters = {
  mention: (entityText: string, entity: MessageEntity, text: string) => ({
    before: '<awesome-mention>',
    after: '</awesome-mention>',
    text: entityText,
  }),
  hashtag: (entityText: string, entity: MessageEntity, text: string) => ({
    before: '<span class="hashtag">',
    after: '</span>',
    text: entityText,
  }),
};

const formatted = formatText(text, entities, { formatters });

console.log(formatted);

/*
{
  text: 'Hello <awesome-mention>@username</awesome-mention> <span class="hashtag">#awesome_hashtag</span>',
  entities: [
    { offset: 6, length: 44, type: 'mention' },
    { offset: 51, length: 45, type: 'hashtag' }
  ]
}
*/