# joinclass

> A utility for composing and transforming CSS class names

Latest version **1.1.2** (published 2026-03-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install joinclass
pnpm add joinclass
yarn add joinclass
bun add joinclass
```

## Health

**Score 55/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 1.1.2 |
| Published | 2026-03-19 |
| First published | 2022-06-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=16.0.0 |
| Dependencies | 0 |
| Unpacked size | 9.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Delpi.Kye |
| Maintainers | delpikye |
| Keywords | react, vue, lib, css, clsx, classs, classnames, classname, classes, joinclass |

## Links

- npm: https://www.npmjs.com/package/joinclass
- Repository: https://github.com/delpikye-v/joinclass
- Homepage: https://github.com/delpikye-v/joinclass#readme
- Issues: https://github.com/delpikye-v/joinclass/issues
- npm.io page: https://npm.io/package/joinclass

## 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.1.2 (latest) — 2026-03-19
- 1.1.1 — 2026-03-11
- 1.1.0 — 2025-09-16
- 1.0.0 — 2022-06-28

## README

# 🎨 joinclass

[![NPM](https://img.shields.io/npm/v/joinclass.svg)](https://www.npmjs.com/package/joinclass) ![Downloads](https://img.shields.io/npm/dt/joinclass.svg)

[LIVE EXAMPLE](https://codesandbox.io/p/sandbox/c48jf8)

A **tiny utility for composing and transforming CSS class names**.

> `joinclass` merges classes from multiple input types and supports prefix/suffix transformation, making it ideal for **Tailwind**, **CSS Modules**, or standard class names.

---

# Why joinclass

Writing class names in modern UI often requires:

- conditional logic
- CSS Modules mapping
- array merging
- deduplication
- dynamic generation

`joinclass` provides a **single deterministic utility** to normalize class inputs.

- ✅ Conditional classes
- ✅ Array / object / function support
- ✅ Set / Map support
- ✅ CSS Modules mapping
- ✅ Prefix / suffix transformation
- ✅ Automatic deduplication
- ✅ Works with Tailwind / CSS Modules
- ✅ Tiny footprint

---

# Installation

```bash
npm install joinclass
```

---

# Import

```ts
import joinclass from "joinclass"
```

---

# Basic Usage

```ts
joinclass("btn", "active")

// → "btn active"
```

Falsy values are ignored automatically.

```ts
joinclass("btn", false && "hidden", null)

// → "btn"
```

---

# Input Types

`joinclass` accepts multiple input formats.

---

## 1️⃣ String

```ts
joinclass("btn", "btn-primary")

// → "btn btn-primary"
```

---

## 2️⃣ Array

```ts
joinclass(["btn", "btn-large", null])

// → "btn btn-large"
```

Arrays are flattened automatically.

---

## 3️⃣ Object (Conditional Classes)

```ts
joinclass({
  primary: true,
  disabled: false
})

// → "primary"
```

Only truthy keys are included.

---

## 4️⃣ Function

```ts
joinclass(() => "dynamic-class")

// → "dynamic-class"
```

Functions allow **lazy class evaluation**.

---

## 5️⃣ Set

```ts
joinclass(new Set(["btn", "active", "btn"]))
// → "btn active" (deduplicated)
```

---

## 6️⃣ Map

```ts
joinclass(
  new Map([
    ["visible", true],
    ["hidden", false]
  ])
)

// → "visible"
```

Map keys behave like object conditional classes.

---

# CSS Modules Support

`joinclass` can map class names through CSS Modules.

```ts
import styles from "./Button.module.css"

joinclass("btn", "active", {
  styles
})

// → "Button_btn__abc Button_active__xyz"
```

---

# Prefix / Suffix

```ts
joinclass("btn", "large", {
  prefix: "ui-"
})

// → "ui-btn ui-large"
```

Suffix example:

```ts
joinclass("btn", {
  suffix: "-active"
})

// → "btn-active"
```

---

# Deduplication

Duplicate classes are removed automatically.

```ts
joinclass("btn", "btn", ["btn"])

// → "btn"
```

---

# Combined

```ts
import styles from "./Button.module.css"

joinclass(
  "btn",
  ["btn-large", null, "active"],
  { primary: true, disabled: false },
  () => "dynamic-class",
  new Set(["set-class"]),
  new Map([["map-class", true]]),
  {
    prefix: "ui-",
    styles
  }
)
```

---

# API

## joinclass(...inputs)

| Input Type  | Description           |
|-------------|---------------------- |
| string      | Direct class name     |
| number      | Converted to string   |
| array       | Flattened recursively |
| object      | Conditional classes   |
| function    | Returns class name    |
| Set         | Converted to array    |
| Map         | Conditional key-value |

---

## Options

| Option   | Description              |
|----------|--------------------------|
| `prefix` | Add prefix to each class |
| `suffix` | Add suffix to each class |
| `styles` | CSS Modules mapping      |

Example:

```ts
joinclass("btn", {
  prefix: "ui-",
  suffix: "-x"
})
```

---

# Use Cases

`joinclass` is useful for:

- React components
- Tailwind UI logic
- CSS Modules integration
- Dynamic class generation
- Utility-first CSS workflows

---

# Philosophy

> Class composition should be deterministic and flexible.

`joinclass` focuses on **normalizing class inputs** rather than adding framework-specific behavior.

---

# LISCENSE

MIT

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