const FUNCTION_NAME_REGEX = /^function\s*([\w$]+)/ ; const DEFAULT_MATCH = [ '' , '' ] ; name export function functionName ( fn ) { if ( fn . name ) return fn . name ; const [ , name ] = String ( fn ) . match ( FUNCTION_NAME_REGEX ) || DEFAULT_MATCH ; return name ; }