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

@lvchengbin/interactive

v0.0.2

Published

A simple utility for building togglable interactive cli tool easily in node.js.

Readme

Interactive

A simple utility for building togglable interactive cli tool easily in node.js.

Installation

$ npm i @lvchengbin/interactive --save

Usage

An example is always a better way for starting:

const Interactive = require( '@lvchengbin/interactive' );

const interactive = new Interactive( {
    title : 'Interactive Mode',
    prompt : '~~> ',
    instructions : {
        start : 'Start Interactive Mode',
        pause : 'Pause Interactive Mode'
    },
    oo : 'CTRL+Y',
    keys : {
        'show .' : '\b'
    },
    completions : [ 'show', 'hide' ],
    exit : true,
    help : {
        show : 'Help information for "show" command.',
        hide : 'Help information for "hide" command.'
    }
} );

interactive.on( 'command', command => {
    console.log( 'command: ', command );
    if( command === 'change prompt' ) {
        interactive.prompt( 'New Prompt> ' );
    } else {
        interactive.prompt();
    }
} );

interactive.start();

Command Completion

You can provide a completion list in options, and this list will be used in completor function:

const Interactive = require( '@lvchengbin/interactive' );

const interactive = new Interactive( {
    title : 'Interactive Mode',
    prompt : '~~> ',
    completions : [ 'command1', 'command2' ],
} );

interactive.start();

Toggle Interactive Mode

The interactive mode can be started and paused by calling interactive.start() and interactive.pause(), and even you can use interactive.close() to close it throughly.

There are another two ways for switching between active(started) and inactive(paused) mode:

  • instructions.start and instructions.pause
  • on-off option

For example:

const Interactive = require( '@lvchengbin/interactive' );

const interactive = new Interactive( {
    instructions : {
        start : 'Start Interactive Mode',
        pause : 'Pause Interactive Mode'
    },
    oo : 'CTRL+Y'
} );

interactive.start();

In the code above, instructions.start is set to Start Interactive Mode and instructions.pause is set to Pause Interactive Mode. That means you can start or pause the interactive mode by typing these two commands. The oo option specified a shortcutkey for toggle the interactive mode.

Shortcut Keys

You can specify some shortcut keys for particular commands, for example:

const Interactive = require( '@lvchengbin/interactive' );

const interactive = new Interactive( {
    keys : {
        'command arg1 arg2' : [ 'CTRL+Y', '\u000c' ]
    }
} );

interactive.on( 'command', () => { } );

interactive.start();

With the code above, while the input equal to CTRL+Y or equal to \u000c, the command event will be emitted with command command arg1 arg2.

API

new Interactive( options )

To create a new instance, and it will start to listen to the input.

options

  • title String The title of the application.

  • prompt String The default prompt string.

  • instructions Object To specify special instructions:

    • start: start the interactive mode
    • pause: pause the interactive mode
  • oo String Array A shortcut key used to toggle interactive mode.

  • keys Object A map for defining shortcut keys for particular comamnds that the key should be the command, and the value should be a String or an Array of keys.

  • completions Array A command list which will be used for completion. The help, man and ? commands will be append into the completion list if the help option is set. The exit and quit commands will be append into the completion list if the exit option is set to true.

  • completor Function To speciy your own completor.

  • exit Boolean By setting this options to true, the interactive mode will be exited with command exit and quit.

  • help String Object The help information which will be shown with help command. If this option is an object, the help <key> command will show the information of corresponding value of the key.

start()

To start the interactive mode.

pause()

To pause the interactive mode.

toggle()

To toggle the interactive mode.

close()

To close the interactive mode throughly, this method will close the readline.Interface.

prompt( tag )

To set and show the prompt.

Events

Event:start

The 'start' event is emitted when the interactive mode start.

Event:pause

The 'pause' event is emitted when the interactive mode pause.

Event:close

The 'close' event is emitted when the interactive mode close

Event:command

The 'command' event is emitted while getting new command.

Event:keypress

The 'keypress' event is emitted while any keys are pressed. The callback function will accept two arguments, the chunk and the key object.