From d058d2bc631b7ecf13a89764c6a353f4cc5191e0 Mon Sep 17 00:00:00 2001 From: "Daniel, David" Date: Sat, 5 Aug 2017 10:46:39 -0700 Subject: [PATCH 1/2] add media queries back --- index.js | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 13d0067..625ba08 100644 --- a/index.js +++ b/index.js @@ -52,6 +52,7 @@ function convertKeyNames(obj) { } const propExists = prop => prop.length; +const addMedia = key => `@media ${key}`; function mungeRules(rules) { const rulesArr = []; @@ -67,7 +68,10 @@ function mungeRules(rules) { selectors.map(s => ({[s]:ruleObj})).forEach(r => rulesArr.push(r)); } } else if(type === 'media') { - rulesArr.concat(mungeRules(rule.rules)); + const key = addMedia(rule.media); + rulesArr.push({ + [key]: mungeRules(rule.rules) + }); } else { console.error('Type of ' + type + ' did not conform to media or rule \n', rule); } @@ -89,17 +93,25 @@ function cssToJson(string) { } } +const isMedia = key => /^\@/.test(key); + +const camelizeArray = arr => arr.map(obj => { + const key = Object.keys(obj)[0]; + if(isMedia(key)) { + console.log('obj[key]', key) + return {[key]:camelizeArray(obj[key])}; + } + return { + [key]: camelize(obj[key]) + } +}) + function cssToCamelizedJson(string) { if (!isString(string)) { throw new Error('cssToCamelizedJson needs a valid css string to convert'); } const json = cssToJson(string); - return json.map(obj => { - const key = Object.keys(obj)[0]; - return { - [key]: camelize(obj[key]) - } - }); + return camelizeArray(json); } module.exports = { From 3bc9731625b0dfd66ba031c32b09e0b546c63be4 Mon Sep 17 00:00:00 2001 From: "Daniel, David" Date: Sat, 5 Aug 2017 10:47:56 -0700 Subject: [PATCH 2/2] 0.1.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a0961a0..914439f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "convert-css", - "version": "0.1.0", + "version": "0.1.1", "description": "Convert css strings to JSON or JS", "main": "index.js", "author": "David Daniel, ",