# @tlgr/fmt

> Formatter functions for telegram reply context

Latest version **1.5.2** (published 2023-02-22) · Apache 2.0 license · 0 weekly downloads

## Install

```sh
npm install @tlgr/fmt
pnpm add @tlgr/fmt
yarn add @tlgr/fmt
bun add @tlgr/fmt
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.5.2 |
| Published | 2023-02-22 |
| First published | 2022-08-17 |
| Weekly downloads | 0 |
| License | Apache 2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 6 |
| Unpacked size | 92.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Vitali Haradkou |
| Maintainers | vitalicset |
| Keywords | Telegram, utility, formatting, JSX |

## Links

- npm: https://www.npmjs.com/package/@tlgr/fmt
- Homepage: https://github.com/vitalics/Telegraph/tree/main/packages/fmt#readme
- Issues: https://github.com/vitalics/Telegraph/issues
- npm.io page: https://npm.io/package/@tlgr/fmt

## Dependencies (6)

- [preact](https://npm.io/package/preact.md) 10.11.0
- [telegraf](https://npm.io/package/telegraf.md) 4.8.6
- [@mdx-js/preact](https://npm.io/package/@mdx-js/preact.md) 2.1.3
- [node-html-parser](https://npm.io/package/node-html-parser.md) 6.1.0
- [awesome-phonenumber](https://npm.io/package/awesome-phonenumber.md) 3.3.0
- [preact-render-to-string](https://npm.io/package/preact-render-to-string.md) 5.2.4

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.5.2 (latest) — 2023-02-22
- 1.5.1 — 2022-10-04
- 1.5.0 — 2022-10-04
- 1.4.4 — 2022-10-04
- 1.4.2 — 2022-09-22
- 1.4.1 — 2022-09-22
- 1.4.0 — 2022-09-21
- 1.3.1 — 2022-08-19
- 1.3.0 — 2022-08-17

## README

# Fmt

Formatter for telegram context.

## Working with JSX

1. install `preact` dependency.

``` bash
npm i preact
```

2. update `tsconfig.json` file(if necessary)
and add jsx support:

``` json
{
  "compilerOptions": {
    // tsconfig options
      "jsx": "react",
      "jsxFactory": "h"
    }
}
```

3. Update file names(`.js` -> `.jsx` or `.ts` -> `.tsx`)

4. Enjoy using JSX :)

Example:

``` tsx
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.)

3. `markdown` (deprecated) - use this package when you want to reply with markdown V2.
4. `html` (deprecated) - use this package when you want to reply with HTML.

Example with react:

``` tsx
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:

``` tsx
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 <u>underline</u>
- 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. `first_last@example.com`
- 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

---
_Source: https://npm.io/package/@tlgr/fmt · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
