index.js
32 lines
| 1 | export default function buildCSS( cssObj ) { |
| 2 | let css = ''; |
| 3 | |
| 4 | for ( const [ key, value ] of Object.entries( cssObj ) ) { |
| 5 | if ( value.length < 1 ) { |
| 6 | continue; |
| 7 | } |
| 8 | |
| 9 | let tempOutput = key + '{'; |
| 10 | let elementsAdded = 0; |
| 11 | |
| 12 | for ( const [ index, properties ] of Object.entries( value ) ) { // eslint-disable-line no-unused-vars |
| 13 | for ( const [ attribute, val ] of Object.entries( properties ) ) { |
| 14 | if ( ! val && 0 !== val ) { |
| 15 | continue; |
| 16 | } |
| 17 | |
| 18 | elementsAdded++; |
| 19 | tempOutput += attribute + ': ' + val + ';'; |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | tempOutput += '}'; |
| 24 | |
| 25 | if ( elementsAdded > 0 ) { |
| 26 | css += tempOutput; |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | return css; |
| 31 | } |
| 32 |