export const functionName = ( fn ) : string => { const extract = ( value ) => value . match ( /^function ([^\(]*)\(/ ) ; let name = ( < any > fn ) . name ; if ( ! name || name . length === 0 ) { const match = extract ( fn . toString ( ) ) ; if ( match != null && match . length > 1 ) { name = match [ 1 ] ; } } if ( typeof name !== 'string' || name === '' ) { name = 'anonymous' ; } name = name . replace ( /[^\w]/gi , '_' ) ; if ( ! isNaN ( parseInt ( name [ 0 ] , 10 ) ) ) { name = '__num_' + name [ 0 ] ; } return name ; } ;