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

js_console_command_executor

v1.0.9

Published

this scripts will be waiting and execute commands you will give to it.

Downloads

15

Readme

Travis Build Status

Review:

This is a script that allows you wrote command and execute it while this script will be listening stdin! You can add any handlers for any keys and any commands for run as written below. In js console you can use "tab" for auto complete names folders and files, "backspace", move cursor position by arrow keys "left" and "right", view history of typed commands by using arrow keys "up" and "down" and much more... Enjoy!

Run demo with:

npm run demo

Why?

Exists situations, especially in development, when you need send to running process some control commands, for example for restart build task (like "rs" in nodemon https://www.npmjs.com/package/nodemon) or something good else. What exactly? You can add every command that you want!

Requirements:

  • Node 4+
  • Npm 2+

Install:

npm i --save-dev js_console_command_executor

Usage:

First of all you need define your commands:

const availableCommands = {
    'k': {
        run: function(pid, signal) {
            console.log(`kill process! ${ pid } with signal "${ signal }"`);
            // some logic
        }
    },
    'exit': {
        run: function() {
            console.log(`exit process! ${ process.pid }`);
            // some logic
        }
    }
};

Add help for each commands, symbol "<>" needed as separator between command and text explanation (for pretty input):

availableCommands.k.usage = 'k [PID, [SIGNAL]] <> kill process by its PID';
availableCommands.exit.usage = 'exit <> stop watching for commands and exit script';

require script:

const execConsole = require('js_console_command_executor')(availableCommands);

Now you can access for this objects:

* execConsole.keys      // objects with defined keys and handlers;
* execConsole.actions   // object with all standard functions such as executeCommand and etc;
* execConsole.commands  // your object with commands;
* execConsole.controls  // object with state of line buffer, cursor position etc;

Optionally you can add new key handler. Adding new handler for "Ctrl + q":

execConsole.keys['\u0011'] = (controls, commands) => {
    console.log('This is handler for Ctrl + q! Another exit action!');
};

And this we're adding action move cursor left for two position for key "{" => "Shift + [":

execConsole.keys['\u007B'] = (controls, commands) => {
    if (controls.cursorPosition > 1) {
        controls.cursorPosition = controls.cursorPosition - 2;
        process.stdout.cursorTo(controls.cursorPosition);
    }
};

Optionally you can rebind standard handler. Rebind logic for "handleCombineActionsForEnterKeyAction":

execConsole.actions.handleCombineActionsForEnterKeyAction = function() {
    console.log(`\r\n\r\nThis is a logger! From rebind standard handler "handleCombineActionsForEnterKeyAction"!`);
    execConsole.actions.handleEnterKeyAction(execConsole.controls);
    execConsole.actions.executeCommand(execConsole.controls, execConsole.commands);
};

run script:

execConsole();

and you can even add a new command after script run (optional)!

execConsole.commands['n'] = {
    run: function() {
        console.log('I\'m a new command added after running script!');
    },
    usage: 'n <> just a new added command!'
};

Try use it!

For demo run:

npm run demo

For tests run:

npm run test

For code coverage run:

npm run coverage