-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
59 lines (52 loc) · 1.44 KB
/
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
function camelToKebabCase(camel) {
return camel.replace(/([A-Z])/g, "-$1").toLowerCase();
}
function themes(type) {
const colors = {
primary: 210,
secondary: 220,
success: 120,
info: 200,
warning: 40,
help: 280,
danger: 0,
};
switch (type) {
case "primary":
return `hsl(${colors.primary}, 85%, calc(50 * 1%))`;
case "danger":
return `hsl(${colors.danger}, 85%, calc(50 * 1%))`;
case "help":
return `hsl(${colors.help}, 85%, calc(50 * 1%))`;
case "info":
return `hsl(${colors.info}, 85%, calc(50 * 1%))`;
case "secondary":
return `hsl(${colors.secondary}, 85%, calc(50 * 1%))`;
case "success":
return `hsl(${colors.success}, 85%, calc(50 * 1%))`;
case "warning":
return `hsl(${colors.warning}, 85%, calc(50 * 1%))`;
default:
return type;
}
}
function styledConsole(text, styles = {}, theme = "primary", delay = 0) {
const defaultStyles = {
color: "#fff",
fontSize: "16px",
background: themes(theme),
padding: "10px",
};
const combinedStyles = { ...defaultStyles, ...styles };
try {
const stylesObj = Object.entries(combinedStyles)
.map(([key, value]) => `${camelToKebabCase(key)}: ${value}`)
.join("; ");
setTimeout(() => {
console.log(`%c${text}`, stylesObj);
}, delay);
} catch (error) {
if (error instanceof Error) throw new Error(error.message);
}
}
export default styledConsole;