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

@corvallo/bem-forge

v1.0.3

Published

Typed BEM class name builder for React/TS (works with clsx)

Readme

🔧 @corvallo/bem-forge

npm version npm downloads CI

A flexible and fully typed utility library for managing BEM-style class names in React, with support for modifiers, compound modifiers, CSS Modules, and automatic class merging. Why bem-forge?

  • Fully typed BEM blocks & modifiers
  • Zero string concatenation
  • Works with CSS Modules
  • Prevents invalid class names at compile time

✨ Features

  • ✅ Single config factory (bem({...})) for blocks + elements
  • ✅ Fully typed modifier system (ModifierProps, ModifierTypes)
  • ✅ Support for compound modifiers
  • bem.bind for seamless integration with CSS Modules
  • ✅ Automatic class merging via clsx
  • ✅ Optional modifier formatting (--value or --key-value)

🚀 Installation

pnpm add @corvallo/bem-forge
# or
npm install @corvallo/bem-forge
# or
yarn add @corvallo/bem-forge

📦 Quick Overview

import { bem, type ModifierTypes } from "@corvallo/bem-forge";
import styles from "./Button.module.scss";

const button = bem({
  block: "button",
  modifiers: {
    size: ["sm", "md", "lg"],
    variant: ["primary", "secondary"],
    fullWidth: [true, false],
  },
  defaultModifiers: { size: "md" },
  compoundModifiers: [{ modifiers: { fullWidth: true }, class: "button--full-width" }],
  elements: {
    icon: {
      modifiers: {
        side: ["left", "right"],
      },
    },
  },
});

export const buttonClasses = bem.bind(styles, button);
export type ButtonVariants = ModifierTypes<typeof button>;

Then consume it inside React:

type ButtonProps = {
  size?: ButtonVariants["block"]["size"];
  variant?: ButtonVariants["block"]["variant"];
  iconSide?: ButtonVariants["elements"]["icon"]["side"];
} & React.ButtonHTMLAttributes<HTMLButtonElement>;

export const Button = ({ size, variant, iconSide, className, children, ...rest }: ButtonProps) => (
  <button className={buttonClasses.block({ size, variant }, className)} {...rest}>
    <span className={buttonClasses.elements.icon({ side: iconSide })} aria-hidden />
    {children}
  </button>
);

Every builder accepts a second argument, so extra className values are merged via clsx.


🧱 API

bem(options)

Creates a block factory (and optional element factories) from a single config.

const card = bem({
  block: "card",
  modifiers: { size: ["sm", "lg"] },
  elements: {
    header: { modifiers: { align: ["left", "center"] } },
  },
});

Call card.block(props, extras?) and card.elements.header(props, extras?) to build class strings.

bem.bind(styles, factory)

Transforms an entire factory into CSS Module aware helpers.

const cardClasses = bem.bind(styles, card);

cardClasses.block({ size: "sm" }, "custom"); // → "_card_x _card--sm_x custom"
cardClasses.elements.header({ align: "left" });

✅ Modifier Options

In BEM only elements use __ (e.g. block__element), while modifiers are always appended with --.... The modifierFormat option just decides whether you emit --value or --key-value.

| Option | Description | | ------------------- | ---------------------------------------------------------- | | modifiers | A list of modifier keys with possible values | | defaultModifiers | Default values applied when no modifier is passed | | compoundModifiers | Apply custom class(es) when specific modifier values match | | modifierFormat | Controls how modifier classes are suffixed (--value vs --key-value) |

const modal = bem({
  block: "modal",
  modifiers: {
    size: ["sm", "lg"], // ← `modifiers`
  },
  defaultModifiers: {
    size: "sm", // ← `defaultModifiers`
  },
  compoundModifiers: [
    {
      modifiers: { size: "lg" },
      class: "modal--emphasis",
    },
  ], // ← `compoundModifiers`
});

modal.block({ size: "lg" }); // default => "modal modal--lg"

const modalKeyValue = bem({
  block: "modal",
  modifiers: { size: ["sm", "lg"] },
  modifierFormat: "key-value",
});

modalKeyValue.block({ size: "lg" }); // => "modal modal--size-lg"

// elements follow the same rule: base with "__", modifier with "--"
const footer = bem({
  block: "modal",
  elements: {
    footer: { modifiers: { align: ["start", "end"] }, modifierFormat: "key-value" },
  },
});

footer.elements.footer({ align: "end" }); // "modal__footer modal__footer--align-end"

🧩 Compound Modifiers

compoundModifiers: [
  {
    modifiers: { variant: "primary", size: "lg" },
    class: "button--highlight",
  },
];

🎨 CSS Modules Integration

bem.bind(styles, factory) maps every class generated by the factory to its CSS Module token, so you can keep working with clean names while React receives the hashed version. No more manual styles[className] lookups.


🧠 Typing Utility

ModifierTypes<typeof factory> returns the modifier prop types for blocks and elements:

type ButtonVariants = ModifierTypes<typeof button>;

const size: ButtonVariants["block"]["size"]; // "sm" | "md" | "lg"
const iconSide: ButtonVariants["elements"]["icon"]["side"]; // "left" | "right"

📁 Folder Structure Recommendation

src/
├── components/
│   └── Button/
│       ├── Button.tsx
│       ├── Button.module.scss
│       └── button.variants.ts