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

unbem

v0.0.2

Published

A small utility for working with BEM in Javascript

Readme

unbem

A tiny ~330 byte utility for working with BEM classes and CSS-modules in Javascript

Motivation

Working with BEM in Javascript can be a pain, especially if you are using CSS Modules and JSX.

Having to write stuff like className={styles['my-block__my-element--modifier']} gets old fast. Then you find yourself concatinating and conditionally applying classes, and you soon wish upon death.

// THIS IS NOT FUN

import styles from './MyComponent.css'

const MyComponent = props => {
  const classes = [
    styles.block__element,
    styles['block__element--some-modifier'],
    props.magicNumber === 42 && styles['block__element--unhappy']
  ].filter(Boolean).join(' ')

  return (
    <h1 className={classes}>
      Hello, world!
    </h1>
  )
}

Solution

Installation

npm install unbem

Usage

Unbem delivers two functions: unbem and bind.

The unbem function

It expects the first argument to be either a block or an element. The rest of the arguments get applied as modifiers to the if the string starts with --. Falsy arguments are omitted.

import { unbem } from 'unbem'
import styles from './MyComponent.css'

const magicNumber = 42

const classes = unbem(
  'block__element',
  '--happy',
  magicNumber === 42 && '--super-happy'
)

console.log(classes)
// > "block__element block__element--happy block__element--super-happy"

If the string does not start with -- the class gets append in its entirety.

const classes = unbem(
  'block__element',
  'something__else',
  magicNumber === 42 && '--cool'
)

// > "block__element something__else something__else--cool"

Notice how the --cool modifier gets applied to the something__else element, not the block__element. The modifier gets applied to the previous non-modifier.

The bind function

Unbem comes with a useful function for when you are using CSS modules. The bind function returns an unbem function that is bound to a CSS module object.

import { bind } from 'unbem'
import styles from './component.css'

const unbem = bind(styles)

const myClasses = unbem('my__block', '--active')
// > "prefix-my__block[hash] prefix-my__block--active[hash]

Improving conditionally applying classes

Unbem has a similiar API to the well known classnames package often used in React projects.

Every argument you pass in can be either an a string, object, or an array. If the argument is falsy it will be ignored.

Strings

const classes = unbem('block__element', '--happy', somethingTruthy && '--super-happy')
// > "block__element block__element--happy, block__element--super-happy"

Objects

Every key on the object gets appended if the value is truthy.

const classes = unbem('block__element', { ['--happy']: magicNumber === 42 })
// > "block__element block__element--happy"

Arrays

Unbem resolves each items in the array. You can even have arrays inside arrays (but don't).

const classes = unbem('block__element', [
  '--happy',
  { ['--super-happy']: 2 + 2 === 4 },
  somethingFalsy && '--not-happy'
])

// > "block__element block__element--happy block__element--super-happy"