import { upperFirst } from 'lodash' ; /**
 * Converts valid file names to valid javascript symbols and does best effort to make them readable. Example: ds-token.test becomes DsTokenTest
 */ export function normalizeName ( rawName ) { const transformations = [ ( s ) => s . replace ( /\s+/g , '-' ) , ( s ) => s . replace ( /\./g , '-' ) , ( s ) => s . replace ( /_/g , '-' ) , ( s ) => s . replace ( /-[a-z]/g , ( match ) => match . substr ( - 1 ) . toUpperCase ( ) ) , ( s ) => s . replace ( /-/g , '' ) , ( s ) => s . replace ( /^\d+/ , '' ) , ( s ) => upperFirst ( s ) , ] ; const finalName = transformations . reduce ( ( s , t ) => t ( s ) , rawName ) ; if ( finalName === '' ) { throw new Error ( `Can't guess class name, please rename file: ${ rawName }` ) ; } return finalName ; }