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

@allnulled/commandir

v1.0.0

Published

Commandir pattern allows to scale command pattern with directories or URLs. Nodejs or browser.

Readme

commandir

Commandir pattern allows to scale command pattern with directories or URLs. Nodejs or browser.

Installation

npm install -s @allnulled/commandir

Importation

In node.js:

require("@allnulled/commandir");

In html:

<script src="node_modules/@allnulled/commandir/commandir.js"></script>

Usage

In node.js:

const commandir = Commandir.nodejs(__dirname + "/commands");

In browser:

const commandir = Commandir.browser("https://github.com/allnulled/path/to/file/raw");

The browser mode, which in fact means AJAX mode, is allowed in node.js too as it only uses fetch.

Then, in any:

commandir.execute("path/to/command.js", {
    parameter1: 1,
    parameter2: 2,
    parameter3: 3
});

You can, then, list(), register(name, callback) and unregister(name):

console.log(commandir.list());
commandir.register("salute", () => console.log("hi!"));
commandir.execute("salute");
commandir.unregister("salute");

Details

  1. The objects module.exports and __dirname exist in both environments.

The only difference is that __dirname in browsers points to the URL of the script. But module.exports and return can be used in browser mode to return a module from the file.

  1. The method register receive different parameters

In browser, register(name, url). In node.js, register(name, callback).

  1. The methods register and unregister work differently

In browser, they just associate a label with a URL. In node.js, they write a file in the filesystem with the callback provided as second parameter, and remove it on unregister.

  1. The method list cannot work in browser

Because directories in the web do not list by default, the method list is still not provided with a polyfill.

  1. Names are fixed and sanitized

Names have a process of validation and transformation before they get registered. They rewrite the .js at the end, and forbid .. just in case.

For now, I think it is all.

Test

This is the example that the test uses. It is cross-environment but because we discriminated.

let basedir = ".";

const isNodejs = typeof global !== "undefined";

const main = async function () {
  if (isNodejs) {
    require(__dirname + "/../commandir.js");
    basedir = __dirname;
  }

  if (isNodejs) {
    const commandir = Commandir.nodejs(basedir + "/commands");
    commandir.execute("/hello", {
      dest: "world"
    });
    commandir.register("/goodbye", function (parameters) {
      console.log(`Goodbye, ${parameters.dest}!`);
    });
    commandir.execute("/goodbye", { dest: "world" });
    commandir.unregister("/goodbye");
    console.log(commandir.list(""));
  } else {
    const commandir = Commandir.browser("/test/commands");
    await commandir.register("hello", "./commands/hello.js");
    await commandir.execute("hello", { dest: "world" });
  }
};

main();