get-fn-name

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][].

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
get-fn-name
401.0.08 years ago8 years agoMinified + gzip package size for get-fn-name in KB

Readme

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.

!code climatecodeclimate-imgcodeclimate-url !standard code stylestandard-imgstandard-url !travis build statustravis-imgtravis-url !coverage statuscoveralls-imgcoveralls-url !dependency statusdavid-imgdavid-url

Install

npm i get-fn-name --save

Usage

For more use-cases see the tests

const getFnName = require('get-fn-name')

getFnName

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 })) // => null
console.log(name(function named () { return 2 })) // => 'named'

// arrows
console.log(name(() => 3)) // => null
console.log(name(() => { return 4 })) // => null
console.log(name((a, b, c) => a + b + c)) // => null
console.log(name((a, b) => { return a + b })) // => null

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.

Charlike Make Reagent !new message to charlikenew-message-imgnew-message-url !freenode #charlikefreenode-imgfreenode-url

!tunnckoCore.tkauthor-www-imgauthor-www-url !keybase tunnckoCorekeybase-imgkeybase-url !tunnckoCore npmauthor-npm-imgauthor-npm-url !tunnckoCore twitterauthor-twitter-imgauthor-twitter-url !tunnckoCore githubauthor-github-imgauthor-github-url