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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@2fd/command

v1.1.2

Published

Modular command line tool

Downloads

45,726

Readme

@2fd/command Build Status

Modular command line interface

install

    npm install --save @2fd/command

Node Compatibility

  • node v6
  • node v5
  • node v4
  • node v0.12

Goals

  • Lazy load.

    Commands can be defined as a string that represents its location, which allows to generate complex tools without the large number of files slowing down the boot.

  • Commands are user-defined.

    • The name that invokes a command is defined by the implementation, which allows you to specify more practical commands (such as 'migration:init'or 'mgt:i' instead of 'module-name:migracions:init').

    • Third-party packages can only suggest the list of commands and names that implement them, but always you can implement only those you need and even replace them with your own ones.

  • Fully modular. A simple and completely object-oriented APIs allow easily:

    • Create commands that can be shared with the community

    • Re-implement and/or expand any functionality

    • Integrate commands created by third parties

  • Definitions included

    If you program in Typescript, definitions are included in the package so they are available when you install as dependincie with npm without requiring a definitions manager as typings or tsd

Usage

Command implementation


    import {
        Command,
        CommandInterface,
        BooleanFlag,
        Param
    } from '@2fd/command';

    // Object command implementation
    class MyCommand extends Command implements CommandInterface {

        description = 'My Command description';

        params = new Param('requireParam [optionalParam] [...optionalParamList]');

        flags = [
            new BooleanFlag('force', ['--force', '-f'], 'Force flag'),
        ];

        // action(input, output) { }; in javascript
        action(input: InputInterface, output: OutputInterface): void {

            // input.params.requireParam: string
            // input.params.optionalParam?: string
            // input.params.optionalParamList: Array<string>
            // input.flags.force: boolean
        };
    }

    export let myCommand = new MyCommand;

    // Function command implementation
    export function myQuickCommand(input: InputInterface, output: OutputInterface): void {
        // Do something
    }

Multiple command executor


    // cmd.js

    import {
        ExecutorCommand,
        ArgvInput,
        ConsoleOutput
    } from '@2fd/command';

    import {myCommand} from './path/to/commands';

    let tool = new ExecutorCommand();

    tool.version = '1.0.0';
    tool.description = 'Command description';

    tool.addCommand('run', myCommand );
    // or
    tool.addCommand('run', './path/to/commands#myCommand' );

    tool.addCommands({
        'command1' : './path/to/commands#myCommand',
        'command2' : './path/to/commands#myCommand'
    });

    tool.addCommadsNS('ns', {
        'command3' : './path/to/commands#myCommand',
        'command4' : './path/to/commands#myCommand'
    });

    tool.handle(
        new ArgvInput(process.argv),
        new ConsoleOutput()
    );
    > node cmd.js

        Command description [v1.0.0]

        Usage: node cmd.js [COMMAND]

        run            My Command description
        command1       My Command description
        command2       My Command description
        ns:command3    My Command description
        ns:command4    My Command description

Simple command in file


    // command.js

    import {myCommand} from './path/to/commands';

    myCommand.handle(
        new ArgvInput(process.argv),
        new ConsoleOutput()
    );

    > node command.js --help

        Usage: node command.js [OPTIONS] requireParam [optionalParam] [...optionalParamList]

        My Command description

        --force, -f    Force flag
        --help, -h     Print this help