import { generateIdName } from './id.helper' ; import { Constructor } from './inversify.types' ; export function getParametersFromConstructor ( constructor ) { const stringParameters = getParametersAsStringFromConstructor ( constructor ) ; return convertStringParametersToList ( stringParameters ) ; } export function getParametersAsStringFromConstructor ( constructor ) { const parameters = constructor . toString ( ) . match ( /(constructor|function) ?(.*) ?\((.*)\)/ ) ; if ( ! parameters ) { throw new Error ( `Cannot find constructor in this class ${ constructor . name }` ) ; } return parameters [ 3 ] ; } export function convertStringParametersToList ( stringParameters ) { return stringParameters . split ( ',' ) . map ( arg => arg . replace ( /\/\*.*\*\// , '' ) . trim ( ) ) . filter ( x => x ) ; } export function cleanParameter ( parameter ) { return generateIdName ( parameter ) . replace ( /_/g , '' ) ; }