Skip to content

Commit a57d78f

Browse files
shinytang6adamgruber
authored andcommitted
Support camelCase options for all the SassMap keys (#9)
* enable camelCase option to work for sassmap * update tests * minor tweak
1 parent 50b1cf7 commit a57d78f

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

lib/transformVars.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function quoteFontName(str) {
2828
*
2929
* @return {string|int} CSS value
3030
*/
31-
function getSassValue(sassVar) {
31+
function getSassValue(sassVar, options) {
3232
const { type, value } = sassVar;
3333
switch (type) {
3434
case 'SassNumber':
@@ -53,7 +53,7 @@ function getSassValue(sassVar) {
5353
}
5454

5555
case 'SassMap':
56-
return transformVars(value);
56+
return transformVars(value, options);
5757

5858
default:
5959
return value;
@@ -88,7 +88,7 @@ function transformVars(varsObj, options) {
8888
const opts = Object.assign({ camelCase: true }, options);
8989
return Object.keys(varsObj).reduce((acc, key) => {
9090
const newKey = transformKey(key, opts.camelCase);
91-
const newVal = getSassValue(varsObj[key]);
91+
const newVal = getSassValue(varsObj[key], opts);
9292
acc[newKey] = newVal;
9393
return acc;
9494
}, {});

test/__snapshots__/test.js.snap

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ Object {
1010
"my_other_vAr": "300px",
1111
"my_var": "200px",
1212
"my_var_2": "600px",
13+
"value-Map": Object {
14+
"my-var5": "900px",
15+
"my__var--6": "1000px",
16+
"my_var4": "800px",
17+
},
1318
}
1419
`;
1520

@@ -23,6 +28,11 @@ Object {
2328
"my_other_vAr": "300px",
2429
"my_var": "200px",
2530
"my_var_2": "600px",
31+
"value-Map": Object {
32+
"my-var5": "900px",
33+
"my__var--6": "1000px",
34+
"my_var4": "800px",
35+
},
2636
}
2737
`;
2838

@@ -36,6 +46,11 @@ Object {
3646
"my_other_vAr": "300px",
3747
"my_var": "200px",
3848
"my_var_2": "600px",
49+
"value-Map": Object {
50+
"my-var5": "900px",
51+
"my__var--6": "1000px",
52+
"my_var4": "800px",
53+
},
3954
}
4055
`;
4156

@@ -77,6 +92,11 @@ Object {
7792
"myVar": "500px",
7893
"myVar2": "600px",
7994
"myVar3": "700px",
95+
"valueMap": Object {
96+
"myVar4": "800px",
97+
"myVar5": "900px",
98+
"myVar6": "1000px",
99+
},
80100
}
81101
`;
82102

test/sass/test-opts-camel.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,8 @@ $My-Cool_var: 400px;
66
$MY-VAR: 500px;
77
$my_var_2: 600px;
88
$my__var--3: 700px;
9+
$value-Map: (
10+
my_var4: 800px,
11+
my-var5: 900px,
12+
my__var--6: 1000px
13+
);

0 commit comments

Comments
 (0)