Registry / testing / get-func-name

get-func-name

JSON →
library3.0.0jsnpmunverified

get-func-name is a specialized utility library within the ChaiJS ecosystem, designed to securely and consistently retrieve the name of a JavaScript function. It offers a single, reliable API that works across both Node.js and browser environments, addressing inconsistencies that can arise from direct property access or varying runtime behaviors. The current stable version is `3.0.0`, which marks a definitive transition to being an ES Module (ESM) exclusively. This follows a previous, temporary ESM introduction and subsequent reversion in the v2.x series. The library maintains a focused release cadence driven by maintenance, bug fixes, and critical updates, such as the security patch in v2.0.1. Its primary differentiator is its cross-platform compatibility and robustness in extracting function names, making it a foundational tool for introspection in testing frameworks and other JavaScript libraries.

npm install get-func-name
INSTALL
IMPORT
SIG · GET-FUNC-NAME
G
get-func-name
testingjavascriptv3.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

getFuncName
import { getFuncName } from 'get-func-name';
const getFuncName = require('get-func-name');
Since v3.0.0, get-func-name is an ES Module (ESM) only. This is the correct way to import its named export. CommonJS `require` is not supported in v3+.
getFuncName
import getFuncName from 'get-func-name';
If `get-func-name` uses a named export for `getFuncName` (as is common for utility functions), attempting a default import will result in `undefined` or a runtime error. Use `import { getFuncName } from 'get-func-name';` instead.
getFuncNameModule
import * as getFuncNameModule from 'get-func-name'; const funcName = getFuncNameModule.getFuncName(myFunction);
const funcName = getFuncNameModule.default(myFunction);
A namespace import aggregates all named exports. For a named export like `getFuncName`, access it as a property of the namespace object (e.g., `getFuncNameModule.getFuncName`). `getFuncNameModule.default` would only be correct if the library also provided a default export for the function.

Demonstrates importing `getFuncName` and using it to retrieve names from various function types including named, anonymous, arrow functions, and class methods.

import { getFuncName } from 'get-func-name'; // A function with an explicit name function myNamedFunction() { // ... } // An anonymous function assigned to a variable const myAnonymousFunction = function() { // ... }; // An arrow function const myArrowFunction = () => { // ... }; // A function nested in an IIFE, which might not have an inferable name const nestedAnonymous = (function() { return function() {}; }()); console.log(`Name of myNamedFunction: '${getFuncName(myNamedFunction)}'`); console.log(`Name of myAnonymousFunction: '${getFuncName(myAnonymousFunction)}'`); console.log(`Name of myArrowFunction: '${getFuncName(myArrowFunction)}'`); console.log(`Name of nestedAnonymous: '${getFuncName(nestedAnonymous)}'`); // Example with a class method class MyClass { static staticMethod() {} instanceMethod() {} } console.log(`Name of staticMethod: '${getFuncName(MyClass.staticMethod)}'`); console.log(`Name of instanceMethod: '${getFuncName(new MyClass().instanceMethod)}'`);
Debug
Known issues
breakingVersion 3.0.0 is an ES Module (ESM) only. CommonJS `require()` is no longer supported. This breaks compatibility for projects not configured for ESM.
fix
Migrate your import statements from `const getFuncName = require('get-func-name');` to `import { getFuncName } from 'get-func-name';` and ensure your project environment supports ESM (e.g., set `"type": "module"` in `package.json`).
affects: >=3.0.0
gotchaThe package briefly transitioned to ESM in a v2.x release, but then reverted to CommonJS in v2.0.2. This created temporary confusion regarding its module format before the definitive ESM-only release of v3.0.0.
fix
Always refer to the latest major version (v3.0.0+) for ESM usage. If strict CommonJS is required, stick to versions `<3.0.0` but be aware of older security fixes.
affects: 2.0.1, 2.0.2
gotchaA security vulnerability (GHSA-4q6p-r6v2-jvc5) was addressed in v2.0.1. Using versions prior to this fix might expose your application to potential security risks.
fix
Upgrade to `get-func-name@2.0.1` or newer. The latest `v3.0.0` also includes this fix and is recommended.
affects: <2.0.1
Errors
Common errors & fixes
ReferenceError: require is not defined
Attempting to use CommonJS `require()` syntax in an ES Module (ESM) context or with `get-func-name` v3.0.0+.
fix
Change your import statement to `import { getFuncName } from 'get-func-name';` and ensure your file is treated as an ES Module (e.g., using `.mjs` extension or `"type": "module"` in `package.json`).
TypeError: (0, _getFuncName.default) is not a function OR TypeError: (0, get_func_name_1.getFuncName) is not a function
Incorrectly importing the `getFuncName` function, often by using a default import (`import getFuncName from 'get-func-name';`) when it's a named export, or vice versa.
fix
Ensure you are using a named import: `import { getFuncName } from 'get-func-name';`. If you are using TypeScript, confirm your `tsconfig.json` `compilerOptions.esModuleInterop` is enabled for better module interoperability.
Upgrade
Version history
3.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
get-func-name — npm install get-func-name · libregistry