Regular expression to capture a function name.
var RE_FUNCTION_NAME = require( '@stdlib/regexp/function-name' );
Regular expression to capture a function
name.
function beep() {
return 'boop';
}
var name = RE_FUNCTION_NAME.exec( beep.toString() )[ 1 ];
// returns 'beep'
var RE_FUNCTION_NAME = require( '@stdlib/utils/regexp/function-name' );
function fname( fcn ) {
return RE_FUNCTION_NAME.exec( fcn.toString() )[ 1 ];
}
console.log( fname( Math.sqrt ) );
// returns 'sqrt'
console.log( fname( Int8Array ) );
// returns 'Int8Array'
console.log( fname( Object.prototype.toString ) );
// returns 'toString'
console.log( fname( function(){} ) );
// returns ''