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 🙏

© 2025 – Pkg Stats / Ryan Hefner

css-bem

v1.0.0

Published

1. 简化class命名规范bem书写方式,让使用bem规范变得更简单 2. 避免在react,vue 等框架中拼接classname 字符串 3. 方便样式增减,减少不必要的判断

Readme

插件说明
  1. 简化class命名规范bem书写方式,让使用bem规范变得更简单
  2. 避免在react,vue 等框架中拼接classname 字符串
  3. 方便样式增减,减少不必要的判断

使用说明

  // 安装
  npm install css-bem
  // 引入
  import cssBem, { bem, flatten, injectBem,vueMixin } from 'css-bem'
  1. 常规使用(以react为例)
  // 指定命名空间和组件名称
  const bem = cssBem('ns','button')
  /**也可以只指定一个
   * bem = cssBem('button')
  */

  // 组件
  export default class Button extend React.Component{
    render(){
      // 是否禁用 是否扁平化 类型 主题
      const {disabled,plain,type,theme = 'dark'} = this.props
      return (
        <div className={bem('wrap',[theme])}>
          <button className={bem([
            type,
            {disabled,plain}
          ])}>
            {this.props.children}
          </button>        
        </div>
      )
    }
  }
  
//页面
  export default class Page extend React.Component{
    statis {
      disabled: false
    }
    render(){
      return <Button type='primary' plain disabled={this.state.disabled}>测试按钮</Button>
    }
  }
 <!--结果-->
  <div class='ns-button__wrap ns-button__wrap--dark'>
    <button class='ns-button ns-button--primary ns-button--plain'>测试按钮</button>
  </div>

2 高阶组件

  class Button extend React.Component{
    render(){
      const {classnames} = this
      return <div className={classnames('wrap',[theme])}>
          <button className={classnames([
            type,
            {disabled,plain}
          ])}>
            {this.props.children}
          </button>        
        </div>
    }
  }

  export default injectBem('ns','button')(Button)

  // 也可以使用装饰器
  @injectBem('ns','button')
  export default class Button extend React.Component{
    render(){
      const {classnames} = this
    }
  }
  1. 只使用bem

    bem函数 用于简化组件命名空间 和 组件名重复输入的问题,主要适用于vue中使用,bem生成的结果可直接给vue的class属性

  const $bem = bem('ns','button')

console.log($bem())
/**输出
 *  'ns-button'
*/

  console.log($bem('wrap',{
    disabled:true
  }))
  /**输出
   * ['ns-button__wrap',{
   *  'ns-button__wrap--disabled':true
   * }]
   * 
  */

 console.log($bem({
   disabled:true
 }))
 /**
  * 输出
  * ['ns-button',{'ns-button--disabled':true}]
 */

console.log($bem(['normal',{
  plain: false
}]))
/**
 * ['ns-button',['ns-button--normal',{'ns-button--plain':false}]]
 * 
*/
  1. Vue中使用

 export default {
   mixins:[vueMixin('ns','button')],
   props:{
     disabled:{
       type:Boolean,
       default: false
     }
   }
 }

 <template>
  <div class={this.classnames('wrap')}>
    <button class={this.classnames([{disabled}])}></button>
  </div>
 </template>