-
-
Save crongro/1ddfc2e6ddc875a4765dea3bee26b984 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('fs'); | |
//functional util | |
const pipe = (...fns) => (value) => fns.reduce((acc, fn) => fn(acc), value); | |
const reduceByFun = (data) => (fun) => (initValue) => data.reduce((p,n) => fun(p,n), initValue); | |
//string utils | |
const trim = (s) => s.trim(s); | |
const removeNewLine = (s) => s.replace(/[\r\n]/g, ''); | |
//main | |
fs.readFile('./target.css', { encoding: 'utf-8' }, (err, str) => { | |
const gubuns = [',', ':', ';', '{', '}']; | |
const result = CSSMinifier.run(str, gubuns); | |
console.log(result); | |
}); | |
//CSSMinifier Object | |
const CSSMinifier = { | |
run(str, gubuns) { | |
const removeSpaces = reduceByFun(gubuns)(this.removeSpaceAroudChar); | |
const pipeSet = [removeNewLine, trim, removeSpaces]; | |
return this.executePipe(str, pipeSet); | |
}, | |
removeSpaceAroudChar(s, gubun) { | |
const reg = new RegExp(`\\s*${gubun}\\s*`, 'g'); | |
return s.replace(reg, `${gubun}`); | |
}, | |
executePipe(str, pipeSet) { | |
const result = pipe(...pipeSet)(str) | |
return result; | |
} | |
} |
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
/* page-setup.css */ | |
html { | |
font-size: 62.5%; | |
box-sizing: border-box; | |
} | |
html, body { | |
height: 100%; | |
width: 100%; | |
padding: 0px; | |
margin: 0px; | |
} | |
div, p, h1, h2, h3, h4, h5, h6, ul, ol, li, dl, dt, dd, | |
table, th, td, form, fieldset, legend, input, textarea, blockquote, button { | |
margin:0 auto; | |
padding:0; | |
border:1px solid red; | |
} | |
*, *:before, *:after { | |
box-sizing: inherit; | |
} | |
li { | |
list-style: none; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment