Skip to content

Instantly share code, notes, and snippets.

@jonathantneal
Created November 15, 2011 21:42
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 jonathantneal/1368457 to your computer and use it in GitHub Desktop.
Save jonathantneal/1368457 to your computer and use it in GitHub Desktop.
cssToObject.js
cssString = '#navbar, #sidebar { width: 80%; height: 23px; ul, ol { list-style-type: none; } li { float: left; a { font-weight: bold; } } } #main { background: #000; }';
cssObject = [{
type: 'rule',
selectors: [ '#navbar', '#sidebar' ],
declarations: [{
type: 'declaration',
property: 'width',
value: '80%'
}, {
type: 'declaration',
property: 'height',
value: '23px'
}, {
type: 'selector',
selectors: [ 'ul', 'ol' ],
declarations: [{
type: 'declaration',
property: 'list-style-type',
value: 'none'
}]
}, {
type: 'rule',
selectors: [ 'li' ],
declarations: [{
type: 'declaration',
property: 'float',
value: 'left'
}, {
type: 'selector',
selectors: [ 'a' ],
declarations: [{
type: 'declaration',
property: 'font-weight',
value: 'bold'
}]
}]
}]
}, {
type: 'rule',
selectors: [ '#main' ],
declarations: [{
type: 'declaration',
property: 'background',
value: '#000'
}]
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment