Last active
July 3, 2016 07:44
-
-
Save jtfell/d1d2ea79bad858c52e28af524566e4ef to your computer and use it in GitHub Desktop.
This file contains 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
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