From 1aed2a684b0f290fad2b17ea665a5a218d94c3b6 Mon Sep 17 00:00:00 2001 From: Nikolay Kostyurin Date: Mon, 6 Aug 2018 02:44:27 +0200 Subject: [PATCH] refactor(preset-html5): optimize style tag functions --- packages/bbob-preset-html5/lib/index.js | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/packages/bbob-preset-html5/lib/index.js b/packages/bbob-preset-html5/lib/index.js index 606a563..27fc4ee 100644 --- a/packages/bbob-preset-html5/lib/index.js +++ b/packages/bbob-preset-html5/lib/index.js @@ -6,20 +6,17 @@ const isTagNode = node => (typeof node === 'object' && Boolean(node.tag)); const isTagOf = (node, type) => (node.tag === type); const createTagNode = tag => ({ tag, attrs: {}, content: [] }); -const getStyleFromAttrs = (attrs) => { - const styles = []; - - if (attrs.color) { - styles.push(`color:${attrs.color};`); - } - - if (attrs.size) { - styles.push(`font-size:${attrs.size};`); - } - - return styles.join(' '); +const styleMap = { + color: val => `color:${val};`, + size: val => `font-size:${val};`, }; +const getStyleFromAttrs = attrs => + Object + .keys(attrs) + .reduce((acc, key) => (styleMap[key] ? acc.concat(styleMap[key](attrs[key])) : acc), []) + .join(' '); + const asListItems = (content) => { const listItems = []; let listIdx = 0;