Something went wrong. Try again.
Library to rectify mistakes in the design of CSS. npmx.dev/package/@declanchidlow/fixcss
webdev front-end css fixcss
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162#!/usr/bin/env node
var fs = require("fs");var path = require("path");var { fixCSS, convertCCW } = require("./fixcss.js");
var args = process.argv.slice(2);
var opts = { fixShorthandDefaults: true, fixAxisOrder: true, fixSelectorCombinators: true, ccwShorthand: false, outputFile: null, inputFile: null, watch: false, stdin: false,};
for (var i = 0; i < args.length; i++) { var arg = args[i]; switch (arg) { case "-o": case "--output": opts.outputFile = args[++i]; break; case "-w": case "--watch": opts.watch = true; break; case "--no-shorthand": opts.fixShorthandDefaults = false; break; case "--no-axis": opts.fixAxisOrder = false; break; case "--no-combinators": opts.fixSelectorCombinators = false; break; case "--ccw": opts.ccwShorthand = true; break; case "--stdin": opts.stdin = true; break; case "-h": case "--help": console.log( [ "FixCSS CLI — Fixes CSS mistakes", "", "Usage:", " fixcss input.css > output.css", " fixcss input.css -o output.css", " fixcss --stdin < input.css", " cat input.css | fixcss --stdin", "", "Options:", " -o, --output <file> Write output to file", " -w, --watch Watch file for changes", " --no-shorthand Don't fix shorthand defaults", " --no-axis Don't fix axis order (V→H swap)", " --no-combinators Don't fix selector combinators", " --ccw Enable CCW→CW shorthand conversion", " --stdin Read from stdin", " -h, --help Show this help", ].join("\n"), ); process.exit(0); break; default: if (arg[0] !== "-") { opts.inputFile = arg; } break; }}
function processCSS(input, sourcePath) { try { var converter = opts.ccwShorthand ? convertCCW : fixCSS; var output = converter(input, { fixShorthandDefaults: opts.fixShorthandDefaults, fixAxisOrder: opts.fixAxisOrder, fixSelectorCombinators: opts.fixSelectorCombinators, ccwShorthand: opts.ccwShorthand, });
if (opts.outputFile) { fs.writeFileSync(opts.outputFile, output, "utf8"); if (!opts.watch) { console.error("✓ Converted: " + (sourcePath || "stdin") + " → " + opts.outputFile); } } else { process.stdout.write(output); } } catch (e) { console.error("Error converting CSS:", e.message); process.exit(1); }}
// ─── Main ────────────────────────────────────────────────────────────────
if (opts.stdin) { var chunks = []; process.stdin.setEncoding("utf8"); process.stdin.on("data", function (chunk) { chunks.push(chunk); }); process.stdin.on("end", function () { processCSS(chunks.join(""), "stdin"); });} else if (opts.inputFile) { var inputPath = path.resolve(opts.inputFile); if (!fs.existsSync(inputPath)) { console.error("Error: File not found: " + inputPath); process.exit(1); }
if (opts.watch) { console.error("Watching " + inputPath + " for changes…"); function doConvert() { try { var input = fs.readFileSync(inputPath, "utf8"); var output = fixCSS(input, { fixShorthandDefaults: opts.fixShorthandDefaults, fixAxisOrder: opts.fixAxisOrder, fixSelectorCombinators: opts.fixSelectorCombinators, ccwShorthand: opts.ccwShorthand, }); if (opts.outputFile) { fs.writeFileSync(opts.outputFile, output, "utf8"); console.error("✓ Converted at " + new Date().toLocaleTimeString()); } else { process.stdout.write(output); } } catch (e) { console.error("Error:", e.message); } }
doConvert(); fs.watch(inputPath, { persistent: true }, function (event) { if (event === "change") { // Small debounce clearTimeout(doConvert._timeout); doConvert._timeout = setTimeout(doConvert, 100); } });
process.stdin.resume(); } else { var input = fs.readFileSync(inputPath, "utf8"); processCSS(input, inputPath); }} else { console.error("Error: No input file specified. Use --stdin or provide a filename."); console.error("Run with --help for usage."); process.exit(1);}