what-color
v1.0.0
Published
CLI tool to find and count all CSS color declarations in your codebase and export to CSV or HTML
Maintainers
Readme
what-color
A CLI tool to find and count all CSS color declarations in your codebase and export them to CSV or HTML with beautiful color swatches.
Features
- Detects multiple color formats:
- Hex colors:
#fff,#ffffff,#fff0,#ffffff00 - RGB/RGBA:
rgb(255, 255, 255),rgba(255, 255, 255, 0.5) - HSL/HSLA:
hsl(120, 100%, 50%),hsla(120, 100%, 50%, 0.5) - Named CSS colors:
red,blue,lightblue, etc.
- Hex colors:
- Filter by file extensions
- Respects
.gitignorefiles - Export formats:
- CSV: Simple comma-separated values with occurrence counts
- HTML: Beautiful visual report with color swatches displaying occurrence numbers
- Sorted by most frequently used colors
- Click-to-copy colors in HTML report
Installation
npm installUsage
Basic usage (search current directory, all files, CSV output)
node index.jsGenerate HTML report with color swatches
node index.js --htmlSearch specific directory
node index.js --dir ./srcSearch specific file extensions
node index.js --ext .css,.scss,.js,.jsx,.htmlSpecify output file and format
# CSV output
node index.js --output my-colors.csv
# HTML output
node index.js --output report.html --format htmlCombined options
node index.js --dir ./src --ext .css,.js --html
node index.js --dir ./src --ext .css,.scss --output colors.htmlCommand Line Options
-d, --dir <path>- Directory to search (default: current directory)-e, --ext <extensions>- Comma-separated file extensions to search (e.g.,.css,.js,.html)- If not specified, searches all files
-o, --output <file>- Output file (default:colors.csv)-f, --format <format>- Output format:csvorhtml(default:csv)--html- Shortcut to generate HTML report (sets output tocolors.html)-h, --help- Show help message
Output Formats
CSV Format
The tool generates a CSV file with two columns:
Color,Occurrences
"#fff",15
"white",12
"rgba(0, 0, 0, 0.1)",8
...HTML Format
The HTML report features:
- Beautiful color swatches with occurrence numbers displayed inside
- Interactive color details - Click any color card to see all file locations and line numbers where that color appears
- Modal popup showing:
- List of all files containing the color
- Exact line numbers for each occurrence
- Summary statistics (number of files and total occurrences)
- Copy color button
- Responsive grid layout
- Summary statistics (unique colors and total occurrences)
- Automatic contrast adjustment for text (white text on dark colors, black on light colors)
- Mobile-friendly design
- Keyboard support (Escape key to close modal)
Colors are sorted by occurrence count (most used first) in both formats.
.gitignore Support
The tool automatically reads and respects .gitignore files in the search directory. Any files or folders listed in .gitignore will be excluded from the search.
Examples
Find all colors in a React project (HTML report)
node index.js --dir ./src --ext .js,.jsx,.css,.scss --htmlFind colors only in stylesheets
node index.js --ext .css,.scss,.sass,.less --htmlAnalyze an entire website directory
node index.js --dir ./public --ext .html,.css,.js --output website-colors.htmlGenerate CSV for data processing
node index.js --dir ./src --output colors-data.csvLicense
MIT
