Skip to content

Instantly share code, notes, and snippets.

@rnowm
Forked from basiclines/CSS units parser
Created November 5, 2012 07:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rnowm/4015900 to your computer and use it in GitHub Desktop.
Save rnowm/4015900 to your computer and use it in GitHub Desktop.
JS for parsing CSS numeric values followed by 'rem' unit and perform math operations over it
//Open the file directly in the browser and run this script from the console
//Assumptions: The browser uses a <pre/> tag for showing the CSS code
var file = document.querySelector("pre");
var fileContent = file.innerHTML;
var newContent = fileContent.replace(/([\d.]+)(rem)/g, function(m){
var measure = parseFloat(m.split("rem")[0]);
var newMeasure = measure / 1.6;
newMeasure = newMeasure.toFixed(2);
return newMeasure+"rem";
});
file.parentNode.innerHTML = "<pre>"+newContent+"</pre>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment