-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilehandler.js
More file actions
48 lines (42 loc) · 1.46 KB
/
filehandler.js
File metadata and controls
48 lines (42 loc) · 1.46 KB
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
import { getStyles, getPropsTally, getHexColorTally } from './styles.js';
const handleFileRead = (error, content) => {
let string = '';
let cssColorTally = {};
let cssPropsTally = {};
// retrieve styles
const styles = getStyles(content);
// remove braces from styles
const trimmedStyles = styles.map((style) => style.substring(1, style.length - 1).trim());
// get tally of all properties in a stylesheet
cssPropsTally = getPropsTally(trimmedStyles);
// get tally of all colors in a stylesheet
cssColorTally = getHexColorTally(trimmedStyles);
// read all entries in COLOR_TALLY_ARR
// combine in a string to be printed
const colorTallyArr = Object
.entries(cssColorTally)
.sort((a, b) => b[1] - a[1]);
// read all entries in COLOR_TALLY_ARR
// combine in a string to be printed
const cssPropsTallyArr = Object
.entries(cssPropsTally)
.sort((a, b) => b[1] - a[1]);
if (colorTallyArr.length > 0) {
string += '-------\ncolours:\n-------\n';
}
for (let i = 0; i < colorTallyArr.length; i += 1) {
string += `${colorTallyArr[i][0]}: ${colorTallyArr[i][1]}`;
string += '\n';
}
if (cssPropsTallyArr.length > 0) {
string += '-------\nstyles:\n-------\n';
}
for (let i = 0; i < cssPropsTallyArr.length; i += 1) {
string += `${cssPropsTallyArr[i][0]}: ${cssPropsTallyArr[i][1]}`;
if (i !== cssPropsTallyArr.length - 1) {
string += '\n';
}
}
console.log(string);
};
export default handleFileRead;