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

babel-plugin-function-tracker

v2.0.0

Published

Track function start and end

Downloads

12

Readme

babel-plugin-function-tracker

Provides tracking without external wrapper overhead by calling user function at the end of block statement.

Installation

Install it as any other babel plugin to dev dependencies:

npm i -D babel-plugin-function-tracker

Then add it to your plugins in babel.config.js and configure it's options. The plugin works only when special function imported from special module and used as a statement in any function definition. So with options like { functionName: 'functionName', moduleName: 'moduleName' } it will search for any import statement with functionName identifier and moduleName source:

module.exports = {
  // other babel config
  plugins: [
    ['babel-plugin-function-tracker', { functionName: 'functionName', moduleName: 'moduleName' }],
    // other babel plugins
  ],
};

Options

The plugin accepts two required options (functionName and moduleName) to search for them in the following import statements:

import { functionName } from 'moduleName';
import * as functionName from 'moduleName';
import functionName from 'moduleName';
import { default as functionName } from 'moduleName';
import { something as functionName } from 'moduleName';

Please, note: any other form of import is not available for special function which should be used only directly.

How it works

Let's assume we provided plugin options as { functionName: 'functionName', moduleName: 'moduleName' }.

The plugin checks for special function import first using provided plugin options:

import React from 'react';
import { name1, functionName, name2, name3 } from 'moduleName'; // found

Then it searches for any special function call as a statement inside a block statement:

function random() {
  functionName(); // found!
  if (Math.random() < 0.5) {
    return 0;
  } else {
    return 1;
  }
}

function log(text) {
  const result = functionName(); // skipped: the call is not a statement
  console.log(text);
}

And only then the code generation happens:

function random() {
  // get the result of special function
  const _end = functionName();
  // wrap every statement below special function in try/catch
  try {
    if (Math.random() < 0.5) {
      // wrap each return statement in the result
      return _end(0);
    } else {
      // wrap each return statement in the result
      return _end(1);
    }
  } catch (_e) {
    // wrap error in the result too
    throw _end(_e);
  }
}

Please take a look at test/fixtures directory for more examples.

Special function

The special function may accept any arguments, but it should always return "end"-function of the following type:

<T>(arg: T) => T;

That means any input of "end"-function should be returned unmodified for correct work.

The simplest example of special function is

export const f = () => (arg) => arg;

It is useless without side effects so we may improve it a little to track call time in ms:

export const track = (name: string) => {
  const now = Date.now();
  console.log('call start', name);
  const end = (arg) => {
    console.log('call end', name, Date.now() - now);
    return arg;
  };
  return end;
};