fn-name
Get the name of a named function
This package has a good security score with no known vulnerabilities.
Community Reviews
Simple, reliable function name extraction with excellent TypeScript support
The package handles edge cases well - anonymous functions, arrow functions, and bound functions all return sensible results. Error handling is straightforward: it returns an empty string for anonymous functions rather than throwing, which is the right choice for a utility like this. The source is tiny (basically a one-liner wrapper around function.name with fallbacks), making it perfect for dependency-conscious projects.
The main limitation is that it's almost too simple - you might question whether you need a dependency for this. However, the cross-environment compatibility and edge case handling it provides saves you from writing and maintaining the same logic yourself. Documentation is minimal but adequate since the API surface is so small.
Best for: Projects needing reliable function name extraction for logging, debugging, or metaprogramming utilities.
Avoid if: You only need basic function.name access in modern environments and don't need cross-platform compatibility.
Minimal utility with one job, does it well with no security baggage
From a security perspective, this package is refreshingly minimal with zero dependencies, which means no supply chain attack surface. The code is simple enough to audit in minutes. It handles edge cases like anonymous functions and arrow functions predictably by returning empty strings or undefined, which won't cause injection issues in logging contexts. No crypto, no network calls, no file system access - just pure function introspection.
The main gotcha is that minification can strip function names, so don't rely on this for production behavior that affects application logic. It's best used for development tooling, error reporting, and debugging where function names provide context but aren't mission-critical.
Best for: Development tooling, debugging utilities, and logging frameworks where function name introspection aids diagnostics.
Avoid if: You need reliable function identification in production code or can simply access .name directly without abstraction.
Tiny utility that does one thing well, but beware the edge cases
The package handles most common scenarios well, including regular named functions, class methods, and arrow functions assigned to variables. However, you'll quickly discover that JavaScript's function naming is more nuanced than expected. Anonymous functions return empty strings, and minified code will give you mangled names. The error messages are minimal since it's such a simple utility, but this also means you need to understand JavaScript's function.name behavior yourself.
For day-to-day use, it's reliable for debugging, logging, and introspection tasks. The package hasn't been updated since 2021, but that's actually fine - it's feature-complete. Community support is limited simply because there's not much that can go wrong, though this means you're mostly on your own for edge cases.
Best for: Projects needing simple function name extraction for logging, debugging, or runtime introspection.
Avoid if: You need robust metadata extraction from minified code or complex function analysis beyond just the name.
Sign in to write a review
Sign In