From 627167ba2818b29c89af10ac845ab19eb6552fea Mon Sep 17 00:00:00 2001 From: 20lives Date: Sun, 25 Oct 2020 21:20:46 +0200 Subject: [PATCH] Refactor flattenColorPalette util function --- src/util/flattenColorPalette.js | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/src/util/flattenColorPalette.js b/src/util/flattenColorPalette.js index 1a94e1802aac..de094a3cb0c7 100644 --- a/src/util/flattenColorPalette.js +++ b/src/util/flattenColorPalette.js @@ -1,19 +1,12 @@ -import _ from 'lodash' +const flattenColorPalette = (colors) => + Object.assign( + ...Object.entries(colors).flatMap(([color, values]) => + typeof values == 'object' + ? Object.entries(flattenColorPalette(values)).map(([number, hex]) => ({ + [color + (number === 'DEFAULT' ? '' : `-${number}`)]: hex, + })) + : [{ [`${color}`]: values }] + ) + ) -export default function flattenColorPalette(colors) { - const result = _(colors) - .flatMap((color, name) => { - if (_.isFunction(color) || !_.isObject(color)) { - return [[name, color]] - } - - return _.map(flattenColorPalette(color), (value, key) => { - const suffix = key === 'DEFAULT' ? '' : `-${key}` - return [`${name}${suffix}`, value] - }) - }) - .fromPairs() - .value() - - return result -} +export default flattenColorPalette