public
Created

CSS decode/encode

  • Download Gist
gistfile1.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
function CSSencode(code)
{
code = code.replace(/\n/ig,'');
code = code.replace(/(\s){2,}/ig,'$1');
code = code.replace(/\t/ig,'');
code = code.replace(/\n\}/ig,'\}');
code = code.replace(/\n\{\s*/ig,'\{');
code = code.replace(/(\S)\s*\}/ig,'$1\}');
code = code.replace(/(\S)\s*\{/ig,'$1\{');
code = code.replace(/\{\s*(\S)/ig,'\{$1');
return code;
}
function CSSdecode(code)
{
code = code.replace(/(\s){2,}/ig,'$1');
code = code.replace(/(\S)\s*\{/ig,'$1 {');
code = code.replace(/\*\/(.[^\}\{]*)}/ig,'\*\/\n$1}');
code = code.replace(/\/\*/ig,'\n\/\*');
code = code.replace(/;\s*(\S)/ig,';\n\t$1');
code = code.replace(/\}\s*(\S)/ig,'\}\n$1');
code = code.replace(/\n\s*\}/ig,'\n\}');
code = code.replace(/\{\s*(\S)/ig,'\{\n\t$1');
code = code.replace(/(\S)\s*\*\//ig,'$1\*\/');
code = code.replace(/\*\/\s*([^\}\{]\S)/ig,'\*\/\n\t$1');
code = code.replace(/(\S)\}/ig,'$1\n\}');
code = code.replace(/(\n){2,}/ig,'\n');
code = code.replace(/:/ig,': ');
code = code.replace(/ /ig,' ');
return code;
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.