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

twl

v0.4.3

Published

The cn API with macro compilation for Tailwind class names

Readme

The cn API with macro compilation. No extra function names to learn.

Install

pnpm add twl

Runtime API

twl exposes the cn API. Its cn, clsx, and twMerge functions also support commented templates. ClassValue and ClassNameValue are available as types.

import { cn, clsx, twMerge } from 'twl'
import type { ClassValue } from 'twl'

cn('p-2', { 'p-4': true }) // 'p-4'
clsx('p-2', { 'p-4': true }) // 'p-2 p-4'
twMerge('p-2', ['p-4']) // 'p-4'

Compiled runtime

twl/runtime directly re-exports cn, clsx, and twMerge from cn, without template handling. The compiler emits imports from this entry.

import { cn as __twl_cn } from 'twl/runtime'

const className = __twl_cn('flex items-center', variant)

Macro API

Import the same names from twl/macro to enable commented templates and build-time compilation. Ordinary function calls keep their original behavior.

import { cn, clsx, twMerge } from 'twl/macro'

cn`
  // spacing
  p-2 p-4
` // 'p-4'
clsx`p-2 p-4` // 'p-2 p-4'
twMerge`p-2 p-4` // 'p-4'

cn`flex ${['p-2', { 'p-4': true }]}` // 'flex p-4'
twMerge`p-2 ${['p-4', false]}` // 'p-4'
cn('p-2', { 'p-4': true }) // ordinary calls still work

All three template tags collapse whitespace and strip // line comments. Comments only start at token boundaries, so bg-[url(https://a.com/x.png)] and content-['//'] are preserved.

| Macro | Interpolations | Tailwind conflicts | | --------- | ----------------------------------------------------- | ------------------ | | cn | ClassValue, including objects and arrays | Merged | | clsx | ClassValue, including objects and arrays | Preserved | | twMerge | ClassNameValue, including strings and nested arrays | Merged |

The macro entry contains only type declarations for cn, clsx, and twMerge. Compiled code imports twl/runtime, which directly re-exports cn, clsx, and twMerge from cn. The twl entry provides template support. The macro entry requires the compiler plugin. To run without compilation, import from twl instead. There are no cls, tw, or standalone macro function exports.

Compiler

// vite.config.ts
import twl from 'twl/vite'

export default { plugins: [twl()] }

Static templates compile to string literals: cn and twMerge also resolve conflicts at build time. Dynamic templates become direct calls to the matching cn, clsx, or twMerge function, with normalized static strings and original expressions as separate arguments. No template literal is emitted. Ordinary function calls are redirected to twl/runtime, which re-exports the original functions from cn.

Also available: twl/rollup, twl/rolldown, twl/webpack, twl/rspack, twl/esbuild, twl/farm, and twl/unplugin.

Next.js

// next.config.ts
import { withTwl } from 'twl/next'

export default withTwl()({ reactCompiler: true })

withTwl() registers the loader on both Turbopack and webpack.

Options

| Option | Default | Purpose | | --------- | ------------------- | ----------------------------------------------------------------------------- | | from | ['twl/macro'] | Module specifiers exposing the macro API, including custom re-export modules. | | include | /\.[cm]?[jt]sx?$/ | Files to compile. Next.js uses its own loader rule. | | exclude | /node_modules/ | Skip dependencies. |

The compiler rejects namespace imports, local bindings that shadow macro imports, and interpolations inside comments. Diagnostics include file and line.

Limitations

prettier-plugin-tailwindcss can reorder comments inside class templates. Use // prettier-ignore on the attribute when needed.

Credits

  • https://github.com/shadcn-ui/cn
  • https://github.com/yunsii/tagged-classnames-free