why-is-this-called
v0.1.0
Published
Track who called a function with clean stack traces
Readme
why-is-this-called
Track who called a function with clean, readable stack traces.
Lightweight. Zero config. Dev-focused.
Made by Tonie
📦 Install
npm install why-is-this-called🚀 Usage
const { whyIsThisCalled } = require("why-is-this-called");
function test() {
console.log("running");
}
const wrapped = whyIsThisCalled(test);
function trigger() {
wrapped();
}
trigger();🔍 Output
[why-is-this-called] test
Called by: at trigger (/app.js:10:3)
Stack:
1. at trigger (/app.js:10:3)
2. at Object.<anonymous> (/app.js:14:1)
running⚙️ Options
whyIsThisCalled(fn, {
name: "customName",
depth: 5,
silent: false,
filterNodeModules: true,
logger: console.log
});| Option | Type | Default | Description | | ----------------- | -------- | ----------- | -------------------------------- | | name | string | fn.name | Custom function name | | depth | number | 5 | Stack depth | | silent | boolean | false | Disable logging | | filterNodeModules | boolean | true | Hide node_modules/internal calls | | logger | function | console.log | Custom logger |
📦 Wrap Object
const { wrapObject } = require("why-is-this-called");
const api = wrapObject({
hello() {
console.log("hi");
}
});
api.hello();🔌 Enable / Disable
const { setEnabled } = require("why-is-this-called");
setEnabled(false); // disable globally
setEnabled(true); // enable🧠 Notes
- Automatically disabled when NODE_ENV=production
- Designed for debugging and development use
- No runtime overhead when disabled
📄 License
MIT
