Skip to content

Instantly share code, notes, and snippets.

@fitzhaile
Created April 5, 2014 18:20
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 fitzhaile/9995866 to your computer and use it in GitHub Desktop.
Save fitzhaile/9995866 to your computer and use it in GitHub Desktop.
Get JSON from Sass output
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