2.0.1 • Published 7 months ago

bem-class-utils v2.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
7 months ago

Modern BEM Class Manager 🎨

A lightweight, TypeScript-first utility for managing BEM classes in modern web applications.

npm version Bundle Size TypeScript

✨ Features

  • 🚀 Modern TypeScript implementation
  • 🎯 Zero dependencies
  • 🔍 Smart BEM class detection
  • 🛠️ Flexible modifier management
  • ⚡ Tree-shakeable ESM support
  • 🎨 Customizable separators

📦 Installation

npm install modern-bem-class-manager

or

yarn add modern-bem-class-manager

or

pnpm add modern-bem-class-manager

🚀 Quick Start

import { createBEM } from 'modern-bem-class-manager';

// Create a BEM instance
const bem = createBEM('card');

// Use it in your components
const className = bem({
  element: 'title',
  modifiers: ['large', { highlighted: true }]
});
// Result: 'card__title card__title--large card__title--highlighted'

🎯 Usage with React

import { createBEM } from 'modern-bem-class-manager';

const Card = ({ isHighlighted, size = 'medium' }) => {
  const bem = createBEM('card');
  
  return (
    <div className={bem({ modifiers: [{ highlighted: isHighlighted }] })}>
      <h2 className={bem({ element: 'title', modifiers: [size] })}>
        Hello World
      </h2>
      <p className={bem({ element: 'content' })}>
        Content goes here
      </p>
    </div>
  );
};

⚙️ Configuration

const bem = createBEM('block', {
  elementSeparator: '__',  // Default
  modifierSeparator: '--', // Default
  strict: true            // Enables strict mode
});

🔧 API Reference

createBEM(block: string, options?: BEMOptions)

Creates a new BEM instance for the given block name.

Options

OptionTypeDefaultDescription
elementSeparatorstring'__'Separator between block and element
modifierSeparatorstring'--'Separator for modifiers
strictbooleanfalseEnables strict mode validation

📝 License

MIT © Your Name


2.0.1

7 months ago

1.0.0

7 months ago