-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
31 lines (26 loc) · 821 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const Color = require('color');
function generateGradient(startColor, endColor, direction) {
const start = Color(startColor);
const end = Color(endColor);
// Generate the CSS gradient based on the specified direction
let gradient = '';
switch (direction) {
case 'to top':
gradient = `to top, ${start.hex()}, ${end.hex()}`;
break;
case 'to bottom':
gradient = `to bottom, ${start.hex()}, ${end.hex()}`;
break;
case 'to left':
gradient = `to left, ${start.hex()}, ${end.hex()}`;
break;
case 'to right':
gradient = `to right, ${start.hex()}, ${end.hex()}`;
break;
default:
gradient = `to bottom, ${start.hex()}, ${end.hex()}`;
break;
}
return `background: linear-gradient(${gradient});`;
}
module.exports = generateGradient;