npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

fn-watch

v1.0.0

Published

Track and analyze function calls with timestamps, stack traces, and performance metrics.

Downloads

8

Readme

Foobar

Foobar is a Python library for dealing with word pluralization.

🔧 Installation

npm install function-tracker

Usage

function-tracker is a lightweight utility that wraps any function and gives you:

✅ Precise execution timing

✅ Automatic stack trace capture

✅ Call count tracking

✅ Optional debounce/throttle support

✅ Hook to log or process each call (onCall)

✅ Zero dependencies — works in browser & Node.js

feature

🧠 Wrap any function

🕒 Track call time & duration

🔁 Log how many times it's been called

📍 See where it was called from

⏳ Debounce or throttle execution

🧪 Inject analytics or custom behavior

Uses


import { trackFunction } from 'function-tracker';

function greet(name: string) {
  console.log(`Hello, ${name}!`);
}

const trackedGreet = trackFunction(greet, {
  name: 'greet',
  log: true,
  onCall({ args, callCount, duration }) {
    console.log(`Custom onCall → args: ${args}, call #: ${callCount}, duration: ${duration.toFixed(2)}ms`);
  }
});

trackedGreet('Alice');
trackedGreet('Bob');
.

📤 Output


[🧠 greet]
⏱️ Time: 2:43:10 PM
📍 Called from: at demo.ts:6:18
🔁 Call count: 2
✅ Execution time: 0.30ms
Custom onCall → args: Alice, call #: 2, duration: 0.30ms

⏳ Debounce & Throttle
🔁 Debounce
Wait X milliseconds after the last call before running.

ts
Copy
Edit
const debouncedFn = trackFunction(() => console.log("Fired!"), {
  debounce: 300
});

debouncedFn(); // skipped
debouncedFn(); // skipped
setTimeout(debouncedFn, 500); // ✅ only this runs
🔁 Throttle
Only allow one call every X milliseconds.

ts
Copy
Edit
const throttledFn = trackFunction(() => console.log("Throttled!"), {
  throttle: 1000
});

throttledFn();           // ✅ runs
throttledFn();           // ❌ ignored (too soon)
setTimeout(throttledFn, 1200); // ✅ runs again
🧪 Full API
trackFunction(fn, options): WrappedFn
Option	Type	Default	Description
name	string	fn.name	Optional name used in logs
debounce	number (ms)	0	Delay execution until X ms after last call
throttle	number (ms)	0	Allow only one call per X ms
log	boolean	true	Enable or disable console logs
onCall	function({ ...data })	() => {}	Callback executed after every actual call

🔄 Cancel Pending Calls
You can cancel a debounced call if needed:

ts
Copy
Edit
const fn = trackFunction(() => console.log("cancel me"), { debounce: 300 });
fn();
fn.cancel?.(); // 🚫 cancel before it runs
📊 onCall Hook
Use onCall to track metrics or integrate with analytics:

ts
Copy
Edit
trackFunction(myFn, {
  onCall: ({ args, result, duration, time, callCount, stack }) => {
    // Log or send data
  }
});
Data structure:
ts
Copy
Edit
{
  args: any[];        // Arguments passed
  result: any;        // Return value
  duration: number;   // ms
  time: number;       // timestamp
  stack: string;      // where it was called from
  callCount: number;  // total calls
}
🌐 Compatibility
✅ Browser (modern + legacy)

✅ Node.js

✅ Supports both CommonJS and ESM

✅ Fully tree-shakable and zero dependencies

🔧 Example Use Cases
Debugging production or complex async code

Tracking how many times a callback was triggered

Creating internal profiling/logging tools

Visualizing performance bottlenecks

Teaching function execution behavior

🪪 License
MIT © Your Name