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 #179

Closed
qfox opened this issue May 11, 2017 · 0 comments
Closed

parse and stringify BemjsonNodes #179

qfox opened this issue May 11, 2017 · 0 comments

Comments

@qfox
Copy link
Member

qfox commented May 11, 2017

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
Projects
None yet
Development

No branches or pull requests

2 participants