Created
December 30, 2025 13:59
-
-
Save dumbmoron/f01afe954f36d18fb841d8bcc7e4e232 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const fs = require('node:fs'); | |
| const L2FFS = (ls) => { | |
| const ffs = []; | |
| let acc = []; | |
| for (const l of ls) { | |
| const lt = l.trim(); | |
| if (!lt) continue; | |
| acc.push(l); | |
| if (lt === '}') { | |
| ffs.push(acc.join('\n')); | |
| acc = []; | |
| } | |
| } | |
| return ffs; | |
| } | |
| const I = (n, h, o) => { | |
| n = [...n]; | |
| let i = -1; | |
| while (n.pop() && i === -1) { | |
| i = h.indexOf(n, o); | |
| } | |
| return i; | |
| } | |
| const FFS2G = (ffs) => { | |
| const G = {} | |
| for (const ff of ffs) { | |
| const ffLine = ff.indexOf('font-family: '); | |
| if (ffLine === -1) throw `wrong`; | |
| const ffLineEnd = I(';\n', ff, ffLine); | |
| if (ffLineEnd === -1) throw `wrong`; | |
| (G[ff.substring(ffLine, ffLineEnd)] ??= []).push(ff); | |
| } | |
| Object.values(G).map(v => v.sort()); | |
| return G; | |
| } | |
| const G2SL = (g) => { | |
| return Object.entries(g) | |
| .sort(([k_1,], [k_2,]) => k_1 < k_2) | |
| .flatMap(([, v]) => v); | |
| } | |
| const X = (I, ...fs) => { | |
| for (const f of fs) { | |
| I = f(I); | |
| } | |
| return I; | |
| } | |
| fs.writeFileSync( | |
| 'stylesheet2.css', | |
| X( | |
| fs.readFileSync('stylesheet.css', 'utf8').split('\n'), | |
| L2FFS, | |
| FFS2G, | |
| G2SL, | |
| ).join('\n\n') | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment