File tree Expand file tree Collapse file tree 4 files changed +30
-0
lines changed Expand file tree Collapse file tree 4 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ const genericNames = require('generic-names');
55const globToRegex = require ( 'glob-to-regexp' ) ;
66const identity = require ( 'lodash' ) . identity ;
77const negate = require ( 'lodash' ) . negate ;
8+ const camelCaseFunc = require ( 'lodash' ) . camelCase ;
89const readFileSync = require ( 'fs' ) . readFileSync ;
910const relative = require ( 'path' ) . relative ;
1011const resolve = require ( 'path' ) . resolve ;
@@ -27,6 +28,7 @@ module.exports = function setupHook({
2728 preprocessCss = identity ,
2829 processCss,
2930 processorOpts,
31+ camelCase,
3032 append = [ ] ,
3133 prepend = [ ] ,
3234 createImportedName,
@@ -103,6 +105,11 @@ module.exports = function setupHook({
103105
104106 tokens = lazyResult . root . tokens ;
105107
108+ if ( camelCase ) {
109+ tokens = Object . assign ( { } , tokens ,
110+ ...Object . keys ( tokens ) . map ( key => ( { [ camelCaseFunc ( key ) ] : tokens [ key ] } ) ) )
111+ }
112+
106113 if ( ! debugMode ) {
107114 // updating cache
108115 tokensByFile [ filename ] = tokens ;
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ const rules = {
1010 preprocessCss : 'function' ,
1111 processCss : 'function' ,
1212 processorOpts : 'object' ,
13+ camelCase : 'boolean' ,
1314 // plugins
1415 append : 'array' ,
1516 prepend : 'array' ,
Original file line number Diff line number Diff line change 1+ const detachHook = require ( '../sugar' ) . detachHook ;
2+ const dropCache = require ( '../sugar' ) . dropCache ;
3+
4+ suite ( 'api/camelCase' , ( ) => {
5+ test ( 'should add camel case keys in token' , ( ) => {
6+ const tokens = require ( './fixture/bem.css' ) ;
7+ assert . deepEqual ( tokens , {
8+ blockElementModifier : '_test_api_fixture_bem__block__element--modifier' ,
9+ 'block__element--modifier' : '_test_api_fixture_bem__block__element--modifier' ,
10+ } ) ;
11+ } ) ;
12+
13+ setup ( ( ) => hook ( { camelCase : true } ) ) ;
14+
15+ teardown ( ( ) => {
16+ detachHook ( '.css' ) ;
17+ dropCache ( './api/fixture/bem.css' ) ;
18+ } ) ;
19+ } ) ;
Original file line number Diff line number Diff line change 1+ .block__element--modifier {
2+ background : # 1e2a35 ;
3+ }
You can’t perform that action at this time.
0 commit comments