Skip to content

Instantly share code, notes, and snippets.

@jtfell
Last active July 3, 2016 07:44
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 jtfell/d1d2ea79bad858c52e28af524566e4ef to your computer and use it in GitHub Desktop.
Save jtfell/d1d2ea79bad858c52e28af524566e4ef to your computer and use it in GitHub Desktop.
function findFontSizeDecl(root) {
var vals = [];
// Iterate over font-size declarations
root.walkDecls(/font-size/, function(decl) {
vals.push(convertToEm(decl.value));
});
return vals;
};
var ROOT_FONT_SIZE = 16;
function convertToEm(value) {
if (value == 0) return 0;
if (value.indexOf('rem') > 0) {
return parseFloat(value.slice(0, -3));
}
if (value.indexOf('em') > 0) {
return parseFloat(value.slice(0, -2));
}
if (value.indexOf('px') > 0) {
var pixels = parseFloat(value.slice(0, -2));
return pixels/ROOT_FONT_SIZE;
}
// Skip declarations of inherits, initial
console.log('Skipping: ', value);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment