Skip to content

Instantly share code, notes, and snippets.

@adhrinae
Created February 19, 2018 11:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save adhrinae/1366902ff056d2cd054e75e47a33ce45 to your computer and use it in GitHub Desktop.
Save adhrinae/1366902ff056d2cd054e75e47a33ce45 to your computer and use it in GitHub Desktop.
const fs = require('fs');
fs.readFile('./page-setup.css', { encoding: 'utf-8' }, (err, data) => {
console.log(cssMinifier(data));
});
function cssMinifier(cssString) {
const removeSpaceAroundChar = char => replace(new RegExp(`\\s*${char}\\s*`, 'g'), char);
const removeNewLine = replace(/[\r\n]/g, '');
const shrinkers = map(removeSpaceAroundChar)([',', ';', ':', '{', '}']);
return pipe(trim, removeNewLine, ...shrinkers)(cssString);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment