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 🙏

© 2026 – Pkg Stats / Ryan Hefner

utils-cn

v1.0.2

Published

A utility function to conditionally join and merge Tailwind CSS classes efficiently.

Downloads

4

Readme

utils-cn 🌀

A lightweight utility function for conditionally applying and merging Tailwind CSS classes.

npm version npm downloads License: MIT

Features

  • ✅ Conditionally apply class names
  • ✅ Intelligently merge Tailwind CSS classes
  • ✅ Resolve conflicting Tailwind utility classes
  • ✅ TypeScript support
  • ✅ Zero dependencies (other than clsx and tailwind-merge)
  • ✅ Tiny bundle size

Installation

# npm
npm install utils-cn

# yarn
yarn add utils-cn

# pnpm
pnpm add utils-cn

Note: This package has peer dependencies on clsx and tailwind-merge. Make sure to install them if not already installed:

npm install clsx tailwind-merge

Usage

The cn function provides a simple way to conditionally apply classes and handle Tailwind CSS class conflicts:

Basic Usage

import cn from "utils-cn";

function Button({ variant, isActive, className }) {
  return (
    <button
      className={cn(
        "px-4 py-2 rounded",
        variant === "primary" && "bg-blue-500 text-white",
        variant === "secondary" && "bg-gray-200 text-gray-800",
        isActive && "ring-2 ring-offset-2",
        className
      )}
    >
      Click me
    </button>
  );
}

Handling Class Conflicts

The cn function automatically resolves Tailwind CSS class conflicts:

// Without utils-cn:
// The mt-4 class would remain and potentially conflict with mt-6
"mt-4 p-2 mt-6";

// With utils-cn:
// The mt-4 class is intelligently overridden by mt-6
cn("mt-4 p-2", "mt-6"); // -> "p-2 mt-6"

With React Components

import React from "react";
import cn from "utils-cn";

type TitleProps = {
  children: React.ReactNode,
  className?: string,
  size?: "sm" | "md" | "lg",
};

export default function Title({
  children,
  className,
  size = "md",
}: TitleProps) {
  return (
    <h1
      className={cn(
        "font-bold tracking-normal",
        size === "sm" && "text-xl md:text-2xl",
        size === "md" && "text-2xl md:text-4xl",
        size === "lg" && "text-3xl md:text-5xl lg:text-6xl lg:leading-tight",
        className
      )}
    >
      {children}
    </h1>
  );
}

TypeScript Support

The package includes TypeScript types:

import cn from "utils-cn";

// Full type safety with TypeScript
const className = cn(
  "base-class",
  true && "applied-class",
  false && "not-applied-class",
  { "conditional-class": true },
  ["array", "of", "classes"]
);

Why utils-cn?

  • Simple API: Just a single function with a straightforward interface
  • Tailwind-aware: Intelligently handles Tailwind's utility class conflicts
  • Tiny footprint: Minimal impact on your bundle size
  • Type-safe: Full TypeScript support included

How It Works

utils-cn combines two popular libraries:

  1. clsx - For conditionally joining class names
  2. tailwind-merge - For intelligently handling Tailwind CSS class conflicts

API Reference

function cn(...inputs: ClassValue[]): string;

Parameters

  • inputs: Any number of class values (strings, objects, arrays, undefined, null, booleans, etc.)

Returns

  • A merged string of class names with Tailwind conflicts resolved

License

MIT