Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parse and stringify BemjsonNodes #3

Open
Yeti-or opened this issue Jun 6, 2017 · 0 comments
Open

parse and stringify BemjsonNodes #3

Yeti-or opened this issue Jun 6, 2017 · 0 comments

Comments

@Yeti-or
Copy link
Member

Yeti-or commented Jun 6, 2017

original: bem/bem-sdk#179

BemjsonMods = Map<String, String>
BemjsonNode = {
  block: String,
  elem: ?String,
  mods: ?BemjsonMods,
  elemMods: ?BemjsonMods,
  mix: ?Array<BemjsonNode|String>
};

stringifyBemjsonNode(Object|BemjsonNode);
parseBemjsonNode(String);


// ex

const n = parseBemjsonNode("b__e b__e_m_b x x_m_v");
// → BemjsonNode<{
    block: 'b',
    elem: 'e',
    elemMods: {m: 'b'},
    mix: [
        BemjsonNode<{
            block: 'x',
            mods: {m: 'v'}
        }>
    ]
}>
n.block; // → 'b'
n.mix[0].block; // → 'x'

stringifyBemjsonNode(new BemjsonNode({
    block: 'b',
    elem: 'e',
    elemMods: {m: 'b'},
    mix: {
        block: 'x',
        mods: {m: '1'},
        mix: { elem: 'huem', elemMods: { q: '2' } }
    }
}));
// → "b__e b__e_m_b x x_m_1 x__huem x__huem_q_2"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant