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 🙏

© 2024 – Pkg Stats / Ryan Hefner

bemmer

v1.1.0

Published

BEM-like simple classname builder.

Downloads

702

Readme

bemmer

bemmer is a BEM-like simple classname builder.

npm version Circle CI license

If you taking pains by handling CSS selector (such as classnames), Try the BEM with with Component oriented design with React. bemmer helps it. See Example with React.

Example

import bemmer = from 'bemmer';

const builder = bemmer.createBuilder('todoList', 'externalClassName');

builder('__items');
// => "todoList__items externalClassName__items"

builder('__items__item', { finished: true });
// => "todoList__items__item todoList__items__item--finished" +
//    "externalClassName__items__item externalClassName__items__item--finished"

API

bemmer.createBuilder()

bemmer.createBuilder(...initialClassNames: string[]): Builder

Create a builder function.

const builder = bemmer.createBuilder('todoList');

// can plural arguments, use with React
const builder = bemmer.createBuilder('todoList', this.props.className);

// parse a BEM-like full classname
const builder = bemmer.createBuilder('todoList__item--finished');

Alias: bemmer.create (not recommended)

builder

builder(elements?: string, modifiers?: object): string

Build a BEM-like full classname. When result are plural class name, It joined with whitespace. (ex. todoList__item externalClassName__item)

const builder = bemmer.createBuilder('todoList', 'main__todoList');

builder('__item', { odd: true });
// => "todoList__item todoList__item--odd main__todoList__item main__todoList__item--odd"

Use with React

Component:
const TodoList = React.createClass({
  render() {
    const b = bemmer.createBuilder('todoList', this.props.className);
    const listItems = this.props.listItems.map((listItem, i) => {
      return (
        <li className={b('item', { odd: i % 2 === 1 })}>
          <span className={b('item__title')}>
            {listItem.title}
          </span>

          <span className={b('item__createdAt')}>
            {listItem.createdAt}
          </span>
        </li>
      );
    });

    return (
      <ul className={b()}>
        {listItems}
      </ul>
    );
  },
});
Result:
<ul class="todoList classNameFromProps">
  <li class="todoList__item todoList__item--odd classNameFromProps__item classNameFromProps__item--odd">
    <span class="todoList__item__title classNameFromProps__item__title">
      v1.0.0
    </span>

    <span class="todoList__item__createdAt classNameFromProps__item__createdAt">
      2016-03-08
    </span>
  </li>

  <li class="todoList__item classNameFromProps__item">
    <span class="todoList__item__title classNameFromProps__item__title">
      v0.4.1
    </span>

    <span class="todoList__item__createdAt classNameFromProps__item__createdAt">
      2015-09-28
    </span>
  </li>

  <li class="todoList__item todoList__item--odd classNameFromProps__item classNameFromProps__item--odd">
    <span class="todoList__item__title classNameFromProps__item__title">
      v0.3.2
    </span>

    <span class="todoList__item__createdAt classNameFromProps__item__createdAt">
      2015-09-16
    </span>
  </li>
</ul>
CSS (less) Example:
.todoList
  &__item
    // ...
    &--odd
      //...
    &__title
      // ...
    &__createdAt
      // ...

It is so simple! 👏

License

MIT