Skip to content
This repository has been archived by the owner on Aug 19, 2019. It is now read-only.
/ classname Public archive

🔤 Helpers for composing and parsing BEM classNames

License

Notifications You must be signed in to change notification settings

rebem/classname

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

maintenance npm travis coverage deps gitter

Set of helpers for composing and parsing BEM classNames.

Install

npm i -S rebem-classname

Usage

stringify

import { stringify } from 'rebem-classname';

const className = stringify(props);

props:

block

Reference.

stringify({
    block: 'beep'
});
// "beep"
elem

Reference.

stringify({
    block: 'beep',
    elem: 'boop'
});
// "beep__boop"
mods

Reference.

stringify({
    block: 'beep',
    mods: {
        foo: 'bar'
    }
});
// "beep beep_foo_bar"
stringify({
    block: 'beep',
    mods: {
        foo: true,
        bar: false
    }
});
// "beep beep_foo"
stringify({
    block: 'beep',
    elem: 'boop',
    mods: {
        foo: 'bar'
    }
});
// "beep__boop beep__boop_foo_bar"
mix

Reference.

stringify({
    block: 'beep',
    mix: {
        block: 'boop',
        elem: 'foo'
    }
});
// "beep boop__foo"
stringify({
    block: 'beep',
    mix: [
        {
            block: 'boop',
            elem: 'foo'
        },
        {
            block: 'bar',
            elem: 'baz',
            mods: {
                test: true
            }
        }
    ]
});
// "beep boop__foo bar__baz bar__baz_test"
className
stringify({
    block: 'boop'
    className: 'beep'
});
// "boop beep"

validate

Checks if BEMJSON is valid and throws warnings into console if it's not. Returns the same BEMJSON back.

import { validate } from 'rebem-classname';

validate({
    elem: 'boop'
});
// "you should provide block along with elem Object{elem: 'boop'}"

parse

TODO

Custom delimeters

Default delimeters are _ for modifiers and __ for elements, but you can change them with special environment variables:

plugins: [
    new webpack.DefinePlugin({
        'process.env': {
            REBEM_MOD_DELIM: JSON.stringify('--'),
            REBEM_ELEM_DELIM: JSON.stringify('~~')
        }
    })
]