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

@tlgr/fmt

v1.5.2

Published

Formatter functions for telegram reply context

Downloads

1

Readme

Fmt

Formatter for telegram context.

Working with JSX

  1. install preact dependency.
npm i preact
  1. update tsconfig.json file(if necessary) and add jsx support:
{
  "compilerOptions": {
    // tsconfig options
      "jsx": "react",
      "jsxFactory": "h"
    }
}
  1. Update file names(.js -> .jsx or .ts -> .tsx)

  2. Enjoy using JSX :)

Example:

import { h, Fragment } from 'preact';
import {render, Bold} from '@tlgr/fmt/default';

const bot = new Telegraf('<API TOKEN>');

bot.start(ctx => {
  ctx.reply(...render(
    <Fragment>
        <Bold>Some text is bolded</Bold>
    </Fragment>
))
})

bot.launch();

Reply context

  1. string - use it in case of using template string.
  2. react - use it in case of using JSX components.

Also its important to use spread operator for render function since this function is returns tuple with raw text and it's modifications (like bold, mention, etc.)

  1. markdown (deprecated) - use this package when you want to reply with markdown V2.
  2. html (deprecated) - use this package when you want to reply with HTML.

Example with react:

import { h, Fragment } from 'preact';
import { render, Bold } from '@tlgr/fmt/react';

const bot = new Telegraf('<API TOKEN>');

bot.start(ctx => {
  // NOTE: use spread operator, since render returns raw string with formatting
  ctx.reply(...render(
    <Fragment>
        <Bold>Some text is bolded</Bold>
    </Fragment>
  ), {}) // others Telegram reply options
})

bot.launch();

Example with string:

import {render, bold} from '@tlgr/fmt/string';

const bot = new Telegraf('<API TOKEN>');

bot.start(ctx => {
  // NOTE: not use spread operator, since render returns raw string
  ctx.reply(...render(
   `${bold('this text is bolded')}`
  ))
})

bot.launch();

Supported formatter functions

  • bold - make text bold
  • italic - make text italic
  • underline - make text underline
  • strikethrough - make text ~~strikethrough~~
  • cash - add currency sign based on locale and currency sign.
  • code - add code snippet
  • command - add / symbol. incoming string must be without spaces ``.
  • email - transform name and host. E.g. [email protected]
  • hashtag - add # sign at the string.
  • hashtags - same as hashtag but accepts many hash strings.
  • link - create link. If name parameter is passed - create a text with link.
  • mention - add @ sign at the start of string.
  • spoiler - make incoming text to spoiler