@@ -6,18 +6,24 @@ const filenameToInterfaceName = (filename) => {
66 . replace ( / \W + ( \w ) / g, ( _ , c ) => c . toUpperCase ( ) ) ;
77} ;
88
9- const cssModuleToTypescriptInterfaceProperties = ( cssModuleKeys , indent = ' ' ) => {
10- return cssModuleKeys
9+ const cssModuleToTypescriptInterfaceProperties = ( cssModuleKeys , orderAlphabetically , indent = ' ' ) => {
10+ return sortCssModuleKeys ( cssModuleKeys )
1111 . map ( ( key ) => `${ indent } '${ key } ': string;` )
1212 . join ( '\n' ) ;
1313} ;
1414
15- const cssModuleToNamedExports = ( cssModuleKeys ) => {
16- return cssModuleKeys
15+ const cssModuleToNamedExports = ( cssModuleKeys , orderAlphabetically ) => {
16+ return sortCssModuleKeys ( cssModuleKeys )
1717 . map ( ( key ) => `export const ${ key } : string;` )
1818 . join ( '\n' ) ;
1919} ;
2020
21+ const sortCssModuleKeys = ( cssModuleKeys , orderAlphabetically ) => {
22+ return orderAlphabetically
23+ ? [ ...cssModuleKeys ] . sort ( )
24+ : [ ...cssModuleKeys ]
25+ } ;
26+
2127const allWordsRegexp = / ^ \w + $ / i;
2228export const filterNonWordClasses = ( cssModuleKeys ) => {
2329 const filteredClassNames = cssModuleKeys . filter ( classname => allWordsRegexp . test ( classname ) ) ;
@@ -80,15 +86,15 @@ export const filenameToTypingsFilename = (filename) => {
8086 return path . join ( dirName , `${ baseName } .d.ts` ) ;
8187} ;
8288
83- export const generateNamedExports = ( cssModuleKeys ) => {
84- const namedExports = cssModuleToNamedExports ( cssModuleKeys ) ;
89+ export const generateNamedExports = ( cssModuleKeys , orderAlphabetically ) => {
90+ const namedExports = cssModuleToNamedExports ( cssModuleKeys , orderAlphabetically ) ;
8591 return ( `${ namedExports }
8692` ) ;
8793} ;
8894
89- export const generateGenericExportInterface = ( cssModuleKeys , filename , indent ) => {
95+ export const generateGenericExportInterface = ( cssModuleKeys , filename , orderAlphabetically , indent ) => {
9096 const interfaceName = filenameToInterfaceName ( filename ) ;
91- const interfaceProperties = cssModuleToTypescriptInterfaceProperties ( cssModuleKeys , indent ) ;
97+ const interfaceProperties = cssModuleToTypescriptInterfaceProperties ( cssModuleKeys , orderAlphabetically , indent ) ;
9298 return (
9399`export interface ${ interfaceName } {
94100${ interfaceProperties }
0 commit comments