Skip to content

Commit ab6f748

Browse files
author
Alexander Ryzhikov
committed
Convert kebab-case to camelCase
closes #2
1 parent cd79353 commit ab6f748

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

lib/utils.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ var _compose = require('lodash/fp/compose');
1313

1414
var _compose2 = _interopRequireDefault(_compose);
1515

16+
var _camelCase = require('lodash/fp/camelCase');
17+
18+
var _camelCase2 = _interopRequireDefault(_camelCase);
19+
1620
var _cond = require('lodash/fp/cond');
1721

1822
var _cond2 = _interopRequireDefault(_cond);
@@ -70,7 +74,8 @@ var objectify = function objectify(root, filepath) {
7074
})) {
7175
var value = rule.value;
7276

73-
var key = rule.prop.replace(/^-+/, ''); // replace "--"
77+
var key = (0, _camelCase2.default)(rule.prop.replace(/^-+/, '') // replace "--"
78+
);
7479

7580
result[key] = value.match(/^[+-]?\d*.?(\d*)?(px)$/i) ? parseFloat(value) : value;
7681
}

src/lib/utils.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import compose from 'lodash/fp/compose'
2+
import camelCase from 'lodash/fp/camelCase'
23
import cond from 'lodash/fp/cond'
34
import postcss from 'postcss'
45
import cssnext from 'postcss-cssnext'
@@ -47,7 +48,9 @@ const objectify = (root, filepath) => {
4748
}
4849
if (rule.parent && rule.parent.selectors.find((sel) => sel === ':root')) {
4950
const { value } = rule
50-
const key = rule.prop.replace(/^-+/, '') // replace "--"
51+
const key = camelCase(
52+
rule.prop.replace(/^-+/, '') // replace "--"
53+
)
5154

5255
result[key] = value.match(/^[+-]?\d*.?(\d*)?(px)$/i) ? parseFloat(value) : value
5356
}
File renamed without changes.

test/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ test('works with @apply', async (t) => {
4545
t.deepEqual(result, {})
4646
})
4747

48+
test('converts kebab case', async (t) => {
49+
const result = await runner('./convertedCase.css')
50+
51+
t.not(result.sizeVariable, undefined)
52+
t.is(result['size-variable'], undefined)
53+
})
54+
4855
test('handles cssSyntax errors', async (t) => {
4956
t.throws(runner('./wrongSyntax.css'), ([error]) => error.message.includes('Unclosed block'))
5057
})

0 commit comments

Comments
 (0)