Skip to content

Files

Latest commit

a3efc18 · May 24, 2016

History

History

function-name

Function Name

Regular expression to capture a function name.

Usage

var RE_FUNCTION_NAME = require( '@stdlib/regexp/function-name' );

RE_FUNCTION_NAME

Regular expression to capture a function name.

function beep() {
    return 'boop';
}

var name = RE_FUNCTION_NAME.exec( beep.toString() )[ 1 ];
// returns 'beep'

Examples

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 ''