@@ -67,50 +67,6 @@ const isAstClassName = (item: {type?: string}): item is AstClassName => item.typ
6767const isAstTagName = ( item : { type ?: string } ) : item is AstTagName => item . type === 'TagName' ;
6868const isAstId = ( item : { type ?: string } ) : item is AstId => item . type === 'Id' ;
6969
70- function toSnakeCase ( str ?: string | null ) : string {
71- if ( ! str ) {
72- return '' ;
73- }
74- const tokens = str
75- . split ( '-' )
76- . map ( ( token ) => token . charAt ( 0 ) . toUpperCase ( ) + token . slice ( 1 ) . toLowerCase ( ) ) ;
77- const out = tokens . join ( '' ) ;
78- return out . charAt ( 0 ) . toLowerCase ( ) + out . slice ( 1 ) ;
79- }
80-
81- function requireBoolean ( css : AstAttribute | AstPseudoClass ) : 'true' | 'false' {
82- const rawValue = ( css as any ) . value ?. value ?? ( css as any ) . argument ?. value ;
83- const value = _ . toLower ( rawValue ?? 'true' ) ;
84- if ( value === 'true' ) {
85- return 'true' ;
86- }
87- if ( value === 'false' ) {
88- return 'false' ;
89- }
90- throw new Error ( `'${ css . name } ' must be true, false or empty. Found '${ ( css as any ) . value } '` ) ;
91- }
92-
93- function requireEntityName ( cssEntity : AstAttribute | AstPseudoClass ) : string {
94- const attrName = cssEntity . name . toLowerCase ( ) ;
95-
96- if ( ALL_ATTRS . includes ( attrName ) ) {
97- return attrName ;
98- }
99-
100- for ( const [ officialAttr , aliasAttrs ] of ATTRIBUTE_ALIASES ) {
101- if ( aliasAttrs . includes ( attrName ) ) {
102- return officialAttr ;
103- }
104- }
105- throw new Error (
106- `'${ attrName } ' is not a valid attribute. Supported attributes are '${ ALL_ATTRS . join ( ', ' ) } '` ,
107- ) ;
108- }
109-
110- function getWordMatcherRegex ( word : string ) : string {
111- return `\\b(\\w*${ _ . escapeRegExp ( word ) } \\w*)\\b` ;
112- }
113-
11470export class CssConverter {
11571 constructor (
11672 private readonly selector : string ,
@@ -277,3 +233,47 @@ export class CssConverter {
277233 throw new Error ( 'No rules could be parsed out of the current selector' ) ;
278234 }
279235}
236+
237+ function toSnakeCase ( str ?: string | null ) : string {
238+ if ( ! str ) {
239+ return '' ;
240+ }
241+ const tokens = str
242+ . split ( '-' )
243+ . map ( ( token ) => token . charAt ( 0 ) . toUpperCase ( ) + token . slice ( 1 ) . toLowerCase ( ) ) ;
244+ const out = tokens . join ( '' ) ;
245+ return out . charAt ( 0 ) . toLowerCase ( ) + out . slice ( 1 ) ;
246+ }
247+
248+ function requireBoolean ( css : AstAttribute | AstPseudoClass ) : 'true' | 'false' {
249+ const rawValue = ( css as any ) . value ?. value ?? ( css as any ) . argument ?. value ;
250+ const value = _ . toLower ( rawValue ?? 'true' ) ;
251+ if ( value === 'true' ) {
252+ return 'true' ;
253+ }
254+ if ( value === 'false' ) {
255+ return 'false' ;
256+ }
257+ throw new Error ( `'${ css . name } ' must be true, false or empty. Found '${ ( css as any ) . value } '` ) ;
258+ }
259+
260+ function requireEntityName ( cssEntity : AstAttribute | AstPseudoClass ) : string {
261+ const attrName = cssEntity . name . toLowerCase ( ) ;
262+
263+ if ( ALL_ATTRS . includes ( attrName ) ) {
264+ return attrName ;
265+ }
266+
267+ for ( const [ officialAttr , aliasAttrs ] of ATTRIBUTE_ALIASES ) {
268+ if ( aliasAttrs . includes ( attrName ) ) {
269+ return officialAttr ;
270+ }
271+ }
272+ throw new Error (
273+ `'${ attrName } ' is not a valid attribute. Supported attributes are '${ ALL_ATTRS . join ( ', ' ) } '` ,
274+ ) ;
275+ }
276+
277+ function getWordMatcherRegex ( word : string ) : string {
278+ return `\\b(\\w*${ _ . escapeRegExp ( word ) } \\w*)\\b` ;
279+ }
0 commit comments