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

@kitbag/bem-modules

v1.0.0

Published

Type-safe BEM utility — autocomplete your blocks, elements, and modifiers

Readme

@kitbag/bem-modules

Type-safe BEM helper — autocomplete your blocks, elements, and modifiers.

License: MIT Types: included

Why

BEM is a great naming convention, but using it means writing class names like card__title--highlighted by hand — which is tedious, error-prone, and noisy. With CSS Modules it's even worse: styles['card__title--highlighted'].

bem-modules gives you a clean function call, bound to your component's block, and works two ways:

Without CSS Modules — builds raw BEM class strings. A lightweight alternative to concatenating while also ensuring the modifiers get applied correctly.

import { useBem } from '@kitbag/bem-modules'

const bem = useBem('navBar')

bem('item', { active: true })
// → 'nav-bar__item nav-bar__item--active'

With CSS Modules — looks up hashed class names from your styles object with full autocomplete for every block, element, and modifier that exists in your stylesheet.

import { useBem } from '@kitbag/bem-modules'
import styles from './card.module.css'

const bem = useBem(styles, 'card')

bem('title', { highlighted: true })
// → '_card__title_x2 _card__title--highlighted_x3'

Why BEM + CSS Modules?

In many ways, both BEM and CSS Modules aim to make styles modular and avoid cross-component interference, but BEM does it via a naming convention in a global namespace, while CSS Modules do it via tooling and local scope.

BEM gives you meaningful structure. Class names like card__title--highlighted tell you what a class is (a title inside a card), what state it represents (highlighted), and how it relates to other classes. This structure is visible in devtools, making debugging straightforward.

CSS Modules give you scoping. They guarantee your class names won't collide with anything else in the application. Even if two components both have a .title class, the generated hashes (like _title_x7f2a) protect styles from leaking between them.

Together they provide a powerful combination of readability, enforced structure, and isolation.

  • Without BEM, CSS Modules class names are flat and unstructured — you lose the ability to see component relationships at a glance in devtools.
  • Without CSS Modules, BEM relies on discipline alone to avoid collisions across a large codebase.

Installation

Install @kitbag/bem-modules with your favorite package manager:

# bun
bun add @kitbag/bem-modules
# yarn
yarn add @kitbag/bem-modules
# npm
npm install @kitbag/bem-modules

Quick start

Call useBem with your component's block, then use the returned bem for the block, its elements, and their modifiers:

import { useBem } from '@kitbag/bem-modules'

const bem = useBem('card')

bem()                                // 'card'
bem('title')                         // 'card__title'
bem('title', { highlighted: true })  // 'card__title card__title--highlighted'
bem({ featured: true })              // 'card card--featured'

Inputs are converted to kebab-case, so with useBem('navBar'), bem('listItem', { isActive: true }) gives 'nav-bar__list-item nav-bar__list-item--is-active'.

With CSS Modules

TypeScript infers the valid blocks, elements, and modifiers from your styles object — rename a class in CSS and every stale usage becomes a type error.

In React

/* card.module.css */
.card { /* ... */ }
.card--featured { /* ... */ }
.card__title { /* ... */ }
.card__title--highlighted { /* ... */ }
.card__title--large { /* ... */ }
.card__body { /* ... */ }
import { useBem } from '@kitbag/bem-modules'
import styles from './card.module.css'

const bem = useBem(styles, 'card')

function Card({ title, featured }: { title: string, featured: boolean }) {
  const [isHighlighted, setIsHighlighted] = useState(false)

  return (
    <div className={bem({ featured })}>
      <h2 className={bem('title', { highlighted: isHighlighted })}>{title}</h2>
      <div className={bem('body')} />
    </div>
  )
}

In Vue

<script setup lang="ts">
  import { useBem } from '@kitbag/bem-modules'
  import { ref, useCssModule } from 'vue'

  defineProps<{ title: string }>()

  const styles = useCssModule()
  const bem = useBem(styles, 'card')

  const isHighlighted = ref(false)
</script>

<template>
  <div :class="bem()">
    <h2 :class="bem('title', { highlighted: isHighlighted })">{{ title }}</h2>
    <div :class="bem('body')"></div>
  </div>
</template>

<style module>
  .card {
    /* ... */
  }
  .card__title {
    /* ... */
  }
</style>

Conditional modifiers

Modifiers are an object mapping modifier names to booleans — only truthy entries are applied, which makes toggling classes from state straightforward:

const bem = useBem(styles, 'card')

bem('title', {
  highlighted: true,
  large: isLarge,       // included only when isLarge is truthy
  active: isActive,     // included only when isActive is truthy
})

Pass the object in place of the element to modify the block itself:

bem({ featured: isFeatured })

With a styles object, modifier keys are typed per block/element, so bem('title', { featured: true }) is a type error when .card__title--featured doesn't exist.

Without a bound block

If you need classes from more than one block in the same place, leave the block off and pass it as the first argument instead. The package also exports bem, which is useBem() ready to use:

import { bem, useBem } from '@kitbag/bem-modules'

bem('card', 'title', { highlighted: true })   // 'card__title card__title--highlighted'
bem('card', { featured: true })               // 'card card--featured'

const cssBem = useBem(styles)
cssBem('nav-bar', 'item', { active: true })   // typed against every block in styles

| Call | Returns | | --- | --- | | useBem(block) | bem(element?, modifiers?) / bem(modifiers) | | useBem(styles, block) | Same, typed and looked up against styles | | useBem() | bem(block, element?, modifiers?) / bem(block, modifiers) | | useBem(styles) | Same, typed and looked up against styles |


Development

npm install      # install dependencies
npm test         # run the test suite once (vitest)
npm run test:watch
npm run build    # bundle with tsup → dist/

License

MIT