A utility for retrieving precise source code coordinates from the execution stack through a simple API.
- Simple API: Use clear, descriptive functions to fetch caller information.
- Call Site Extraction: Get a list of all stack frames in the current execution.
- Caller Identification: Quickly find the file path that called your function.
- Type Safety: Fully typed with TypeScript for reliable development and autocomplete.
- Result Pattern: Use a success/failure result type to handle missing stack data safely.
- Configurable Depth: Limit the number of results returned from the stack trace.
npm add @zokugun/callsite- Node.js:
v18.20or higher - Modules: ECMAScript Modules (
ESM) or CommonJS (CJS)
import { getCallerFile } from '@zokugun/callsite';
function printCallerPath(): void {
const result = getCallerFile();
if(result.fails) {
return;
}
const filePath = result.value;
console.log(`Called by file: ${filePath}`);
}type CallSite = {
column: number;
file: string;
line: number;
};
function getCallSites(maxResult?: number): CallSite[];
function getCallerFile(): DResult<string>;
function getCallerSite(): DResult<CallSite>;Contributions are most welcome. Please:
- Open issues and feature requests under the repository discussions.
- Follow the
CONTRIBUTING.md.
Support this project by becoming a financial contributor.
| ko-fi.com/daiyam | |
| liberapay.com/daiyam/donate | |
| paypal.me/daiyam99 |
Copyright © 2026-present Baptiste Augrain
Licensed under the MIT license.