File tree Expand file tree Collapse file tree 4 files changed +19
-7
lines changed Expand file tree Collapse file tree 4 files changed +19
-7
lines changed Original file line number Diff line number Diff line change @@ -13,10 +13,6 @@ var _compose = require('lodash/fp/compose');
1313
1414var _compose2 = _interopRequireDefault ( _compose ) ;
1515
16- var _camelCase = require ( 'lodash/fp/camelCase' ) ;
17-
18- var _camelCase2 = _interopRequireDefault ( _camelCase ) ;
19-
2016var _cond = require ( 'lodash/fp/cond' ) ;
2117
2218var _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+
6163var 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 * ) ? ( p x ) $ / i) ? parseFloat ( value ) : value ;
Original file line number Diff line number Diff line change 11import compose from 'lodash/fp/compose'
2- import camelCase from 'lodash/fp/camelCase'
32import cond from 'lodash/fp/cond'
43import postcss from 'postcss'
54import cssnext from 'postcss-cssnext'
@@ -35,6 +34,9 @@ const toExport = cond([
3534
3635const toString = ( data ) => `${ JSON . stringify ( data , null , '\t' ) } `
3736
37+ const dashesCamelCase = str =>
38+ str . replace ( / - + ( \w ) / g, ( match , firstLetter ) => firstLetter . toUpperCase ( ) )
39+
3840const 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
Original file line number Diff line number Diff line change 11: root {
22 --size-variable : 10em ;
3+ --color-RGBA : 'rgba' ;
34}
Original file line number Diff line number Diff 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+
5461test ( 'handles cssSyntax errors' , async ( t ) => {
5562 t . throws ( runner ( './wrongSyntax.css' ) , ( [ error ] ) => error . message . includes ( 'Unclosed block' ) )
5663} )
You can’t perform that action at this time.
0 commit comments