Skip to content

Commit 629c906

Browse files
author
Alexander Ryzhikov
committed
fix: replace camelCase with dashesCamelCase
1 parent 7c056de commit 629c906

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

lib/utils.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ 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-
2016
var _cond = require('lodash/fp/cond');
2117

2218
var _cond2 = _interopRequireDefault(_cond);
@@ -58,6 +54,12 @@ var toString = function toString(data) {
5854
return '' + (0, _stringify2.default)(data, null, '\t');
5955
};
6056

57+
var dashesCamelCase = function dashesCamelCase(str) {
58+
return str.replace(/-+(\w)/g, function (match, firstLetter) {
59+
return firstLetter.toUpperCase();
60+
});
61+
};
62+
6163
var objectify = function objectify(root, filepath) {
6264
var result = {};
6365

@@ -74,7 +76,7 @@ var objectify = function objectify(root, filepath) {
7476
})) {
7577
var value = rule.value;
7678

77-
var key = (0, _camelCase2.default)(rule.prop.replace(/^-+/, '') // replace "--"
79+
var key = dashesCamelCase(rule.prop.replace(/^-+/, '') // replace "--"
7880
);
7981

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

src/lib/utils.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import compose from 'lodash/fp/compose'
2-
import camelCase from 'lodash/fp/camelCase'
32
import cond from 'lodash/fp/cond'
43
import postcss from 'postcss'
54
import cssnext from 'postcss-cssnext'
@@ -35,6 +34,9 @@ const toExport = cond([
3534

3635
const toString = (data) => `${JSON.stringify(data, null, '\t')}`
3736

37+
const dashesCamelCase = str =>
38+
str.replace(/-+(\w)/g, (match, firstLetter) => firstLetter.toUpperCase())
39+
3840
const objectify = (root, filepath) => {
3941
const result = {}
4042

@@ -48,7 +50,7 @@ const objectify = (root, filepath) => {
4850
}
4951
if (rule.parent && rule.parent.selectors.find((sel) => sel === ':root')) {
5052
const { value } = rule
51-
const key = camelCase(
53+
const key = dashesCamelCase(
5254
rule.prop.replace(/^-+/, '') // replace "--"
5355
)
5456

test/fixtures/convertedCase.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
:root {
22
--size-variable: 10em;
3+
--color-RGBA: 'rgba';
34
}

test/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ test('converts kebab case', async (t) => {
5151
t.is(result['size-variable'], undefined)
5252
})
5353

54+
test('converts only dashes', async (t) => {
55+
const result = await runner('./convertedCase.css')
56+
57+
t.not(result.colorRGBA, undefined)
58+
t.is(result['color-RGBA'], undefined)
59+
})
60+
5461
test('handles cssSyntax errors', async (t) => {
5562
t.throws(runner('./wrongSyntax.css'), ([error]) => error.message.includes('Unclosed block'))
5663
})

0 commit comments

Comments
 (0)