Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const el = (tag, attrs, body) => `${renderTag(tag, attrs)}${renderBody(body)}${renderClosingTag(tag)}`;
- const renderTag = (tag, attrs) => `<${tag}${renderAttrs(attrs)}>`;
- const renderAttrs = attrs => `${hasAttrs(attrs) ? ' ' : ''}${joinAttrs(attrs)}`;
- const hasAttrs = attrs => Object.keys(attrs || {}).length > 0;
- const joinAttrs = attrs => Object.entries(attrs).map(attr => attrToString(attr)).join(' ');
- const attrToString = ([key, value]) => `${key}="${value}"`;
- const renderBody = body => body.join('');
- const renderClosingTag = tag => isClosingTag ? `</${tag}>` : '';
- const isClosingTag = tag => !tagsWithoutClosing.includes(tag);
- const tagsWithoutClosing = ['input'];
- const text = txt => txt.toString();
- const div = (attrs, ...body) => el('div', attrs, body);
- const span = (attrs, ...body) => el('span', attrs, body);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement