Created
April 5, 2014 18:20
-
-
Save fitzhaile/9995866 to your computer and use it in GitHub Desktop.
Get JSON from Sass output
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 getSassyJSON() { | |
var style = null; | |
var json = null; | |
// Get the json string from CSS | |
if ( window.getComputedStyle && window.getComputedStyle(document.body, '::before') ) { | |
style = window.getComputedStyle(document.body, '::before'); | |
style = style.content; | |
} | |
// Get rid of quotes | |
if (typeof style === 'string' || style instanceof String) { | |
style = style.replace(/^['"]+|\s+|\\|(;\s?})+|['"]$/g, ''); | |
} | |
if ( JSON.parse(style) ) { | |
return JSON.parse(style); | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment