# merge-class-names

> A function that merges given class names, no matter their format: string with single or multiple class names or an array of class names. Filters out invalid class names as well.

Latest version **1.4.2** (published 2021-08-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install merge-class-names
pnpm add merge-class-names
yarn add merge-class-names
bun add merge-class-names
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.4.2 |
| Published | 2021-08-26 |
| First published | 2017-09-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 6.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 12 |
| Author | Wojciech Maj |
| Maintainers | wojtekmaj |
| Keywords | class, class names, class list, merge |

## Links

- npm: https://www.npmjs.com/package/merge-class-names
- Repository: https://github.com/wojtekmaj/merge-class-names
- Funding: https://github.com/wojtekmaj/merge-class-names?sponsor=1
- npm.io page: https://npm.io/package/merge-class-names

## Recent versions

- 1.4.2 (latest) — 2021-08-26
- 1.4.1 — 2021-08-26
- 1.4.0 — 2021-01-20
- 1.3.0 — 2019-11-03
- 1.2.0 — 2019-05-03
- 1.1.1 — 2017-10-07
- 1.1.0 — 2017-09-09
- 1.0.1 — 2017-09-09
- 1.0.0 — 2017-09-09

## README

[![npm](https://img.shields.io/npm/v/merge-class-names.svg)](https://www.npmjs.com/package/merge-class-names) ![downloads](https://img.shields.io/npm/dt/merge-class-names.svg) [![CI](https://github.com/wojtekmaj/merge-class-names/workflows/CI/badge.svg)](https://github.com/wojtekmaj/merge-class-names/actions) ![dependencies](https://img.shields.io/david/wojtekmaj/merge-class-names.svg) ![dev dependencies](https://img.shields.io/david/dev/wojtekmaj/merge-class-names.svg) [![tested with jest](https://img.shields.io/badge/tested_with-jest-99424f.svg)](https://github.com/facebook/jest)

# Merge-Class-Names
A function that merges given class names, no matter their format. Filters out invalid class names as well.

## tl;dr
* Install by executing `npm install merge-class-names` or `yarn add merge-class-names`.
* Import by adding `import mergeClassNames from 'merge-class-names'`.
* Use it in `className` like so: `<div className={mergeClassNames('foo', condition && 'bar', arrayOfClasses)} />`

## Accepted formats
* Strings with one or multiple class names: `a`, `a b`
* Array of strings with one or multiple class names: `['a', 'b']`, `['a b', 'c d']`.

## Examples

```js
> mergeClassNames('a', 'b', 'c');
< 'a b c'

> mergeClassNames('a b', 'c d', 'e f');
< 'a b c d e f'

> mergeClassNames(['a', 'b'], ['c', 'd']);
< 'a b c d'

> mergeClassNames(['a b', 'c d'], ['e f', 'g h']);
< 'a b c d e f g h'

> mergeClassNames('a', 'b', falsyCondition && 'c');
< 'a b'

> mergeClassNames('a', 'b', 'c', null, ['d', null], () => {}, 'e', undefined);
< 'a b c d e'
```

## License

The MIT License.

## Author

<table>
  <tr>
    <td>
      <img src="https://github.com/wojtekmaj.png?s=100" width="100">
    </td>
    <td>
      Wojciech Maj<br />
      <a href="mailto:kontakt@wojtekmaj.pl">kontakt@wojtekmaj.pl</a><br />
      <a href="https://wojtekmaj.pl">https://wojtekmaj.pl</a>
    </td>
  </tr>
</table>

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