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 🙏

© 2024 – Pkg Stats / Ryan Hefner

name-all-the-things

v1.0.1

Published

Node require hook to put names on anonymous functions

Downloads

15

Readme

Name All The Things

With Node.js, there are several situations in which using anonymous functions is less than helpful for debugging purposes.

Name All The Things (name-all-the-things) is a Node.js require hook which scans any loaded modules, and inserts a name for any functions that it find. The function names are meant to be somewhat reasonable.

// Putting a name on unnamed functions that initialize vars is easy
var foo = function () {};
// becomes var foo = function anon$foo() {};

// Initializing fields is also easy
{
  bar: function () {}
  // becomes bar: function anon$bar() {}
}

// Anonymous functions passed directly in as callbacks can be tricky. These
// are simply given names that indicate the filename and line number
doSomething(someParams, function () {})
// becomes doSomething(someParams, function anon$readme$19() {})

Usage

To use name-all-the-things on any Node.js app, install globally and run the name-all-the-things command.

$ npm i -g name-all-the-things
$ natt app.js

To embed name-all-the-things in your application, add a call to the register(). Note that this won't be able to instrument anything in this file itself; just in the modules that are loaded later.

require('not-named');
require('name-all-the-things').register();
require('gets-named');

var alsoNotNamed = function () {}

Compatibility

This module probably doesn't work with most transpilers, since they are trying similar but different hackery to get into the require process. But this isn't very useful with them anyways, since line numbers will be from the generated JavaScript, so they probably won't line up with the original source.