Skip to content

Instantly share code, notes, and snippets.

@basiclines
Created October 31, 2012 10:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save basiclines/3986314 to your computer and use it in GitHub Desktop.
Save basiclines/3986314 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