File tree Expand file tree Collapse file tree 3 files changed +23
-9
lines changed
Expand file tree Collapse file tree 3 files changed +23
-9
lines changed Original file line number Diff line number Diff line change @@ -162,10 +162,15 @@ declare function convertCssToJss(rawCss: string): ObjectProperty[]
162162import { convertCssToJssString } from ' jss-codemorphs/convertCssToJss'
163163```
164164
165- Converts CSS to JSS. Returns the resulting JSS code as a string.
165+ Converts CSS to JSS. Returns the resulting JSS code as a string. You can
166+ pass ` recast.Options ` as the second argument to customize the code format.
167+ Uses ` { tabWidth: 2, useTabs: false, quote: 'single' } ` as default options.
166168
167169Signature:
168170
169171``` js
170- declare function convertCssToJssString (rawCss : string ): string
172+ declare function convertCssToJssString (
173+ rawCss : string ,
174+ options ?: recast .Options
175+ ): string
171176```
Original file line number Diff line number Diff line change @@ -111,9 +111,7 @@ export default function Root(): React.ReactNode {
111111 debounce ( ( input : string ) : void => {
112112 let converted : string | Error
113113 try {
114- converted = convertCssToJssString ( input ) . replace ( / ^ { 2 , } / gm, match =>
115- match . substring ( match . length / 2 )
116- )
114+ converted = convertCssToJssString ( input )
117115 } catch ( error ) {
118116 converted = error
119117 }
Original file line number Diff line number Diff line change @@ -34,10 +34,21 @@ export default function convertCssToJss(rawCss: string): ObjectProperty[] {
3434 ) as ObjectProperty [ ]
3535}
3636
37- export function convertCssToJssString ( rawCss : string ) : string {
38- return convertCssToJss ( rawCss )
39- . map ( p => recast . prettyPrint ( p ) . code )
40- . join ( ',\n' )
37+ export function convertCssToJssString (
38+ rawCss : string ,
39+ options ?: recast . Options
40+ ) : string {
41+ const recastOptions : recast . Options = {
42+ quote : 'single' ,
43+ tabWidth : 2 ,
44+ useTabs : false ,
45+ ...options ,
46+ }
47+ return (
48+ convertCssToJss ( rawCss )
49+ . map ( p => recast . prettyPrint ( p , recastOptions ) . code )
50+ . join ( ',\n' ) + ','
51+ )
4152}
4253
4354export function collectAnimationNames ( nodes : postcss . Node [ ] ) : Set < string > {
You can’t perform that action at this time.
0 commit comments