Skip to content
This repository was archived by the owner on Dec 15, 2024. It is now read-only.

Commit a6d02a4

Browse files
committed
Cleaner code?
1 parent 9aa87b5 commit a6d02a4

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

index.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
const _ = require('lodash');
22
const Color = require('color');
33

4-
const colorsAreSupported = function(colors) {
4+
const normalizeColors = function(colors, transparentFirst = true) {
5+
colors = _.castArray(colors);
56
const unsupportedColorKeywords = ['inherit', 'initial', 'unset', 'revert'];
6-
return _.intersection(unsupportedColorKeywords, colors).length === 0;
7-
};
8-
9-
const listColors = function(colors, transparentFirst = true) {
7+
if (_.intersection(unsupportedColorKeywords, colors).length > 0) {
8+
return null;
9+
}
1010
if (colors.length === 1) {
1111
const color = colors[0];
1212
let transparentColor = 'transparent';
@@ -18,7 +18,7 @@ const listColors = function(colors, transparentFirst = true) {
1818
}
1919
colors = transparentFirst ? [transparentColor, color] : [color, transparentColor];
2020
}
21-
return colors.join(', ');
21+
return colors;
2222
};
2323

2424
module.exports = function() {
@@ -67,13 +67,13 @@ module.exports = function() {
6767
const linearGradientUtilities = (function() {
6868
let utilities = {};
6969
_.forEach(linearGradientColors, (colors, colorKey) => {
70-
colors = _.castArray(colors);
71-
if (!colorsAreSupported(colors)) {
70+
colors = normalizeColors(colors, true);
71+
if (!colors) {
7272
return; // continue
7373
}
7474
_.forEach(linearGradientDirections, (direction, directionKey) => {
7575
utilities[`.${e(`bg-gradient-${directionKey}-${colorKey}`)}`] = {
76-
backgroundImage: `linear-gradient(${direction}, ${listColors(colors, true)})`,
76+
backgroundImage: `linear-gradient(${direction}, ${colors.join(', ')})`,
7777
};
7878
});
7979
});
@@ -83,15 +83,15 @@ module.exports = function() {
8383
const radialGradientUtilities = (function() {
8484
let utilities = {};
8585
_.forEach(radialGradientColors, (colors, colorKey) => {
86-
colors = _.castArray(colors);
87-
if (!colorsAreSupported(colors)) {
86+
colors = normalizeColors(colors, false);
87+
if (!colors) {
8888
return; // continue
8989
}
9090
_.forEach(radialGradientPositions, (position, positionKey) => {
9191
_.forEach(radialGradientSizes, (size, sizeKey) => {
9292
_.forEach(radialGradientShapes, (shape, shapeKey) => {
9393
utilities[`.${e(`bg-radial${shapeKey === 'default' ? '' : `-${shapeKey}`}${sizeKey === 'default' ? '' : `-${sizeKey}`}${positionKey === 'default' ? '' : `-${positionKey}`}-${colorKey}`)}`] = {
94-
backgroundImage: `radial-gradient(${shape} ${size} at ${position}, ${listColors(colors, false)})`,
94+
backgroundImage: `radial-gradient(${shape} ${size} at ${position}, ${colors.join(', ')})`,
9595
};
9696
});
9797
});

0 commit comments

Comments
 (0)