Get function name with strictness and correctness in mind. Also works for arrow functions and getting correct name of bounded functions. Powered by fn-name.
Install
npm i get-fn-name --save
Usage
For more use-cases see the tests
const getFnName = require('get-fn-name')
Trying to get the name of val
function.
Params
val
{Function}: Regular or arrow (es2015/es6, also know as fat arrow
) function.returns
{String|null}: The name of function or null
otherwise.
Example
var name = require('get-fn-name')
console.log(name(function () { return 1 }))
console.log(name(function named () { return 2 }))
console.log(name(() => 3))
console.log(name(() => { return 4 }))
console.log(name((a, b, c) => a + b + c))
console.log(name((a, b) => { return a + b }))
Related
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
But before doing anything, please read the CONTRIBUTING.md guidelines.