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

nano-classnames

v1.0.3

Published

🧹 A bite-size utility for composing classnames.

Readme

  • 2.3kb unzipped (271 B gzipped)
  • Full TypeScript support
  • Works with all modern frameworks

Table of contents

⚡️ Getting started

First, install nano-classnames via npm/yarn/pnpm:

npm i nano-classnames
yarn add nano-classnames 
pnpm i nano-classnames

Then import the class constructor in your project:

import { cn } from "nano-classnames"

You can now compose your classnames:

<div class={cn("class-1", "class-2")}>...</div>
 
//<div class="class-1 class-2">...<div>

Read the documention to learn more about composing classes with nano-classnames.

🤔 Why nano-classnames

nano-classnames was inspired from the great classnames package with an emphasis on speed and composability. While I love classnames, I found its syntax for conditional classnames to be disruptive as you must use an object to apply conditional classes, which can be clunky to work with. nano-classnames does away with this by using tuples (an array) to quickly apply conditional classes.

nano-classnames also only supports strings for composing classes (hence "nano"). This is an intentional design choice as, personally, I never use nested arrays/objects when composing classes. If you need to use them for composing classes then I recommend using classnames.

nano-classnames is not a drop-in replacement for classnames

📖 Documentation

By design, nano-classnames is meant to be extremely lightweight and straightforward. It works great if you're using TailwindCSS!

Using cn to compose classes

cn is the class constructor, it allows you to quickly compose classes together.

You can import cn from nano-classnames using a named import:

import { cn } from "nano-classnames"

Then use cn like this:

cn("text-red-500 text-lg", "font-bold") ➡️ "text-red-500 text-lg font-bold"

We only support string inputs! If you need to use arrays, objects, or nested arrays/objects then refer to classnames for a more robust solution!

Conditionally apply classnames

To conditionally apply classnames, use a tuple (an array)! These tuples are formatted like this:

[boolean, trueClassnames, falseClassnames]

You can then pass these into the cn constructor:

let state = true;

cn([state, "text-red-500"]) ➡️ "text-red-500"

You can also pass a third value to represent an else state:

let state = true;

cn([state, "text-red-500", "text-blue-500"]) ➡️ "text-blue-500"

You can also pass in a variable (so as long as it is a string!)

let classes = "..."

cn(classes) ➡️ "..."

⚙️ API

cn(...classes)

  • ...classes: (string | [boolean, string, string])[]
  • Returns string