-
Notifications
You must be signed in to change notification settings - Fork 0
/
color.js
38 lines (31 loc) · 1.08 KB
/
color.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
const fs = require('fs');
const path = require('path');
// Extract the filename from command line arguments
const fileName = process.argv[2]; // The filename will be the third argument (index 2)
if (!fileName) {
console.error('Please provide a CSS file name.');
process.exit(1);
}
const filePath = path.join(__dirname, fileName); // Use the provided filename
try {
const css = fs.readFileSync(filePath, 'utf8');
const colorMatches = css.match(/#[0-9A-Fa-f]{3,6}/g);
// Using a Set to store unique colors
const uniqueColors = new Set();
if (colorMatches) {
colorMatches.forEach(color => {
// Check if the color is not already in the uniqueColors Set
if (!uniqueColors.has(color)) {
uniqueColors.add(color);
}
});
console.log('Colors used in css file:');
uniqueColors.forEach(color => {
console.log(`\u2022 ${color}`); // Prints each color as a bullet point
});
} else {
console.log('No colors found in the CSS file.');
}
} catch (err) {
console.error('Error reading the file:', err);
}