locateV8() returns the absolute source file path for a function or class at runtime.
npm install function-locationSupports Node.js 16+.
import { locateV8 } from 'function-location';
class ExampleClass {}
function exampleFunction() {}
locateV8(ExampleClass); // /path/to/file.ts
locateV8(exampleFunction); // /path/to/file.tslocateV8(input: Function): string | undefined- Throws
Function argument expectedwhen input is not a function/class constructor. - Returns
undefinedfor anonymous/native/builtins where metadata is unavailable.
This library uses a synchronous native addon lookup instead of the inspector protocol.
Sample comparison against an inspector-protocol baseline:
| Approach | Median time / call | Relative speed |
|---|---|---|
locate |
0.1197 µs |
1878.60x faster |
inspector protocol |
224.8900 µs |
baseline |
Results vary by environment; treat them as sample measurements only. Methodology and raw samples: docs/BENCHMARK.md
