# @megafon/ui-helpers

> Helpers library

Latest version **5.1.0** (published 2026-09-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install @megafon/ui-helpers
pnpm add @megafon/ui-helpers
yarn add @megafon/ui-helpers
bun add @megafon/ui-helpers
```

## Health

**Score 70/100 (B)** — status: active.

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

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 5.1.0 |
| Published | 2026-09-03 |
| First published | 2021-07-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 4 |
| Unpacked size | 51.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | MegaFon |
| Maintainers | myfka, ifonin, hq-lk-admins, ns3777k, balffr, dmitrylobasov, artem.kovalchuk |

## Links

- npm: https://www.npmjs.com/package/@megafon/ui-helpers
- npm.io page: https://npm.io/package/@megafon/ui-helpers

## Dependencies (4)

- [htmr](https://npm.io/package/htmr.md) ^1.0.2
- [core-js](https://npm.io/package/core-js.md) ^3.6.4
- [classnames](https://npm.io/package/classnames.md) ^2.2.6
- [@babel/runtime](https://npm.io/package/@babel/runtime.md) ^7.8.4

## Recent versions

- 5.1.0 (latest) — 2026-09-03
- 3.0.0-beta.1 (beta) — 2024-07-11
- 5.0.2 — 2026-07-27
- 5.0.1 — 2026-05-12
- 5.0.0 — 2026-04-20
- 5.0.0-alpha.3 — 2026-03-04
- 4.1.3 — 2026-03-04
- 4.1.1 — 2026-03-04
- 5.0.0-alpha.2 — 2026-01-15
- 4.1.0 — 2026-01-15
- 5.0.0-alpha.1 — 2025-07-08
- 5.0.0-alpha.0 — 2025-07-01
- 4.0.2 — 2025-06-17
- 4.0.1 — 2025-03-11
- 4.0.0 — 2025-02-06
- … 29 more at https://npm.io/package/@megafon/ui-helpers/versions

## README

# @megafon/ui-helpers

Helpers library

## Installation

with npm
```bash
npm install --save @megafon/ui-helpers
```

or yarn
```bash
yarn add @megafon/ui-helpers
```

## Usage

---
### cnCreate
BEM generator

```js
import { cnCreate } from '@megafon/ui-helpers';

const cn = cnCreate('block');

cn();
// block

cn('element');
// block__element

cn({ mod: true });
// block block_mod

cn({ mod: 'value' });
// block block_mod_value

cn(['custom-class', 'custom-class-2']);
// block custom-class custom-class-2

cn('element', ['custom-class', 'custom-class-2']);
// block__element custom-class custom-class-2

cn('element', { mod: true }, ['custom-class', 'custom-class-2']);
// block__element block__element_mod custom-class custom-class-2
```

---
### convert
htmr library extension for replacing html tags with your own components, recognizing
components props and html attributes

requires React as dependency

```tsx
import React from 'react';
import { convert, ConvertTransformConfig } from '@megafon/ui-helpers';

const Link = ({ href, target, className, children }) => (
    <a className={className} href={href} target={target}>{children}</a>
);

const config: ConvertTransformConfig = {
    a: {
        component: Link,
        props: ['href', 'target'],
        customProps: { className: 'class-name' },
    },
};

convert('<a href="/test" target="_blank">link</a>', config);
// <Link className="class-name" href="/test" target="_blank">link</Link>'
```
---

### filterDataAttrs
Filters properties using regular expression /^data-/

```ts
import { filterDataAttrs } from '@megafon/ui-helpers';

filterDataAttrs({
    'data-attr': 'value',
    'data-custom-attr': 'value',
    'DataAttr': 'value',
    'attr-data': 'value'
});
// { 'data-attr': 'value', 'data-custom-attr': 'value' }
```
---

### detectTouch
Detects touch devices

```js
import { detectTouch } from '@megafon/ui-helpers';

detectTouch()
// returns `true` or `false` depending on device

```
---

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